MybatisPlusApplicationTests.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package com.template;
  2. import org.junit.jupiter.api.Test;
  3. import org.springframework.beans.factory.annotation.Value;
  4. import org.springframework.boot.test.context.SpringBootTest;
  5. @SpringBootTest
  6. class MybatisPlusApplicationTests {
  7. @Value("${my-security.privateKey}")
  8. String privateKey;
  9. @Value("${my-security.publicKey}")
  10. String publicKey;
  11. @Test
  12. void contextLoads() {
  13. // System.out.println(mySecurity.toString());
  14. System.out.println("privateKey = " + privateKey);
  15. System.out.println("publicKey = " + publicKey);
  16. }
  17. // // 继承了BaseMapper,所有的方法都来自己父类
  18. // // 我们也可以编写自己的扩展方法!
  19. // @Autowired
  20. // private PlaybackRecordMapper playbackRecordMapper;
  21. //
  22. // @Test
  23. // void contextLoads() {
  24. // // 参数是一个 Wrapper ,条件构造器,这里我们先不用 null
  25. // // 查询全部用户
  26. // List<PlaybackRecord> playbackRecords = playbackRecordMapper.selectList(null);
  27. // playbackRecords.forEach(System.out::println);
  28. // }
  29. //
  30. // // 测试插入
  31. // @Test
  32. // public void testInsert(){
  33. // PlaybackRecord playbackRecord = new PlaybackRecord();
  34. // playbackRecord.setUrl("www.baidu.com");
  35. // playbackRecord.setSharerId("123456");
  36. // playbackRecord.setShareeId("654321");
  37. //
  38. // int result = playbackRecordMapper.insert(playbackRecord); // 帮我们自动生成id
  39. // System.out.println(result); // 受影响的行数
  40. // System.out.println(playbackRecord); // 发现,id会自动回填
  41. // }
  42. //
  43. // // 测试更新
  44. // @Test
  45. // public void testUpdate(){
  46. // PlaybackRecord playbackRecord = new PlaybackRecord();
  47. // // 通过条件自动拼接动态sql
  48. // playbackRecord.setShareeId("123456");
  49. // // 注意:updateById 但是参数是一个 对象!
  50. // int i = playbackRecordMapper.updateById(playbackRecord);
  51. // System.out.println(i);
  52. // }
  53. //
  54. // // 测试乐观锁成功!
  55. // @Test
  56. // public void testOptimisticLocker(){
  57. // // 1、查询用户信息
  58. // PlaybackRecord playbackRecord = playbackRecordMapper.selectById(1L);
  59. // // 2、修改用户信息
  60. // playbackRecord.setShareeId("123456");
  61. // // 3、执行更新操作
  62. // playbackRecordMapper.updateById(playbackRecord);
  63. // }
  64. //
  65. //
  66. // // 测试乐观锁失败!多线程下
  67. // @Test
  68. // public void testOptimisticLocker2(){
  69. //
  70. // // 线程 1
  71. // PlaybackRecord playbackRecord = playbackRecordMapper.selectById(1L);
  72. // playbackRecord.setShareeId("123456");
  73. //
  74. // // 模拟另外一个线程执行了插队操作
  75. // PlaybackRecord playbackRecord2 = playbackRecordMapper.selectById(1L);
  76. // playbackRecord.setShareeId("123456");
  77. // playbackRecordMapper.updateById(playbackRecord2);
  78. //
  79. // // 自旋锁来多次尝试提交!
  80. // playbackRecordMapper.updateById(playbackRecord); // 如果没有乐观锁就会覆盖插队线程的值!
  81. // }
  82. //
  83. // // 测试查询
  84. // @Test
  85. // public void testSelectById(){
  86. // PlaybackRecord playbackRecord = playbackRecordMapper.selectById(1L);
  87. // System.out.println(playbackRecord);
  88. // }
  89. //
  90. // // 测试批量查询!
  91. // @Test
  92. // public void testSelectByBatchId(){
  93. // List<PlaybackRecord> playbackRecords = playbackRecordMapper.selectBatchIds(Arrays.asList(1, 2, 3));
  94. // playbackRecords.forEach(System.out::println);
  95. // }
  96. //
  97. // // 按条件查询之一使用map操作
  98. // @Test
  99. // public void testSelectByBatchIds(){
  100. // HashMap<String, Object> map = new HashMap<>();
  101. // // 自定义要查询
  102. // map.put("sharer_id","123456");
  103. //
  104. // List<PlaybackRecord> playbackRecords = playbackRecordMapper.selectByMap(map);
  105. // playbackRecords.forEach(System.out::println);
  106. // }
  107. //
  108. // // 测试分页查询
  109. // @Test
  110. // public void testPage(){
  111. // // 参数一:当前页
  112. // // 参数二:页面大小
  113. // // 使用了分页插件之后,所有的分页操作也变得简单的!
  114. // Page<PlaybackRecord> page = new Page<>(2,5);
  115. // playbackRecordMapper.selectPage(page,null);
  116. //
  117. // page.getRecords().forEach(System.out::println);
  118. // System.out.println(page.getTotal());
  119. //
  120. // }
  121. //
  122. //
  123. // // 测试删除
  124. // @Test
  125. // public void testDeleteById(){
  126. // playbackRecordMapper.deleteById(1L);
  127. // }
  128. //
  129. // // 通过id批量删除
  130. // @Test
  131. // public void testDeleteBatchId(){
  132. // playbackRecordMapper.deleteBatchIds(Arrays.asList(1240620674645544961L,1240620674645544962L));
  133. // }
  134. //
  135. // // 通过map删除
  136. // @Test
  137. // public void testDeleteMap(){
  138. // HashMap<String, Object> map = new HashMap<>();
  139. // map.put("name","123456");
  140. // playbackRecordMapper.deleteByMap(map);
  141. // }
  142. }