Browse Source

ver: mybatis demo run

zhangxiaoyu 3 years ago
parent
commit
866b9f7cb3

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

@@ -1,5 +1,6 @@
1
 package com.example.springbootdemo;
1
 package com.example.springbootdemo;
2
 
2
 
3
+import org.mybatis.spring.annotation.MapperScan;
3
 import org.springframework.boot.SpringApplication;
4
 import org.springframework.boot.SpringApplication;
4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5
 import org.springframework.context.ConfigurableApplicationContext;
6
 import org.springframework.context.ConfigurableApplicationContext;

+ 9 - 0
src/main/java/com/example/springbootdemo/controller/HelloController.java

@@ -1,5 +1,7 @@
1
 package com.example.springbootdemo.controller;
1
 package com.example.springbootdemo.controller;
2
 
2
 
3
+import com.example.springbootdemo.entity.FootScanEntity;
4
+import com.example.springbootdemo.service.FootScanService;
3
 import com.example.springbootdemo.zxyTeST.sql.dao.ArmGrabRepository;
5
 import com.example.springbootdemo.zxyTeST.sql.dao.ArmGrabRepository;
4
 import com.example.springbootdemo.zxyTeST.sql.dao.ColorRepository;
6
 import com.example.springbootdemo.zxyTeST.sql.dao.ColorRepository;
5
 import com.example.springbootdemo.zxyTeST.sql.entity.ArmGrabEntity;
7
 import com.example.springbootdemo.zxyTeST.sql.entity.ArmGrabEntity;
@@ -8,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
8
 import org.springframework.dao.EmptyResultDataAccessException;
10
 import org.springframework.dao.EmptyResultDataAccessException;
9
 import org.springframework.jdbc.core.JdbcTemplate;
11
 import org.springframework.jdbc.core.JdbcTemplate;
10
 import org.springframework.web.bind.annotation.RequestMapping;
12
 import org.springframework.web.bind.annotation.RequestMapping;
13
+import org.springframework.web.bind.annotation.RequestParam;
11
 import org.springframework.web.bind.annotation.RestController;
14
 import org.springframework.web.bind.annotation.RestController;
12
 
15
 
13
 import java.util.List;
16
 import java.util.List;
@@ -20,6 +23,8 @@ public class HelloController {
20
     ArmGrabRepository armGrabRepository;
23
     ArmGrabRepository armGrabRepository;
21
     @Autowired
24
     @Autowired
22
     JdbcTemplate jdbcTemplate;
25
     JdbcTemplate jdbcTemplate;
26
+    @Autowired
27
+    FootScanService footScanService;
23
     @RequestMapping("/hello")
28
     @RequestMapping("/hello")
24
     public void hello() {
29
     public void hello() {
25
         List<Color> listColors = colorRepository.findByColorId(2314);
30
         List<Color> listColors = colorRepository.findByColorId(2314);
@@ -42,6 +47,10 @@ public class HelloController {
42
             return "hha我snull";
47
             return "hha我snull";
43
         }
48
         }
44
 
49
 
50
+    }
51
+    @RequestMapping("mybatis")
52
+    public List<FootScanEntity> getById(@RequestParam("foot_scan_id") Long foot_scan_id) {
53
+        return footScanService.getFootScanById(foot_scan_id);
45
 
54
 
46
     }
55
     }
47
 
56
 

+ 6 - 0
src/main/java/com/example/springbootdemo/mapper/FootScanMapper.java

@@ -1,12 +1,18 @@
1
 package com.example.springbootdemo.mapper;
1
 package com.example.springbootdemo.mapper;
2
 
2
 
3
+import com.example.springbootdemo.entity.FootScanEntity;
4
+import org.apache.ibatis.annotations.Mapper;
3
 import org.springframework.stereotype.Repository;
5
 import org.springframework.stereotype.Repository;
4
 
6
 
7
+import java.util.List;
8
+
5
 /**
9
 /**
6
  * @author zhangxiaoyu
10
  * @author zhangxiaoyu
7
  * @version 1.0
11
  * @version 1.0
8
  * @date 2021/5/31 下午5:20
12
  * @date 2021/5/31 下午5:20
9
  */
13
  */
14
+@Mapper
10
 @Repository
15
 @Repository
11
 public interface FootScanMapper {
16
 public interface FootScanMapper {
17
+    List<FootScanEntity> queryFootScanInfo(Long foot_scan_id);
12
 }
18
 }

+ 18 - 0
src/main/java/com/example/springbootdemo/service/FootScanService.java

@@ -0,0 +1,18 @@
1
+package com.example.springbootdemo.service;
2
+
3
+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
+
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
+
18
+}

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

@@ -18,13 +18,15 @@ spring:
18
         login-username: zxy
18
         login-username: zxy
19
         login-password: 123456
19
         login-password: 123456
20
       driver-class-name: com.mysql.cj.jdbc.Driver
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
       username: root
22
       username: root
23
-      password: 123456
23
+      password:
24
   jpa:
24
   jpa:
25
     database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
25
     database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
26
     open-in-view: false
26
     open-in-view: false
27
   freemarker:
27
   freemarker:
28
     cache: false
28
     cache: false
29
 mybatis:
29
 mybatis:
30
-#  config-location:
30
+  mapper-locations: classpath:mapper/*.xml
31
+  configuration:
32
+    map-underscore-to-camel-case: true

+ 0 - 5
src/main/resources/mapper/ColorMapper.xml

@@ -1,5 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8" ?>
2
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
3
-<mapper namespace="">
4
-    <!--namespace根据自己需要创建的的mapper的路径和名称填写-->
5
-</mapper>

+ 21 - 0
src/main/resources/mapper/FootScanMapper.xml

@@ -0,0 +1,21 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper
3
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
4
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
5
+
6
+<mapper namespace="com.example.springbootdemo.mapper.FootScanMapper">
7
+
8
+    <select id="queryFootScanInfo" resultType="com.example.springbootdemo.entity.FootScanEntity">
9
+        SELECT
10
+            *
11
+        FROM
12
+           wb_tbl_foot_scan
13
+        WHERE
14
+            foot_scan_id = #{foot_scan_id}
15
+	</select>
16
+
17
+
18
+
19
+
20
+
21
+</mapper>