Bläddra i källkod

mybatis Plus task page 02

zhangxiaoyu 3 år sedan
förälder
incheckning
33735a6d53

+ 10 - 0
src/main/java/com/example/demo/config/MyConfig.java

@@ -1,5 +1,9 @@
1 1
 package com.example.demo.config;
2 2
 
3
+import com.baomidou.mybatisplus.annotation.DbType;
4
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
5
+import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
6
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
3 7
 import com.example.demo.controller.User;
4 8
 import org.springframework.context.annotation.Bean;
5 9
 import org.springframework.context.annotation.Configuration;
@@ -18,5 +22,11 @@ public class MyConfig {
18 22
         User lisi = new User("lisi");
19 23
         return  lisi;
20 24
     }
25
+    @Bean
26
+    public MybatisPlusInterceptor paginationInterceptor() {
27
+        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
28
+        interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
29
+        return interceptor;
30
+    }
21 31
 
22 32
 }

+ 15 - 0
src/main/java/com/example/springbootdemo/controller/MybatisPlusController.java

@@ -1,8 +1,11 @@
1 1
 package com.example.springbootdemo.controller;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
4 5
 import com.example.springbootdemo.entity.Device;
6
+import com.example.springbootdemo.entity.FootScanEntity;
5 7
 import com.example.springbootdemo.mapper.DeviceMapper;
8
+import com.example.springbootdemo.service.FootScanService;
6 9
 import org.springframework.beans.factory.annotation.Autowired;
7 10
 import org.springframework.web.bind.annotation.RequestMapping;
8 11
 import org.springframework.web.bind.annotation.RestController;
@@ -18,10 +21,22 @@ import java.util.List;
18 21
 public class MybatisPlusController {
19 22
     @Autowired
20 23
     DeviceMapper deviceMapper;
24
+    @Autowired
25
+    FootScanService footScanService;
21 26
     @RequestMapping("/mybatisPlusSelect")
22 27
     public Device getDeviceList() {
23 28
         QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
24 29
         queryWrapper.eq("device_code","19216800200306800");
25 30
         return deviceMapper.selectOne(queryWrapper);
26 31
     }
32
+    @RequestMapping("/pageDemo")
33
+    public List<FootScanEntity> getFootScanListPage() {
34
+        Page<FootScanEntity> page = new Page<>(1,3);
35
+        QueryWrapper<FootScanEntity> queryWrapper = new QueryWrapper<FootScanEntity>()
36
+                .eq("device_code","SCMD03001001").orderByDesc("foot_scan_id");
37
+        footScanService.page(page,queryWrapper);
38
+        return  page.getRecords();
39
+    }
40
+
41
+
27 42
 }

+ 1 - 0
src/main/java/com/example/springbootdemo/entity/FootScanEntity.java

@@ -23,4 +23,5 @@ public class FootScanEntity implements Serializable {
23 23
     @GeneratedValue
24 24
     private Integer footScanId;
25 25
     private String deviceCode;
26
+    private String footScanJson;
26 27
 }

+ 5 - 2
src/main/resources/application-dev.yml

@@ -18,9 +18,9 @@ spring:
18 18
         login-username: zxy
19 19
         login-password: 123456
20 20
       driver-class-name: com.mysql.cj.jdbc.Driver
21
-      url: jdbc:mysql://192.168.2.130:3306/ceshi?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
21
+      url: jdbc:mysql://localhost:3306/test?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
22 22
       username: root
23
-      password: 123456
23
+      password:
24 24
   jpa:
25 25
     database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
26 26
     open-in-view: false
@@ -30,3 +30,6 @@ mybatis:
30 30
 #  mapper-locations: classpath:mapper/*.xml
31 31
   configuration:
32 32
     map-underscore-to-camel-case: true
33
+mybatis-plus:
34
+  configuration:
35
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl