Quellcode durchsuchen

mybatis plus task

xiaoyuzhang vor 3 Jahren
Ursprung
Commit
ecd8069f7b

+ 20 - 4
src/main/java/com/example/springbootdemo/controller/HelloController.java

@@ -1,8 +1,10 @@
1 1
 package com.example.springbootdemo.controller;
2 2
 
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
4
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
3 5
 import com.example.springbootdemo.entity.FootScanEntity;
4 6
 import com.example.springbootdemo.entity.FootScanGroup;
5
-import com.example.springbootdemo.mapper.FootScanGroupMapper;
7
+import com.example.springbootdemo.mapper.FootScanMapper;
6 8
 import com.example.springbootdemo.service.FootScanGroupService;
7 9
 import com.example.springbootdemo.service.FootScanService;
8 10
 import com.example.springbootdemo.zxyTeST.sql.dao.ArmGrabRepository;
@@ -28,6 +30,10 @@ public class HelloController {
28 30
     FootScanService footScanService;
29 31
     @Autowired
30 32
     FootScanGroupService footScanGroupService;
33
+    @Autowired
34
+    FootScanMapper footScanMapper;
35
+
36
+
31 37
     @RequestMapping("/hello")
32 38
     public void hello() {
33 39
         List<Color> listColors = colorRepository.findByColorId(2314);
@@ -52,19 +58,29 @@ public class HelloController {
52 58
 
53 59
     }
54 60
     @RequestMapping("mybatis")
55
-    public List<FootScanEntity> getById(@RequestParam("foot_scan_id") Long foot_scan_id) {
61
+    public FootScanEntity getById(@RequestParam("foot_scan_id") Long foot_scan_id) {
56 62
         return footScanService.getFootScanById(foot_scan_id);
57 63
 
58 64
     }
59 65
     @RequestMapping("mybatis1")
60 66
     public FootScanGroup getFootScanGroup(@RequestParam("foot_scan_group_id") Long foot_scan_group_id) {
61
-        return footScanGroupService.findByFootScanGroupId(foot_scan_group_id);
67
+        return footScanGroupService.getById(foot_scan_group_id);
62 68
     }
63 69
     @RequestMapping(value = "/mybatis2",method = RequestMethod.POST)
64 70
     public FootScanGroup addFootScanGroup(@RequestBody FootScanGroup footScanGroup) {
65
-        footScanGroupService.addFootScanGroup(footScanGroup);
71
+        footScanGroupService.save(footScanGroup);
66 72
         return footScanGroup;
67 73
     }
74
+    @RequestMapping("mybatis3")
75
+    public FootScanEntity getFootScanInfo(@RequestParam("foot_scan_id") Long foot_scan_id) {
76
+        return  footScanMapper.queryFootScanInfo(foot_scan_id);
77
+    }
78
+    @RequestMapping("mybatis4")
79
+    public List<FootScanEntity> getFootScanListPage() {
80
+        Page<FootScanEntity> footScanEntityPage = new Page<>(1,20);
81
+        footScanService.page(footScanEntityPage,null);
82
+        return  footScanEntityPage.getRecords();
83
+    }
68 84
 
69 85
 }
70 86
 

+ 5 - 3
src/main/java/com/example/springbootdemo/controller/MybatisPlusController.java

@@ -1,5 +1,6 @@
1 1
 package com.example.springbootdemo.controller;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3 4
 import com.example.springbootdemo.entity.Device;
4 5
 import com.example.springbootdemo.mapper.DeviceMapper;
5 6
 import org.springframework.beans.factory.annotation.Autowired;
@@ -18,8 +19,9 @@ public class MybatisPlusController {
18 19
     @Autowired
19 20
     DeviceMapper deviceMapper;
20 21
     @RequestMapping("/mybatisPlusSelect")
21
-    public List<Device> getDeviceList() {
22
-        List<Device> deviceList = deviceMapper.selectList(null);
23
-        return deviceList;
22
+    public Device getDeviceList() {
23
+        QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
24
+        queryWrapper.eq("device_code","19216800200306800");
25
+        return deviceMapper.selectOne(queryWrapper);
24 26
     }
25 27
 }

+ 5 - 3
src/main/java/com/example/springbootdemo/entity/Device.java

@@ -1,5 +1,7 @@
1 1
 package com.example.springbootdemo.entity;
2 2
 
3
+import com.baomidou.mybatisplus.annotation.TableId;
4
+import com.baomidou.mybatisplus.annotation.TableName;
3 5
 import lombok.Data;
4 6
 
5 7
 import javax.persistence.GeneratedValue;
@@ -14,11 +16,11 @@ import java.sql.Timestamp;
14 16
  * @date 2021/6/1 下午3:50
15 17
  */
16 18
 @Data
17
-@Table(name = "wb_tbl_device")
19
+@TableName("wb_tbl_device")
18 20
 public class Device implements Serializable {
19
-    @Id
21
+    @TableId("device_id")
20 22
     @GeneratedValue
21
-    private Long deviceId;
23
+    private Integer deviceId;
22 24
     private String deviceCode;
23 25
     private Long companyId;
24 26
     private Timestamp runDateUtime;

+ 5 - 2
src/main/java/com/example/springbootdemo/entity/FootScanEntity.java

@@ -1,5 +1,7 @@
1 1
 package com.example.springbootdemo.entity;
2 2
 
3
+import com.baomidou.mybatisplus.annotation.TableId;
4
+import com.baomidou.mybatisplus.annotation.TableName;
3 5
 import lombok.Data;
4 6
 
5 7
 import javax.persistence.Entity;
@@ -14,9 +16,10 @@ import java.io.Serializable;
14 16
  * @date 2021/5/31 下午5:14
15 17
  */
16 18
 @Data
17
-@Table(name = "wb_tbl_foot_scan")
19
+//@Table(name = "wb_tbl_foot_scan")
20
+@TableName("wb_tbl_foot_scan")
18 21
 public class FootScanEntity implements Serializable {
19
-    @Id
22
+    @TableId("foot_scan_id")
20 23
     @GeneratedValue
21 24
     private Integer footScanId;
22 25
     private String deviceCode;

+ 5 - 2
src/main/java/com/example/springbootdemo/entity/FootScanGroup.java

@@ -1,6 +1,8 @@
1 1
 package com.example.springbootdemo.entity;
2 2
 
3 3
 
4
+import com.baomidou.mybatisplus.annotation.TableId;
5
+import com.baomidou.mybatisplus.annotation.TableName;
4 6
 import com.fasterxml.jackson.annotation.JsonProperty;
5 7
 import lombok.Data;
6 8
 
@@ -15,9 +17,10 @@ import java.io.Serializable;
15 17
  * @date 2021/6/1 上午9:45
16 18
  */
17 19
 @Data
18
-@Table(name = "wb_tbl_foot_scan_group")
20
+//@Table(name = "wb_tbl_foot_scan_group")
21
+@TableName("wb_tbl_foot_scan_group")
19 22
 public class FootScanGroup implements Serializable {
20
-    @Id
23
+    @TableId("foot_scan_group_id")
21 24
     @GeneratedValue
22 25
     private Long footScanGroupId;
23 26
     @JsonProperty("user_id")

+ 2 - 1
src/main/java/com/example/springbootdemo/mapper/FootScanGroupMapper.java

@@ -1,5 +1,6 @@
1 1
 package com.example.springbootdemo.mapper;
2 2
 
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
3 4
 import com.example.springbootdemo.entity.FootScanGroup;
4 5
 import org.apache.ibatis.annotations.Insert;
5 6
 import org.apache.ibatis.annotations.Mapper;
@@ -14,7 +15,7 @@ import java.util.List;
14 15
  * @date 2021/6/1 上午9:48
15 16
  */
16 17
 @Mapper
17
-public interface FootScanGroupMapper {
18
+public interface FootScanGroupMapper extends BaseMapper<FootScanGroup> {
18 19
     @Select("SELECT foot_scan_group_id,user_id,user_name FROM wb_tbl_foot_scan_group WHERE  foot_scan_group_id = #{id}")
19 20
     FootScanGroup findByFootScanGroupId(Long id);
20 21
     @Insert("insert into wb_tbl_foot_scan_group (user_id,user_name) values (#{userId},#{userName})")

+ 3 - 2
src/main/java/com/example/springbootdemo/mapper/FootScanMapper.java

@@ -1,5 +1,6 @@
1 1
 package com.example.springbootdemo.mapper;
2 2
 
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
3 4
 import com.example.springbootdemo.entity.FootScanEntity;
4 5
 import org.apache.ibatis.annotations.Mapper;
5 6
 import org.springframework.stereotype.Repository;
@@ -13,6 +14,6 @@ import java.util.List;
13 14
  */
14 15
 @Mapper
15 16
 @Repository
16
-public interface FootScanMapper {
17
-    List<FootScanEntity> queryFootScanInfo(Long foot_scan_id);
17
+public interface FootScanMapper extends BaseMapper<FootScanEntity> {
18
+    FootScanEntity queryFootScanInfo(Long foot_scan_id);
18 19
 }

+ 2 - 17
src/main/java/com/example/springbootdemo/service/FootScanGroupService.java

@@ -1,23 +1,8 @@
1 1
 package com.example.springbootdemo.service;
2 2
 
3
+import com.baomidou.mybatisplus.extension.service.IService;
3 4
 import com.example.springbootdemo.entity.FootScanGroup;
4
-import com.example.springbootdemo.mapper.FootScanGroupMapper;
5
-import org.springframework.beans.factory.annotation.Autowired;
6
-import org.springframework.stereotype.Service;
7
-
8
-import java.util.List;
9
-
10
-@Service
11
-public class FootScanGroupService {
12
-    @Autowired
13
-    FootScanGroupMapper footScanGroupMapper;
14
-    public FootScanGroup findByFootScanGroupId(Long foot_scan_group_id) {
15
-        return footScanGroupMapper.findByFootScanGroupId(foot_scan_group_id);
16
-    }
17
-
18
-    public void addFootScanGroup(FootScanGroup footScanGroup) {
19
-        footScanGroupMapper.addFootScanGroup(footScanGroup);
20
-    }
21 5
 
6
+public interface FootScanGroupService extends IService<FootScanGroup> {
22 7
 
23 8
 }

+ 3 - 12
src/main/java/com/example/springbootdemo/service/FootScanService.java

@@ -1,18 +1,9 @@
1 1
 package com.example.springbootdemo.service;
2 2
 
3
+import com.baomidou.mybatisplus.extension.service.IService;
3 4
 import com.example.springbootdemo.entity.FootScanEntity;
4
-import com.example.springbootdemo.mapper.FootScanMapper;
5
-import org.springframework.beans.factory.annotation.Autowired;
6
-import org.springframework.stereotype.Service;
7 5
 
8
-import java.util.List;
9
-
10
-@Service
11
-public class FootScanService {
12
-    @Autowired
13
-    FootScanMapper footScanMapper;
14
-    public List<FootScanEntity> getFootScanById(Long foot_scan_id) {
15
-        return footScanMapper.queryFootScanInfo(foot_scan_id);
16
-    }
17 6
 
7
+public interface FootScanService extends IService<FootScanEntity> {
8
+    FootScanEntity getFootScanById(Long foot_scan_id);
18 9
 }