Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3e3ad70

Browse files
committed
Spring Boot MyBatis Demo
1 parent4f1a3d6 commit3e3ad70

File tree

26 files changed

+102
-167
lines changed

26 files changed

+102
-167
lines changed

‎spring-boot-mybatis-annotation/src/main/resources/application.properties‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎spring-boot-mybatis-xml/src/main/java/com/neo/mapper/UserMapper.java‎

Lines changed: 0 additions & 19 deletions
This file was deleted.

‎spring-boot-mybatis-xml/src/main/resources/application.properties‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎spring-boot-mybatis-annotation/pom.xml‎renamed to ‎spring-boot-mybatis/spring-boot-mybatis-annotation/pom.xml‎

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<parent>
1515
<groupId>org.springframework.boot</groupId>
1616
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>1.4.1.RELEASE</version>
17+
<version>2.1.0.RELEASE</version>
1818
<relativePath/><!-- lookup parent from repository-->
1919
</parent>
2020

@@ -24,63 +24,31 @@
2424
</properties>
2525

2626
<dependencies>
27-
<dependency>
28-
<groupId>org.springframework.boot</groupId>
29-
<artifactId>spring-boot-starter</artifactId>
30-
</dependency>
31-
<dependency>
32-
<groupId>org.springframework.boot</groupId>
33-
<artifactId>spring-boot-starter-test</artifactId>
34-
<scope>test</scope>
35-
</dependency>
3627
<dependency>
3728
<groupId>org.springframework.boot</groupId>
3829
<artifactId>spring-boot-starter-web</artifactId>
3930
</dependency>
4031
<dependency>
4132
<groupId>org.mybatis.spring.boot</groupId>
4233
<artifactId>mybatis-spring-boot-starter</artifactId>
43-
<version>1.1.1</version>
34+
<version>2.0.0</version>
4435
</dependency>
4536
<dependency>
4637
<groupId>mysql</groupId>
4738
<artifactId>mysql-connector-java</artifactId>
4839
</dependency>
49-
<dependency>
50-
<groupId>org.springframework.boot</groupId>
51-
<artifactId>spring-boot-devtools</artifactId>
52-
<optional>true</optional>
40+
<dependency>
41+
<groupId>org.springframework.boot</groupId>
42+
<artifactId>spring-boot-starter-test</artifactId>
43+
<scope>test</scope>
5344
</dependency>
5445
</dependencies>
5546

5647
<build>
57-
<resources>
58-
<resource>
59-
<directory>src/main/resources</directory>
60-
<filtering>true</filtering>
61-
<excludes>
62-
<exclude>bootstrap-test.properties</exclude>
63-
<exclude>bootstrap-dev.properties</exclude>
64-
<exclude>bootstrap-pro.properties</exclude>
65-
<exclude>bootstrap.properties</exclude>
66-
</excludes>
67-
</resource>
68-
<resource>
69-
<directory>src/main/resources</directory>
70-
<filtering>true</filtering>
71-
<includes>
72-
<include>bootstrap-${env}.properties</include>
73-
<include>bootstrap.properties</include>
74-
</includes>
75-
</resource>
76-
</resources>
7748
<plugins>
7849
<plugin>
7950
<groupId>org.springframework.boot</groupId>
8051
<artifactId>spring-boot-maven-plugin</artifactId>
81-
<configuration>
82-
<fork>true</fork>
83-
</configuration>
8452
</plugin>
8553
</plugins>
8654
</build>

