Browse Source

mybatis plus task

xiaoyuzhang 3 years ago
parent
commit
ecd8069f7b

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

@@ -1,8 +1,10 @@
1
 package com.example.springbootdemo.controller;
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
 import com.example.springbootdemo.entity.FootScanEntity;
5
 import com.example.springbootdemo.entity.FootScanEntity;
4
 import com.example.springbootdemo.entity.FootScanGroup;
6
 import com.example.springbootdemo.entity.FootScanGroup;
5
-import com.example.springbootdemo.mapper.FootScanGroupMapper;
7
+import com.example.springbootdemo.mapper.FootScanMapper;
6
 import com.example.springbootdemo.service.FootScanGroupService;
8
 import com.example.springbootdemo.service.FootScanGroupService;
7
 import com.example.springbootdemo.service.FootScanService;
9
 import com.example.springbootdemo.service.FootScanService;
8
 import com.example.springbootdemo.zxyTeST.sql.dao.ArmGrabRepository;
10
 import com.example.springbootdemo.zxyTeST.sql.dao.ArmGrabRepository;
@@ -28,6 +30,10 @@ public class HelloController {
28
     FootScanService footScanService;
30
     FootScanService footScanService;
29
     @Autowired
31
     @Autowired
30
     FootScanGroupService footScanGroupService;
32
     FootScanGroupService footScanGroupService;
33
+    @Autowired
34
+    FootScanMapper footScanMapper;
35
+
36
+
31
     @RequestMapping("/hello")
37
     @RequestMapping("/hello")
32
     public void hello() {
38
     public void hello() {
33
         List<Color> listColors = colorRepository.findByColorId(2314);
39
         List<Color> listColors = colorRepository.findByColorId(2314);
@@ -52,19 +58,29 @@ public class HelloController {
52
 
58
 
53
     }
59
     }
54
     @RequestMapping("mybatis")
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
         return footScanService.getFootScanById(foot_scan_id);
62
         return footScanService.getFootScanById(foot_scan_id);
57
 
63
 
58
     }
64
     }
59
     @RequestMapping("mybatis1")
65
     @RequestMapping("mybatis1")
60
     public FootScanGroup getFootScanGroup(@RequestParam("foot_scan_group_id") Long foot_scan_group_id) {
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
     @RequestMapping(value = "/mybatis2",method = RequestMethod.POST)
69
     @RequestMapping(value = "/mybatis2",method = RequestMethod.POST)
64
     public FootScanGroup addFootScanGroup(@RequestBody FootScanGroup footScanGroup) {
70
     public FootScanGroup addFootScanGroup(@RequestBody FootScanGroup footScanGroup) {
65
-        footScanGroupService.addFootScanGroup(footScanGroup);
71
+        footScanGroupService.save(footScanGroup);
66
         return footScanGroup;
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
 package com.example.springbootdemo.controller;
1
 package com.example.springbootdemo.controller;
2
 
2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3
 import com.example.springbootdemo.entity.Device;
4
 import com.example.springbootdemo.entity.Device;
4
 import com.example.springbootdemo.mapper.DeviceMapper;
5
 import com.example.springbootdemo.mapper.DeviceMapper;
5
 import org.springframework.beans.factory.annotation.Autowired;
6
 import org.springframework.beans.factory.annotation.Autowired;
@@ -18,8 +19,9 @@ public class MybatisPlusController {
18
     @Autowired
19
     @Autowired
19
     DeviceMapper deviceMapper;
20
     DeviceMapper deviceMapper;
20
     @RequestMapping("/mybatisPlusSelect")
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
 package com.example.springbootdemo.entity;
1
 package com.example.springbootdemo.entity;
2
 
2
 
3
+import com.baomidou.mybatisplus.annotation.TableId;
4
+import com.baomidou.mybatisplus.annotation.TableName;
3
 import lombok.Data;
5
 import lombok.Data;
4
 
6
 
5
 import javax.persistence.GeneratedValue;
7
 import javax.persistence.GeneratedValue;
@@ -14,11 +16,11 @@ import java.sql.Timestamp;
14
  * @date 2021/6/1 下午3:50
16
  * @date 2021/6/1 下午3:50
15
  */
17
  */
16
 @Data
18
 @Data
17
-@Table(name = "wb_tbl_device")
19
+@TableName("wb_tbl_device")
18
 public class Device implements Serializable {
20
 public class Device implements Serializable {
19
-    @Id
21
+    @TableId("device_id")
20
     @GeneratedValue
22
     @GeneratedValue
21
-    private Long deviceId;
23
+    private Integer deviceId;
22
     private String deviceCode;
24
     private String deviceCode;
23
     private Long companyId;
25
     private Long companyId;
24
     private Timestamp runDateUtime;
26
     private Timestamp runDateUtime;

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

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

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

@@ -1,6 +1,8 @@
1
 package com.example.springbootdemo.entity;
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
 import com.fasterxml.jackson.annotation.JsonProperty;
6
 import com.fasterxml.jackson.annotation.JsonProperty;
5
 import lombok.Data;
7
 import lombok.Data;
6
 
8
 
@@ -15,9 +17,10 @@ import java.io.Serializable;
15
  * @date 2021/6/1 上午9:45
17
  * @date 2021/6/1 上午9:45
16
  */
18
  */
17
 @Data
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
 public class FootScanGroup implements Serializable {
22
 public class FootScanGroup implements Serializable {
20
-    @Id
23
+    @TableId("foot_scan_group_id")
21
     @GeneratedValue
24
     @GeneratedValue
22
     private Long footScanGroupId;
25
     private Long footScanGroupId;
23
     @JsonProperty("user_id")
26
     @JsonProperty("user_id")

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

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