Skip to content

Commit d3d41de

Browse files
committed
[bug] 新增mybatisJdbcTemplate支持测试
1 parent 175d285 commit d3d41de

File tree

17 files changed

+1223
-0
lines changed

17 files changed

+1223
-0
lines changed

spring-data-jdbc-demo/.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/modules.xml
8+
.idea/jarRepositories.xml
9+
.idea/compiler.xml
10+
.idea/libraries/
11+
*.iws
12+
*.iml
13+
*.ipr
14+
15+
### Eclipse ###
16+
.apt_generated
17+
.classpath
18+
.factorypath
19+
.project
20+
.settings
21+
.springBeans
22+
.sts4-cache
23+
24+
### NetBeans ###
25+
/nbproject/private/
26+
/nbbuild/
27+
/dist/
28+
/nbdist/
29+
/.nb-gradle/
30+
build/
31+
!**/src/main/**/build/
32+
!**/src/test/**/build/
33+
34+
### VS Code ###
35+
.vscode/
36+
37+
### Mac OS ###
38+
.DS_Store

spring-data-jdbc-demo/pom.xml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>com.vonchange.common</groupId>
6+
<artifactId>spring-data-jdbc-mybatis-parent</artifactId>
7+
<version>2.5.0</version>
8+
</parent>
9+
<artifactId>spring-data-jdbc-demo</artifactId>
10+
<packaging>jar</packaging>
11+
12+
<name>spring-data-jdbc-native</name>
13+
<url>http://maven.apache.org</url>
14+
<properties>
15+
<spring.boot.version>2.7.18</spring.boot.version>
16+
<spring.jdbc.mybatis>2.5.0.1</spring.jdbc.mybatis>
17+
<mysql-connector-java.version>8.0.15</mysql-connector-java.version>
18+
<version.slf4j>2.17.0</version.slf4j>
19+
</properties>
20+
<dependencyManagement>
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-dependencies</artifactId>
25+
<version>${spring.boot.version}</version>
26+
<type>pom</type>
27+
<scope>import</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-starter</artifactId>
32+
<version>${spring.boot.version}</version>
33+
<exclusions>
34+
<exclusion>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-logging</artifactId>
37+
</exclusion>
38+
</exclusions>
39+
</dependency>
40+
</dependencies>
41+
</dependencyManagement>
42+
43+
<dependencies>
44+
<dependency>
45+
<groupId>com.vonchange.common</groupId>
46+
<artifactId>jdbc-mybatis</artifactId>
47+
<version>2.5.1</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.springframework.boot</groupId>
51+
<artifactId>spring-boot-starter-web</artifactId>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.springframework.boot</groupId>
55+
<artifactId>spring-boot-starter-log4j2</artifactId>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.springframework.boot</groupId>
59+
<artifactId>spring-boot-starter-data-jdbc</artifactId>
60+
<version>2.1.3.RELEASE</version>
61+
</dependency>
62+
<!--<dependency>
63+
<groupId>org.springframework.boot</groupId>
64+
<artifactId>spring-boot-starter-jdbc</artifactId>
65+
<version>2.1.3.RELEASE</version>
66+
<scope>compile</scope>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.springframework.data</groupId>
70+
<artifactId>spring-data-jdbc</artifactId>
71+
<version>1.0.5.RELEASE</version>
72+
<scope>compile</scope>
73+
</dependency>-->
74+
<dependency>
75+
<groupId>org.projectlombok</groupId>
76+
<artifactId>lombok</artifactId>
77+
<version>1.18.6</version>
78+
</dependency>
79+
<dependency>
80+
<groupId>com.h2database</groupId>
81+
<artifactId>h2</artifactId>
82+
<version>1.4.200</version>
83+
<!--<scope>test</scope>-->
84+
</dependency>
85+
<dependency>
86+
<groupId>mysql</groupId>
87+
<artifactId>mysql-connector-java</artifactId>
88+
<version>8.0.16</version>
89+
</dependency>
90+
<dependency>
91+
<groupId>org.springframework.boot</groupId>
92+
<artifactId>spring-boot-starter-test</artifactId>
93+
<scope>test</scope>
94+
</dependency>
95+
</dependencies>
96+
97+
<build>
98+
<plugins>
99+
<plugin>
100+
<groupId>org.apache.maven.plugins</groupId>
101+
<artifactId>maven-compiler-plugin</artifactId>
102+
<version>3.8.1</version>
103+
<configuration>
104+
<source>1.8</source>
105+
<target>1.8</target>
106+
<encoding>UTF-8</encoding>
107+
<failOnError>false</failOnError>
108+
</configuration>
109+
</plugin>
110+
<plugin>
111+
<groupId>org.apache.maven.plugins</groupId>
112+
<artifactId>maven-deploy-plugin</artifactId>
113+
<version>2.8.2</version>
114+
<configuration>
115+
<skip>true</skip>
116+
</configuration>
117+
</plugin>
118+
<plugin>
119+
<groupId>org.springframework.boot</groupId>
120+
<artifactId>spring-boot-maven-plugin</artifactId>
121+
<version>2.7.18</version>
122+
</plugin>
123+
124+
</plugins>
125+
<resources>
126+
<resource>
127+
<directory>src/main/resources</directory>
128+
</resource>
129+
<resource>
130+
<directory>src/main/java</directory>
131+
<includes>
132+
<include>**/*.md</include>
133+
</includes>
134+
<filtering>true</filtering>
135+
</resource>
136+
</resources>
137+
</build>
138+
</project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.vonchange.common;
2+
3+
import com.vonchange.jdbc.mybatis.MybatisJdbcTemplate;
4+
import com.vonchange.mybatis.dialect.Dialect;
5+
import com.vonchange.mybatis.dialect.MySQLDialect;
6+
import org.springframework.boot.SpringApplication;
7+
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
10+
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
11+
12+
import javax.sql.DataSource;
13+
14+
/**
15+
* Hello world!
16+
*
17+
*/
18+
@SpringBootApplication
19+
@EnableJdbcRepositories
20+
public class App
21+
{
22+
23+
24+
@Bean
25+
public NamedParameterJdbcOperations namedParameterJdbcOperations(DataSource dataSource) {
26+
return new MybatisJdbcTemplate(dataSource) {
27+
@Override
28+
protected Dialect dialect() {
29+
return new MySQLDialect();
30+
}
31+
};
32+
}
33+
public static void main( String[] args )
34+
{
35+
SpringApplication.run(App.class, args);
36+
}
37+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.vonchange.common.dao;
2+
3+
import com.vonchange.common.domain.ReqUser;
4+
import com.vonchange.common.domain.UserDTO;
5+
import com.vonchange.common.domain.UserInfoDO;
6+
import org.springframework.data.domain.Page;
7+
import org.springframework.data.domain.Pageable;
8+
import org.springframework.data.jdbc.repository.query.Modifying;
9+
import org.springframework.data.jdbc.repository.query.Query;
10+
import org.springframework.data.repository.CrudRepository;
11+
import org.springframework.data.repository.query.Param;
12+
13+
import java.util.List;
14+
15+
public interface UserRepository extends CrudRepository<UserInfoDO,Integer> {
16+
17+
@Query("user.queryByUserCode")
18+
//@Query("select * from user_info where user_code =:userCode")
19+
List<UserDTO> queryByUserCode(@Param("userCode") String userCode);
20+
21+
Page<UserInfoDO> findByUserCode(String userCode, Pageable pageable);
22+
//@Query("user.queryByBean")
23+
@Query("select * from user_info where user_code = #{user.userCode}")
24+
List<UserInfoDO> queryByBean(@Param("user") ReqUser user);
25+
@Query("user.queryByUserCodes")
26+
//@Query("select * from user_info where user_code in (:userCodes)")
27+
List<UserDTO> queryByUserCodes(@Param("userCodes")List<String> userCodes);
28+
List<UserInfoDO> queryByUserName(@Param("userName") String userName);
29+
@Modifying
30+
@Query("update user_info set user_name = #{user.userName} where user_code = #{user.userCode}")
31+
int updateByUserCode(@Param("user") UserDTO user);
32+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.vonchange.common.domain;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
import lombok.Setter;
8+
9+
@Getter
10+
@Setter
11+
@AllArgsConstructor
12+
@NoArgsConstructor
13+
@Builder
14+
public class ReqUser {
15+
private String userCode;
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.vonchange.common.domain;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
import lombok.ToString;
6+
7+
@Getter
8+
@Setter
9+
@ToString
10+
public class UserDTO {
11+
private String userCode;
12+
private String userName;
13+
private String address;
14+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.vonchange.common.domain;
2+
3+
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Getter;
7+
import lombok.NoArgsConstructor;
8+
import lombok.Setter;
9+
import lombok.ToString;
10+
import org.springframework.data.annotation.Id;
11+
import org.springframework.data.relational.core.mapping.Table;
12+
13+
@Getter
14+
@Setter
15+
@Table("user_info")
16+
@Builder
17+
@AllArgsConstructor
18+
@NoArgsConstructor
19+
@ToString
20+
public class UserInfoDO {
21+
@Id
22+
private Long id;
23+
private String userCode;
24+
//@Column("user_name")
25+
private String userName;
26+
private String mobileNo;
27+
private String address;
28+
// private boolean isValid;
29+
// private Integer status;
30+
// private byte[] headImageData;
31+
32+
33+
}

0 commit comments

Comments
 (0)