‎spring-boot-mybatis-xml/src/main/java/com/neo/Application.java‎renamed to ‎spring-boot-mybatis/spring-boot-mybatis-annotation/src/main/java/com/neo/MybatisAnnotationApplication.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
@SpringBootApplication
88
@MapperScan("com.neo.mapper")
9-
publicclassApplication {
9+
publicclassMybatisAnnotationApplication {
1010

1111
publicstaticvoidmain(String[]args) {
12-
SpringApplication.run(Application.class,args);
12+
SpringApplication.run(MybatisAnnotationApplication.class,args);
1313
}
1414
}

‎spring-boot-mybatis-annotation/src/main/java/com/neo/mapper/UserMapper.java‎renamed to ‎spring-boot-mybatis/spring-boot-mybatis-annotation/src/main/java/com/neo/mapper/UserMapper.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
importjava.util.List;
44

5+
importcom.neo.model.User;
56
importorg.apache.ibatis.annotations.Delete;
67
importorg.apache.ibatis.annotations.Insert;
78
importorg.apache.ibatis.annotations.Result;
89
importorg.apache.ibatis.annotations.Results;
910
importorg.apache.ibatis.annotations.Select;
1011
importorg.apache.ibatis.annotations.Update;
1112

12-
importcom.neo.entity.UserEntity;
1313
importcom.neo.enums.UserSexEnum;
1414

1515
publicinterfaceUserMapper {
@@ -19,20 +19,20 @@ public interface UserMapper {
1919
@Result(property ="userSex",column ="user_sex",javaType =UserSexEnum.class),
2020
@Result(property ="nickName",column ="nick_name")
2121
})
22-
List<UserEntity>getAll();
22+
List<User>getAll();
2323

2424
@Select("SELECT * FROM users WHERE id = #{id}")
2525
@Results({
2626
@Result(property ="userSex",column ="user_sex",javaType =UserSexEnum.class),
2727
@Result(property ="nickName",column ="nick_name")
2828
})
29-
UserEntitygetOne(Longid);
29+
UsergetOne(Longid);
3030

3131
@Insert("INSERT INTO users(userName,passWord,user_sex) VALUES(#{userName}, #{passWord}, #{userSex})")
32-
voidinsert(UserEntityuser);
32+
voidinsert(Useruser);
3333

3434
@Update("UPDATE users SET userName=#{userName},nick_name=#{nickName} WHERE id =#{id}")
35-
voidupdate(UserEntityuser);
35+
voidupdate(Useruser);
3636

3737
@Delete("DELETE FROM users WHERE id =#{id}")
3838
voiddelete(Longid);

‎spring-boot-mybatis-xml/src/main/java/com/neo/entity/UserEntity.java‎renamed to ‎spring-boot-mybatis/spring-boot-mybatis-annotation/src/main/java/com/neo/model/User.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
packagecom.neo.entity;
1+
packagecom.neo.model;
22

33
importjava.io.Serializable;
44

55
importcom.neo.enums.UserSexEnum;
66

7-
publicclassUserEntityimplementsSerializable {
7+
publicclassUserimplementsSerializable {
88

99
privatestaticfinallongserialVersionUID =1L;
1010
privateLongid;
@@ -13,11 +13,11 @@ public class UserEntity implements Serializable {
1313
privateUserSexEnumuserSex;
1414
privateStringnickName;
1515

16-
publicUserEntity() {
16+
publicUser() {
1717
super();
1818
}
1919

20-
publicUserEntity(StringuserName,StringpassWord,UserSexEnumuserSex) {
20+
publicUser(StringuserName,StringpassWord,UserSexEnumuserSex) {
2121
super();
2222
this.passWord =passWord;
2323
this.userName =userName;

‎spring-boot-mybatis-annotation/src/main/java/com/neo/web/UserController.java‎renamed to ‎spring-boot-mybatis/spring-boot-mybatis-annotation/src/main/java/com/neo/web/UserController.java‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
importorg.springframework.web.bind.annotation.RequestMapping;
88
importorg.springframework.web.bind.annotation.RestController;
99

10-
importcom.neo.entity.UserEntity;
10+
importcom.neo.model.User;
1111
importcom.neo.mapper.UserMapper;
1212

1313
@RestController
@@ -17,24 +17,24 @@ public class UserController {
1717
privateUserMapperuserMapper;
1818

1919
@RequestMapping("/getUsers")
20-
publicList<UserEntity>getUsers() {
21-
List<UserEntity>users=userMapper.getAll();
20+
publicList<User>getUsers() {
21+
List<User>users=userMapper.getAll();
2222
returnusers;
2323
}
2424

2525
@RequestMapping("/getUser")
26-
publicUserEntitygetUser(Longid) {
27-
UserEntityuser=userMapper.getOne(id);
26+
publicUsergetUser(Longid) {
27+
Useruser=userMapper.getOne(id);
2828
returnuser;
2929
}
3030

3131
@RequestMapping("/add")
32-
publicvoidsave(UserEntityuser) {
32+
publicvoidsave(Useruser) {
3333
userMapper.insert(user);
3434
}
3535

3636
@RequestMapping(value="update")
37-
publicvoidupdate(UserEntityuser) {
37+
publicvoidupdate(Useruser) {
3838
userMapper.update(user);
3939
}
4040

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
mybatis.type-aliases-package=com.neo.model
2+
3+
spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true
4+
spring.datasource.username=root
5+
spring.datasource.password=root
6+
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp