Skip to content

Commit ddea0ba

Browse files
committed
mybatis plus
1 parent e3e4c4e commit ddea0ba

File tree

9 files changed

+284
-0
lines changed

9 files changed

+284
-0
lines changed

springboot-mybatis-plus/pom.xml

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.1.3.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>cn.tellsea</groupId>
12+
<artifactId>springboot-mybatis-plus</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>springboot-mybatis-plus</name>
15+
<description>Demo project for Spring Boot</description>
16+
17+
<properties>
18+
<java.version>1.8</java.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-web</artifactId>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-test</artifactId>
30+
<scope>test</scope>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>com.baomidou</groupId>
35+
<artifactId>mybatis-plus-boot-starter</artifactId>
36+
<version>3.1.2</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>mysql</groupId>
40+
<artifactId>mysql-connector-java</artifactId>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>org.projectlombok</groupId>
45+
<artifactId>lombok</artifactId>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>com.alibaba</groupId>
50+
<artifactId>fastjson</artifactId>
51+
<version>1.2.7</version>
52+
</dependency>
53+
54+
<!-- druid数据源 -->
55+
<dependency>
56+
<groupId>com.alibaba</groupId>
57+
<artifactId>druid-spring-boot-starter</artifactId>
58+
<version>1.1.14</version>
59+
</dependency>
60+
<dependency>
61+
<groupId>log4j</groupId>
62+
<artifactId>log4j</artifactId>
63+
<version>1.2.17</version>
64+
</dependency>
65+
</dependencies>
66+
67+
<build>
68+
<plugins>
69+
<plugin>
70+
<groupId>org.springframework.boot</groupId>
71+
<artifactId>spring-boot-maven-plugin</artifactId>
72+
</plugin>
73+
</plugins>
74+
</build>
75+
76+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package cn.tellsea;
2+
3+
import org.mybatis.spring.annotation.MapperScan;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
7+
/**
8+
* 启动类
9+
*
10+
* @author Tellsea
11+
* @Description Created on 2019/8/4
12+
*/
13+
@SpringBootApplication
14+
@MapperScan("cn.tellsea.mapper")
15+
public class SpringbootMybatisPlusApplication {
16+
17+
public static void main(String[] args) {
18+
SpringApplication.run(SpringbootMybatisPlusApplication.class, args);
19+
}
20+
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package cn.tellsea.entity;
2+
3+
import com.alibaba.fastjson.annotation.JSONField;
4+
import com.baomidou.mybatisplus.annotation.IdType;
5+
import com.baomidou.mybatisplus.annotation.TableId;
6+
import lombok.Data;
7+
8+
import java.util.Date;
9+
10+
/**
11+
* 用户表 实体类
12+
*
13+
* @author Tellsea
14+
* @Description Created on 2019-08-03
15+
*/
16+
@Data
17+
public class UserInfo {
18+
19+
/**
20+
* 用户ID
21+
*/
22+
@TableId(type = IdType.AUTO)
23+
private Integer id;
24+
25+
/**
26+
* 用户名
27+
*/
28+
private String userName;
29+
30+
/**
31+
* 账户,登录名,不可更改
32+
*/
33+
private String nickName;
34+
35+
/**
36+
* 密码
37+
*/
38+
private String password;
39+
40+
/**
41+
* 盐值
42+
*/
43+
private String salt;
44+
45+
/**
46+
* 头像
47+
*/
48+
private String avatar;
49+
50+
/**
51+
* 手机
52+
*/
53+
private String phone;
54+
55+
/**
56+
* 性别 1男 2女
57+
*/
58+
private Integer sex;
59+
60+
/**
61+
* 描述
62+
*/
63+
private String description;
64+
65+
/**
66+
* 状态 0 锁定 1有效
67+
*/
68+
private Boolean status;
69+
70+
/**
71+
* 创建人
72+
*/
73+
private int createUser;
74+
75+
/**
76+
* 创建时间
77+
*/
78+
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
79+
private Date createTime;
80+
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package cn.tellsea.mapper;
2+
3+
import cn.tellsea.entity.UserInfo;
4+
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5+
6+
/**
7+
* @author Tellsea
8+
* @Description Created on 2019/8/4
9+
*/
10+
public interface UserInfoMapper extends BaseMapper<UserInfo> {
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package cn.tellsea.service;
2+
3+
/**
4+
* @author Tellsea
5+
* @Description Created on 2019/8/4
6+
*/
7+
public interface UserInfoService {
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package cn.tellsea.service.impl;
2+
3+
import org.springframework.stereotype.Service;
4+
5+
/**
6+
* @author Tellsea
7+
* @Description Created on 2019/8/4
8+
*/
9+
@Service
10+
public class UserInfoService implements cn.tellsea.service.UserInfoService {
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
spring:
2+
datasource:
3+
type: com.alibaba.druid.pool.DruidDataSource
4+
driver-class-name: com.mysql.jdbc.Driver
5+
platform: mysql
6+
url: jdbc:mysql://127.0.0.1:3306/skeleton?useUnicode=true&characterEncoding=utf-8&useSSL=false
7+
username: root
8+
password: 123456
9+
initialSize: 5
10+
minIdle: 5
11+
maxActive: 20
12+
maxWait: 60000
13+
timeBetweenEvictionRunsMillis: 60000
14+
minEvictableIdleTimeMillis: 300000
15+
validationQuery: SELECT1FROMDUAL
16+
testWhileIdle: true
17+
testOnBorrow: false
18+
testOnReturn: false
19+
filters: stat,wall,log4j
20+
logSlowSql: true
21+
22+
# ÈÕÖ¾
23+
logging:
24+
level:
25+
cn.tellsea.skeleton.business.mapper: debug
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cn.tellsea;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.boot.test.context.SpringBootTest;
6+
import org.springframework.test.context.junit4.SpringRunner;
7+
8+
@RunWith(SpringRunner.class)
9+
@SpringBootTest
10+
public class SpringbootMybatisPlusApplicationTests {
11+
12+
@Test
13+
public void contextLoads() {
14+
}
15+
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package cn.tellsea.service.impl;
2+
3+
import cn.tellsea.SpringbootMybatisPlusApplicationTests;
4+
import cn.tellsea.entity.UserInfo;
5+
import cn.tellsea.mapper.UserInfoMapper;
6+
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
7+
import org.junit.Test;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
10+
import static org.junit.Assert.*;
11+
12+
public class UserInfoServiceTest extends SpringbootMybatisPlusApplicationTests {
13+
14+
@Autowired
15+
private UserInfoMapper userInfoMapper;
16+
17+
@Test
18+
public void save() {
19+
UserInfo userInfo = new UserInfo();
20+
userInfo.setUserName("mybatis plus");
21+
int count = userInfoMapper.insert(userInfo);
22+
if (count != 1) {
23+
System.out.println("error");
24+
} else {
25+
System.out.println("success");
26+
}
27+
}
28+
29+
@Test
30+
public void list() {
31+
QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
32+
queryWrapper.getSqlSelect();
33+
userInfoMapper.selectObjs(queryWrapper);
34+
}
35+
}

0 commit comments

Comments
 (0)