mirror of
https://gitee.com/yudaocode/SpringBoot-Labs.git
synced 2026-09-03 05:53:54 +08:00
增加 lab-12-mybatis-plus 项目(部分)
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# Spring Security Setting
|
||||
security.user.name=yunai
|
||||
security.user.password=1024
|
||||
@@ -0,0 +1,3 @@
|
||||
# Spring Security Setting
|
||||
security.user.name=yunai
|
||||
security.user.password=1024
|
||||
@@ -0,0 +1,9 @@
|
||||
# Spring Security Setting
|
||||
security.user.name=yunai
|
||||
security.user.password=1024
|
||||
|
||||
##################### MySQL #####################
|
||||
jdbc.driverClassName=com.mysql.jdbc.Driver
|
||||
jdbc.url=jdbc:mysql://127.0.0.1:33061/oauth2
|
||||
jdbc.user=root
|
||||
jdbc.pass=123456
|
||||
@@ -0,0 +1,21 @@
|
||||
INSERT INTO oauth_client_details
|
||||
(client_id, client_secret, scope, authorized_grant_types,
|
||||
web_server_redirect_uri, authorities, access_token_validity,
|
||||
refresh_token_validity, additional_information, autoapprove)
|
||||
VALUES
|
||||
('fooClientIdPassword', 'secret', 'foo,read,write',
|
||||
'password,authorization_code,refresh_token', null, null, 36000, 36000, null, true);
|
||||
INSERT INTO oauth_client_details
|
||||
(client_id, client_secret, scope, authorized_grant_types,
|
||||
web_server_redirect_uri, authorities, access_token_validity,
|
||||
refresh_token_validity, additional_information, autoapprove)
|
||||
VALUES
|
||||
('sampleClientId', 'secret', 'read,write,foo,bar',
|
||||
'implicit', null, null, 36000, 36000, null, false);
|
||||
INSERT INTO oauth_client_details
|
||||
(client_id, client_secret, scope, authorized_grant_types,
|
||||
web_server_redirect_uri, authorities, access_token_validity,
|
||||
refresh_token_validity, additional_information, autoapprove)
|
||||
VALUES
|
||||
('barClientIdPassword', 'secret', 'bar,read,write',
|
||||
'password,authorization_code,refresh_token', null, null, 36000, 36000, null, true);
|
||||
@@ -0,0 +1,66 @@
|
||||
--------------- MySQL ---------------
|
||||
drop table if exists oauth_client_details;
|
||||
create table oauth_client_details (
|
||||
client_id VARCHAR(255) PRIMARY KEY,
|
||||
resource_ids VARCHAR(255),
|
||||
client_secret VARCHAR(255),
|
||||
scope VARCHAR(255),
|
||||
authorized_grant_types VARCHAR(255),
|
||||
web_server_redirect_uri VARCHAR(255),
|
||||
authorities VARCHAR(255),
|
||||
access_token_validity INTEGER,
|
||||
refresh_token_validity INTEGER,
|
||||
additional_information VARCHAR(4096),
|
||||
autoapprove VARCHAR(255)
|
||||
);
|
||||
|
||||
create table if not exists oauth_client_token (
|
||||
token_id VARCHAR(255),
|
||||
token LONG VARBINARY,
|
||||
authentication_id VARCHAR(255) PRIMARY KEY,
|
||||
user_name VARCHAR(255),
|
||||
client_id VARCHAR(255)
|
||||
);
|
||||
|
||||
create table if not exists oauth_access_token (
|
||||
token_id VARCHAR(255),
|
||||
token LONG VARBINARY,
|
||||
authentication_id VARCHAR(255) PRIMARY KEY,
|
||||
user_name VARCHAR(255),
|
||||
client_id VARCHAR(255),
|
||||
authentication LONG VARBINARY,
|
||||
refresh_token VARCHAR(255)
|
||||
);
|
||||
|
||||
create table if not exists oauth_refresh_token (
|
||||
token_id VARCHAR(255),
|
||||
token LONG VARBINARY,
|
||||
authentication LONG VARBINARY
|
||||
);
|
||||
|
||||
create table if not exists oauth_code (
|
||||
code VARCHAR(255), authentication LONG VARBINARY
|
||||
);
|
||||
|
||||
create table if not exists oauth_approvals (
|
||||
userId VARCHAR(255),
|
||||
clientId VARCHAR(255),
|
||||
scope VARCHAR(255),
|
||||
status VARCHAR(10),
|
||||
expiresAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
lastModifiedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
create table if not exists ClientDetails (
|
||||
appId VARCHAR(255) PRIMARY KEY,
|
||||
resourceIds VARCHAR(255),
|
||||
appSecret VARCHAR(255),
|
||||
scope VARCHAR(255),
|
||||
grantTypes VARCHAR(255),
|
||||
redirectUrl VARCHAR(255),
|
||||
authorities VARCHAR(255),
|
||||
access_token_validity INTEGER,
|
||||
refresh_token_validity INTEGER,
|
||||
additionalInformation VARCHAR(4096),
|
||||
autoApproveScopes VARCHAR(255)
|
||||
);
|
||||
@@ -0,0 +1,3 @@
|
||||
# Spring Security Setting
|
||||
security.user.name=yunai
|
||||
security.user.password=1024
|
||||
@@ -0,0 +1,3 @@
|
||||
# Spring Security Setting
|
||||
security.user.name=yunai
|
||||
security.user.password=1024
|
||||
@@ -0,0 +1,3 @@
|
||||
# Spring Security Setting
|
||||
security.user.name=yunai
|
||||
security.user.password=1024
|
||||
29
lab-03/target/classes/application.properties
Normal file
29
lab-03/target/classes/application.properties
Normal file
@@ -0,0 +1,29 @@
|
||||
#============== kafka ===================
|
||||
# 指定kafka 代理地址,可以多个
|
||||
spring.kafka.bootstrap-servers=127.0.0.1:9092
|
||||
|
||||
#=============== provider =======================
|
||||
|
||||
spring.kafka.producer.retries=0
|
||||
# 每次批量发送消息的数量
|
||||
spring.kafka.producer.batch-size=16384
|
||||
spring.kafka.producer.buffer-memory=33554432
|
||||
|
||||
# 指定消息key和消息体的编解码方式
|
||||
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
|
||||
spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer
|
||||
|
||||
#=============== consumer =======================
|
||||
# 指定默认消费者group id
|
||||
spring.kafka.consumer.group-id=test-consumer-group6
|
||||
|
||||
spring.kafka.listener.concurrency=10
|
||||
|
||||
spring.kafka.consumer.auto-offset-reset=earliest
|
||||
spring.kafka.consumer.enable-auto-commit=true
|
||||
spring.kafka.consumer.auto-commit-interval=100
|
||||
enable.auto.commit=false
|
||||
|
||||
# 指定消息key和消息体的编解码方式
|
||||
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
|
||||
spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer
|
||||
Binary file not shown.
4
lab-05/lab-05-jetty/target/maven-archiver/pom.properties
Normal file
4
lab-05/lab-05-jetty/target/maven-archiver/pom.properties
Normal file
@@ -0,0 +1,4 @@
|
||||
#Created by Apache Maven 3.3.9
|
||||
version=1.0-SNAPSHOT
|
||||
groupId=cn.iocoder.springboot.labs
|
||||
artifactId=lab-05-jetty
|
||||
@@ -0,0 +1,2 @@
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-05/lab-05-jetty/src/main/java/cn/iocoder/springboot/labs/lab05/tomcat/JettyApplication.java
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-05/lab-05-jetty/src/main/java/cn/iocoder/springboot/labs/lab05/tomcat/Controller.java
|
||||
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
#Created by Apache Maven 3.3.9
|
||||
version=1.0-SNAPSHOT
|
||||
groupId=cn.iocoder.springboot.labs
|
||||
artifactId=lab-05-tomcat-apr
|
||||
@@ -0,0 +1,2 @@
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-05/lab-05-tomcat-apr/src/main/java/cn/iocoder/springboot/labs/lab05/tomcat/Controller.java
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-05/lab-05-tomcat-apr/src/main/java/cn/iocoder/springboot/labs/lab05/tomcat/TomcatAprApplication.java
|
||||
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
#Created by Apache Maven 3.3.9
|
||||
version=1.0-SNAPSHOT
|
||||
groupId=cn.iocoder.springboot.labs
|
||||
artifactId=lab-05-tomcat
|
||||
@@ -0,0 +1,2 @@
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-05/lab-05-tomcat/src/main/java/cn/iocoder/springboot/labs/lab05/tomcat/TomcatApplication.java
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-05/lab-05-tomcat/src/main/java/cn/iocoder/springboot/labs/lab05/tomcat/Controller.java
|
||||
@@ -0,0 +1,2 @@
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-05/lab-05-tomcat/src/main/java/cn/iocoder/springboot/labs/lab05/tomcat/TomcatApplication.java
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-05/lab-05-tomcat/src/main/java/cn/iocoder/springboot/labs/lab05/tomcat/Controller.java
|
||||
BIN
lab-05/lab-05-undertow/target/lab-05-undertow-1.0.0.jar.original
Normal file
BIN
lab-05/lab-05-undertow/target/lab-05-undertow-1.0.0.jar.original
Normal file
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
#Created by Apache Maven 3.3.9
|
||||
version=1.0.0
|
||||
groupId=cn.iocoder.springboot.labs
|
||||
artifactId=lab-05-undertow
|
||||
@@ -0,0 +1,2 @@
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-05/lab-05-undertow/src/main/java/cn/iocoder/springboot/labs/lab05/undertow/UndertowApplication.java
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-05/lab-05-undertow/src/main/java/cn/iocoder/springboot/labs/lab05/undertow/Controller.java
|
||||
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
#Created by Apache Maven 3.3.9
|
||||
version=1.0-SNAPSHOT
|
||||
groupId=cn.iocoder.springboot.labs
|
||||
artifactId=lab-06-springmvc-tomcat
|
||||
@@ -0,0 +1,2 @@
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-06/lab-06-springmvc-tomcat/src/main/java/cn/iocoder/springboot/labs/lab06/springmvc/SpringMVCApplication.java
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-06/lab-06-springmvc-tomcat/src/main/java/cn/iocoder/springboot/labs/lab06/springmvc/Controller.java
|
||||
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
#Created by Apache Maven 3.3.9
|
||||
version=1.0-SNAPSHOT
|
||||
groupId=cn.iocoder.springboot.labs
|
||||
artifactId=lab-06-webflux-netty
|
||||
@@ -0,0 +1 @@
|
||||
cn/iocoder/springboot/labs/lab06/webflux/WebfluxNettyApplication.class
|
||||
@@ -0,0 +1,2 @@
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-06/lab-06-webflux-netty/src/main/java/cn/iocoder/springboot/labs/lab06/webflux/WebfluxNettyApplication.java
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-06/lab-06-webflux-netty/src/main/java/cn/iocoder/springboot/labs/lab06/webflux/Controller.java
|
||||
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
#Created by Apache Maven 3.3.9
|
||||
version=1.0-SNAPSHOT
|
||||
groupId=cn.iocoder.springboot.labs
|
||||
artifactId=lab-06-webflux-tomcat
|
||||
@@ -0,0 +1,2 @@
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-06/lab-06-webflux-tomcat/src/main/java/cn/iocoder/springboot/labs/lab06/webflux/WebfluxTomcatApplication.java
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-06/lab-06-webflux-tomcat/src/main/java/cn/iocoder/springboot/labs/lab06/webflux/Controller.java
|
||||
@@ -0,0 +1,2 @@
|
||||
server:
|
||||
port: 8081
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
#Created by Apache Maven 3.3.9
|
||||
version=1.0.0
|
||||
groupId=org.springframework.boot
|
||||
artifactId=lab-07-spring-cloud-gateway
|
||||
@@ -0,0 +1 @@
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-07/lab-07-spring-cloud-gateway/src/main/java/cn/iocoder/springboot/labs/lab07/springcloudgateway/SpringCloudGatewayApplication.java
|
||||
13
lab-07/lab-07-zuul/target/classes/application.yml
Normal file
13
lab-07/lab-07-zuul/target/classes/application.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
zuul:
|
||||
routes:
|
||||
static:
|
||||
path: /hello.txt
|
||||
url: http://127.0.0.1:8000/
|
||||
stripPrefix: false
|
||||
api:
|
||||
path: /**
|
||||
url: http://127.0.0.1:8080
|
||||
include-debug-header: true
|
||||
|
||||
server:
|
||||
port: 8081
|
||||
BIN
lab-07/lab-07-zuul/target/lab-07-zuul-1.0.0.jar.original
Normal file
BIN
lab-07/lab-07-zuul/target/lab-07-zuul-1.0.0.jar.original
Normal file
Binary file not shown.
BIN
lab-07/lab-07-zuul/target/lab-07-zuul-2.1.3.RELEASE.jar.original
Normal file
BIN
lab-07/lab-07-zuul/target/lab-07-zuul-2.1.3.RELEASE.jar.original
Normal file
Binary file not shown.
4
lab-07/lab-07-zuul/target/maven-archiver/pom.properties
Normal file
4
lab-07/lab-07-zuul/target/maven-archiver/pom.properties
Normal file
@@ -0,0 +1,4 @@
|
||||
#Created by Apache Maven 3.3.9
|
||||
version=1.0.0
|
||||
groupId=org.springframework.boot
|
||||
artifactId=lab-07-zuul
|
||||
@@ -0,0 +1 @@
|
||||
cn/iocoder/springboot/labs/lab07/zuul/ZuulApplication.class
|
||||
@@ -0,0 +1 @@
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-07/lab-07-zuul/src/main/java/cn/iocoder/springboot/labs/lab07/zuul/ZuulApplication.java
|
||||
22
lab-08/target/classes/application.yaml
Normal file
22
lab-08/target/classes/application.yaml
Normal file
@@ -0,0 +1,22 @@
|
||||
spring:
|
||||
application:
|
||||
name: user-application
|
||||
# jpa
|
||||
redis:
|
||||
password:
|
||||
database: 0
|
||||
port: 6379
|
||||
host: 127.0.0.1
|
||||
timeout: 0
|
||||
jedis:
|
||||
pool:
|
||||
max-wait:
|
||||
max-idle: 8
|
||||
min-idle: 0
|
||||
|
||||
|
||||
# server
|
||||
server:
|
||||
port: 16003
|
||||
servlet:
|
||||
context-path: /user-api/
|
||||
BIN
lab-08/target/lab-08-2.1.4.RELEASE.jar.original
Normal file
BIN
lab-08/target/lab-08-2.1.4.RELEASE.jar.original
Normal file
Binary file not shown.
4
lab-08/target/maven-archiver/pom.properties
Normal file
4
lab-08/target/maven-archiver/pom.properties
Normal file
@@ -0,0 +1,4 @@
|
||||
#Created by Apache Maven 3.3.9
|
||||
version=2.1.4.RELEASE
|
||||
groupId=org.springframework.boot
|
||||
artifactId=lab-08
|
||||
@@ -0,0 +1,2 @@
|
||||
cn/iocoder/springboot/labs/lab08/UserApplication.class
|
||||
cn/iocoder/springboot/labs/lab08/UserController.class
|
||||
@@ -0,0 +1,2 @@
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-08/src/main/java/cn/iocoder/springboot/labs/lab08/UserController.java
|
||||
/Users/yunai/Java/SpringBoot-Labs/lab-08/src/main/java/cn/iocoder/springboot/labs/lab08/UserApplication.java
|
||||
BIN
lab-09/target/classes/META-INF/lab-09.kotlin_module
Normal file
BIN
lab-09/target/classes/META-INF/lab-09.kotlin_module
Normal file
Binary file not shown.
BIN
lab-10/target/classes/META-INF/lab-10.kotlin_module
Normal file
BIN
lab-10/target/classes/META-INF/lab-10.kotlin_module
Normal file
Binary file not shown.
2
lab-10/target/classes/application.properties
Normal file
2
lab-10/target/classes/application.properties
Normal file
@@ -0,0 +1,2 @@
|
||||
management.endpoint.health.show-details=always
|
||||
server.port=9080
|
||||
Binary file not shown.
@@ -0,0 +1,15 @@
|
||||
spring:
|
||||
# 对应 RedisProperties 类
|
||||
redis:
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
password: # Redis 服务器密码,默认为空。生产中,一定要设置 Redis 密码!
|
||||
database: 0 # Redis 数据库号,默认为 0 。
|
||||
timeout: 0 # Redis 连接超时时间,单位:毫秒。
|
||||
# 对应 RedisProperties.Jedis 内部类
|
||||
jedis:
|
||||
pool:
|
||||
max-active: 8 # 连接池最大连接数,默认为 8 。使用负数表示没有限制。
|
||||
max-idle: 8 # 默认连接数最小空闲的连接数,默认为 8 。使用负数表示没有限制。
|
||||
min-idle: 0 # 默认连接池最小空闲的连接数,默认为 0 。允许设置 0 和 正数。
|
||||
max-wait: -1 # 连接池最大阻塞等待时间,单位:毫秒。默认为 -1 ,表示不限制。
|
||||
@@ -0,0 +1,5 @@
|
||||
if redis.call('GET', KEYS[1]) ~= ARGV[1] then
|
||||
return 0
|
||||
end
|
||||
redis.call('SET', KEYS[1], ARGV[2])
|
||||
return 1
|
||||
@@ -0,0 +1 @@
|
||||
return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
if redis.call('GET', KEYS[1]) != ARGV[1] then
|
||||
return {0}
|
||||
end
|
||||
redis.call('SET', KEYS[2], ARGV[2])
|
||||
return {1}
|
||||
Binary file not shown.
Binary file not shown.
43
lab-12/lab-12-mybatis-plus/pom.xml
Normal file
43
lab-12/lab-12-mybatis-plus/pom.xml
Normal file
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.3.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>lab-12-mybatis-plus</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- 实现对数据库连接池的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency> <!-- 本示例,我们使用 MySQL -->
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.48</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对 MyBatis Plus 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.2.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 方便等会写单元测试 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.iocoder.springboot.lab12.mybatis;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@MapperScan(basePackages = "cn.iocoder.springboot.lab12.mybatis.mapper")
|
||||
public class Application {
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package cn.iocoder.springboot.lab12.mybatis.dataobject;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 用户 DO
|
||||
*/
|
||||
@TableName(value = "users")
|
||||
public class UserDO {
|
||||
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 账号
|
||||
*/
|
||||
private String username;
|
||||
/**
|
||||
* 密码(明文)
|
||||
*
|
||||
* ps:生产环境下,千万不要明文噢
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
@TableLogic
|
||||
private Integer deleted;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public UserDO setId(Integer id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public UserDO setUsername(String username) {
|
||||
this.username = username;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public UserDO setPassword(String password) {
|
||||
this.password = password;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public UserDO setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public UserDO setDeleted(Integer deleted) {
|
||||
this.deleted = deleted;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package cn.iocoder.springboot.lab12.mybatis.mapper;
|
||||
|
||||
import cn.iocoder.springboot.lab12.mybatis.dataobject.UserDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface UserMapper extends BaseMapper<UserDO> {
|
||||
|
||||
default UserDO selectByUsername(@Param("username") String username) {
|
||||
return selectOne(new QueryWrapper<UserDO>().eq("username", username));
|
||||
}
|
||||
|
||||
List<UserDO> selectByIds(@Param("ids") Collection<Integer> ids);
|
||||
|
||||
default IPage<UserDO> selectPageByCreateTime(IPage<UserDO> page, @Param("createTime") Date createTime) {
|
||||
return selectPage(page,
|
||||
new QueryWrapper<UserDO>().gt("create_time", createTime));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
spring:
|
||||
# datasource 数据源配置内容
|
||||
datasource:
|
||||
url: jdbc:mysql://47.112.193.81:3306/testb5f4?useSSL=false&useUnicode=true&characterEncoding=UTF-8
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
username: testb5f4
|
||||
password: F4df4db0ed86@11
|
||||
|
||||
# mybatis-plus 配置内容
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。
|
||||
global-config:
|
||||
db-config:
|
||||
id-type: auto # ID 主键自增
|
||||
logic-delete-value: 1 # 逻辑已删除值(默认为 1)
|
||||
logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
|
||||
mapper-locations: classpath*:mapper/*.xml
|
||||
type-aliases-package: cn.iocoder.mall.admin.dataobject
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.springboot.lab12.mybatis.mapper.UserMapper">
|
||||
|
||||
<select id="selectByIds" resultType="UserDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM users
|
||||
WHERE id IN
|
||||
<foreach item="id" collection="ids" separator="," open="(" close=")" index="">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,58 @@
|
||||
package cn.iocoder.springboot.lab12.mybatis.mapper;
|
||||
|
||||
import cn.iocoder.springboot.lab12.mybatis.Application;
|
||||
import cn.iocoder.springboot.lab12.mybatis.dataobject.UserDO;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class)
|
||||
public class UserMapperTest {
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@Test
|
||||
public void testInsert() {
|
||||
UserDO user = new UserDO().setUsername(UUID.randomUUID().toString())
|
||||
.setPassword("nicai").setCreateTime(new Date());
|
||||
userMapper.insert(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateById() {
|
||||
UserDO updateUser = new UserDO().setId(1)
|
||||
.setPassword("wobucai");
|
||||
userMapper.updateById(updateUser);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteById() {
|
||||
userMapper.deleteById(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectById() {
|
||||
userMapper.selectById(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectByUsername() {
|
||||
userMapper.selectByUsername("yunai");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectByIds() {
|
||||
List<UserDO> users = userMapper.selectByIds(Arrays.asList(1, 3));
|
||||
System.out.println("users:" + users.size());
|
||||
}
|
||||
|
||||
}
|
||||
13
lab-12/lab-12-mybatis-plus/target/classes/application.yaml
Normal file
13
lab-12/lab-12-mybatis-plus/target/classes/application.yaml
Normal file
@@ -0,0 +1,13 @@
|
||||
spring:
|
||||
# datasource 数据源配置内容
|
||||
datasource:
|
||||
url: jdbc:mysql://47.112.193.81:3306/testb5f4?useSSL=false&useUnicode=true&characterEncoding=UTF-8
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
username: testb5f4
|
||||
password: F4df4db0ed86@11
|
||||
|
||||
# mybatis 配置内容
|
||||
mybatis:
|
||||
config-location: classpath:mybatis-config.xml # 配置 MyBatis 配置文件路径
|
||||
mapper-locations: classpath:mapper/*.xml # 配置 Mapper XML 地址
|
||||
type-aliases-package: cn.iocoder.springboot.lab12.mybatis.dataobject # 配置数据库实体包路径
|
||||
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.springboot.lab12.mybatis.mapper.UserMapper">
|
||||
|
||||
<sql id="FIELDS">
|
||||
id, username, password, create_time
|
||||
</sql>
|
||||
|
||||
<insert id="insert" parameterType="UserDO" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO users (
|
||||
username, password, create_time
|
||||
) VALUES (
|
||||
#{username}, #{password}, #{createTime}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updateById" parameterType="UserDO">
|
||||
UPDATE users
|
||||
<set>
|
||||
<if test="username != null">
|
||||
, username = #{username}
|
||||
</if>
|
||||
<if test="password != null">
|
||||
, password = #{password}
|
||||
</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteById" parameterType="Integer">
|
||||
DELETE FROM users
|
||||
WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
<select id="selectById" parameterType="Integer" resultType="UserDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM users
|
||||
WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectByUsername" parameterType="String" resultType="UserDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM users
|
||||
WHERE username = #{username}
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="selectByIds" resultType="UserDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM users
|
||||
WHERE id IN
|
||||
<foreach item="id" collection="ids" separator="," open="(" close=")" index="">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
19
lab-12/lab-12-mybatis-plus/target/classes/mybatis-config.xml
Normal file
19
lab-12/lab-12-mybatis-plus/target/classes/mybatis-config.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
|
||||
<configuration>
|
||||
|
||||
<settings>
|
||||
<!-- 使用驼峰命名法转换字段。 -->
|
||||
<setting name="mapUnderscoreToCamelCase" value="true"/>
|
||||
</settings>
|
||||
|
||||
<typeAliases>
|
||||
<typeAlias alias="Integer" type="java.lang.Integer"/>
|
||||
<typeAlias alias="Long" type="java.lang.Long"/>
|
||||
<typeAlias alias="HashMap" type="java.util.HashMap"/>
|
||||
<typeAlias alias="LinkedHashMap" type="java.util.LinkedHashMap"/>
|
||||
<typeAlias alias="ArrayList" type="java.util.ArrayList"/>
|
||||
<typeAlias alias="LinkedList" type="java.util.LinkedList"/>
|
||||
</typeAliases>
|
||||
|
||||
</configuration>
|
||||
13
lab-12/lab-12-mybatis-xml/target/classes/application.yaml
Normal file
13
lab-12/lab-12-mybatis-xml/target/classes/application.yaml
Normal file
@@ -0,0 +1,13 @@
|
||||
spring:
|
||||
# datasource 数据源配置内容
|
||||
datasource:
|
||||
url: jdbc:mysql://47.112.193.81:3306/testb5f4?useSSL=false&useUnicode=true&characterEncoding=UTF-8
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
username: testb5f4
|
||||
password: F4df4db0ed86@11
|
||||
|
||||
# mybatis 配置内容
|
||||
mybatis:
|
||||
config-location: classpath:mybatis-config.xml # 配置 MyBatis 配置文件路径
|
||||
mapper-locations: classpath:mapper/*.xml # 配置 Mapper XML 地址
|
||||
type-aliases-package: cn.iocoder.springboot.lab12.mybatis.dataobject # 配置数据库实体包路径
|
||||
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.springboot.lab12.mybatis.mapper.UserMapper">
|
||||
|
||||
<sql id="FIELDS">
|
||||
id, username, password, create_time
|
||||
</sql>
|
||||
|
||||
<insert id="insert" parameterType="UserDO" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO users (
|
||||
username, password, create_time
|
||||
) VALUES (
|
||||
#{username}, #{password}, #{createTime}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updateById" parameterType="UserDO">
|
||||
UPDATE users
|
||||
<set>
|
||||
<if test="username != null">
|
||||
, username = #{username}
|
||||
</if>
|
||||
<if test="password != null">
|
||||
, password = #{password}
|
||||
</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteById" parameterType="Integer">
|
||||
DELETE FROM users
|
||||
WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
<select id="selectById" parameterType="Integer" resultType="UserDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM users
|
||||
WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectByUsername" parameterType="String" resultType="UserDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM users
|
||||
WHERE username = #{username}
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="selectByIds" resultType="UserDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM users
|
||||
WHERE id IN
|
||||
<foreach item="id" collection="ids" separator="," open="(" close=")" index="">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
19
lab-12/lab-12-mybatis-xml/target/classes/mybatis-config.xml
Normal file
19
lab-12/lab-12-mybatis-xml/target/classes/mybatis-config.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
|
||||
<configuration>
|
||||
|
||||
<settings>
|
||||
<!-- 使用驼峰命名法转换字段。 -->
|
||||
<setting name="mapUnderscoreToCamelCase" value="true"/>
|
||||
</settings>
|
||||
|
||||
<typeAliases>
|
||||
<typeAlias alias="Integer" type="java.lang.Integer"/>
|
||||
<typeAlias alias="Long" type="java.lang.Long"/>
|
||||
<typeAlias alias="HashMap" type="java.util.HashMap"/>
|
||||
<typeAlias alias="LinkedHashMap" type="java.util.LinkedHashMap"/>
|
||||
<typeAlias alias="ArrayList" type="java.util.ArrayList"/>
|
||||
<typeAlias alias="LinkedList" type="java.util.LinkedList"/>
|
||||
</typeAliases>
|
||||
|
||||
</configuration>
|
||||
@@ -14,6 +14,7 @@
|
||||
<modules>
|
||||
<module>lab-12-mybatis-xml</module>
|
||||
<module>lab-12-mybatis-annotation</module>
|
||||
<module>lab-12-mybatis-plus</module>
|
||||
</modules>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user