<!-- Mysql-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.76</version>
</dependency>
<!-- commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<!--spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>3.0.4</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.23</version>
</dependency>
<!-- Subject 用户-->
<!-- SecurityManager 管理所有用户-->
<!-- Realm 连接数据库-->
<!-- Shiro整合Spring-->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.11.0</version>
</dependency>
<!-- Thymeleaf ,模板引擎-->
<!--thymeleaf -->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<!-- thymeleaf-spring5 -->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<!--Spring5 Thymeleaf整合-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<!-- swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!-- swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!-- log4j-->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- druid-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.12</version>
</dependency>
<!-- Mybatis整合-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
Thymeleaf 头文件
<html lang="en" xmlns:th="http://www.thymeleaf.org">
整合Mybatis相关最新Jdk需求
整合Mybatis(XML)配置文档(! ! ! 注意尽量不要有中文注释否则可能会无缘无故报错误)
<?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="com.spring_mybatis.mapper.UserMapper">
<select id="getUserLogin" resultType="com.spring_mybatis.pojo.User">
select * from line_managenemt.user where Id_number = #{user}
</select>
<select id="getuserRegister" parameterType="String" resultType="com.spring_mybatis.pojo.User">
select * from line_managenemt.user where Phone = #{Phone} or Id_number = #{Id_number}
</select>
<select id="addUser" resultType="com.spring_mybatis.pojo.User">
insert into line_managenemt.user(`Phone`, `Id_number`, `password`, `mailbox`) VALUES (#{Phone}, #{Id_number}, #{password}, #{mailbox})
</select>
</mapper>
Mybatis整合 properties
#==============================数据库相关配置======================================================
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.url=jdbc:mysql://localhost:3306/line_managenemt?serverTimezone=UTC&userUnicode=true&characterEncoding=utf-8
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#==============================在控制台打印出执行的相关sql语句======================================================#
spring.jpa.show-sql=true
#==============================整合Mybatis======================================================#
mybatis.type-aliases-package=com.spring_mybatis.pojo
mybatis.mapper-locations=classpath:mapper/*.xml
#==============================swagger升级2.6x之后和springboot出现了不兼容情况======================================================#
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
Ruid(德鲁伊)数据源
@Configuration
class ruidConfig {
@ConfigurationProperties(prefix = "spring.datasource")
@Bean
public DataSource druidDataSource(){
return new DruidDataSource();
}
// 后台监控:web.xml
@Bean
public ServletRegistrationBean statViewServlet(){
ServletRegistrationBean<StatViewServlet> bean = new ServletRegistrationBean<>(new StatViewServlet(),"/druid/*");
// 后台管理员的登陆,账号密码设置
HashMap<String, String> initParameters = new HashMap<>();
// 增加配置
initParameters.put("loginUsername","root");//登录的key是固定的 loginUsername
initParameters.put("loginPassword","admin");
// 允许谁可以访问为空这都可
initParameters.put("allow","");
// 禁止可以访问
// initParameters.put("gorge","192.168.92.131");
// 设置初始化
bean.setInitParameters(initParameters);
return bean;
}
}
yml配置文件
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
initialSize: 5
minIdle: 5
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
filters: stat,wall,log4j
maxPoolPreparedStatementPerConnectionSize: 20
useGlobalDataSourceStat: true
connectionionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
Swagger(测试)
@Configuration
@EnableSwagger2 //开启Swagger2
public class SwaggerConfig {
// 配置Swagger的Docket的bean实例
@Bean
public Docket docket(){
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo());
}
// 配置Swagger 信息 = apiInfo
private ApiInfo apiInfo(){
// 作者信息
Contact contact = new Contact("George","https://www.baidu.com","@163.com");
// 具体信息
return new ApiInfo(
"Swagger测试文档",
"不听老人言开心好几年",
"V1.0",
"https://www.baidu.com",
contact,
"Swagger2",
"https://www.baidu.com",
new ArrayList()
);
}