目录
dependency
yml
Config
qq邮箱Config
Common
响应类
分页类
校验数据类
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
org.projectlombok
lombok
1.18.20
true
org.springframework.boot
spring-boot-starter-test
test
com.mysql
mysql-connector-j
8.0.32
com.alibaba
druid
1.1.16
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.2.0
com.baomidou
mybatis-plus-boot-starter
3.4.2
org.springframework.boot
spring-boot-starter-thymeleaf
org.apache.tomcat.embed
tomcat-embed-jasper
provided
org.springframework.boot
spring-boot-starter-security
org.springframework.boot
spring-boot-starter-data-redis
2.5.9
com.alibaba
fastjson
1.2.33
io.jsonwebtoken
jjwt
0.9.0
com.github.pagehelper
pagehelper-spring-boot-starter
1.4.1
org.springframework.boot
spring-boot-starter-mail
spring:
mail:
# 你的邮箱地址
username: [email protected]
# 授权码
password: ********
# 默认的邮件编码为UTF-8
default-encoding: UTF-8
# 邮件服务器地址
host: smtp.qq.com
port: 465
properties:
mail:
transport:
protocol: smtps
smtps:
ssl:
enable: true
auth: true
starttls:
enable: true
# 数据库源
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/library?useSSL=true&useUnicode=true&characterEncoding=UTF-8
username: root
password: root
#端口
thymeleaf:
# cache是否开启模板缓存
cache: false
# 表示模板文件的编码格式
encoding: UTF-8
# mode :模板语法的模式,默认HTML5
mode: HTML5
# prefix 表示模板文件存放的路径
prefix: classpath:/templates/
# 表示模板文件的后缀名 SpringBoot中通常用Thymeleaf作为模板引擎。
suffix: .jsp
# SpringMvc自动处理静态资源请求,并将请求映射到指定的URL路径下,可以方便得管理静态资源,提高Web应用的性能和可维护性。
mvc:
static-path-pattern: /static/**
server:
port: 8080
mybatis-plus:
mapper-locations: classpath*:/mapper/*.xml
type-aliases-package: com.ma.entity
configuration:
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
id-type: ASSIGN_ID
#日志
logging:
level:
root: ERROR # 设置根日志级别为ERROR,只输出错误级别的日志
com.gl: WARN # 设置com.example包下的日志级别为WARN,只输出警告级别以上的日志
org.apache.ibatis: WARN # 设置 MyBatis 包下的日志级别为 WARN,限制日志输出为 WARN 级别及以上
# 分页插件配置
pagehelper:
helper-dialect: mysql
reasonable: true
support-methods-arguments: true
package com.ma.springboot_test01.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import java.util.Properties;
/**
* @author Mtz
* @version 1.0
* @2023/4/910:40
* @function
* @comment
*/
@Configuration
@ConfigurationProperties(prefix = "spring.mail")
public class MailSenderConfig {
@Value("${spring.mail.host}")
private String host;
@Value("${spring.mail.port}")
private int port;
@Value("${spring.mail.username}")
private String username;
@Value("${spring.mail.password}")
private String password;
@Bean
public JavaMailSender mailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(host);
mailSender.setPort(port);
mailSender.setUsername(username);
mailSender.setPassword(password);
mailSender.setJavaMailProperties(getMailProperties());
return mailSender;
}
private Properties getMailProperties() {
Properties properties = new Properties();
properties.put("mail.transport.protocol", "smtps");
properties.put("mail.smtps.auth", "true");
properties.put("mail.smtps.starttls.enable", "true");
properties.put("mail.smtps.ssl.enable", "true");
properties.put("mail.smtps.ssl.trust", host);
return properties;
}
}
package com.ma.common;
import lombok.Data;
import java.util.HashMap;
import java.util.Map;
@Data
public class R {
private Integer code; //编码:1成功,0和其它数字为失败
private String msg; //错误信息
private T data; //数据
private Map map = new HashMap(); //动态数据
public static R success(T object) {
R r = new R();
r.data = object;
r.code = 1;
return r;
}
public static R error(String msg) {
R r = new R();
r.msg = msg;
r.code = 0;
return r;
}
public R add(String key, Object value) {
this.map.put(key, value);
return this;
}
}
import com.fasterxml.jackson.annotation.JsonInclude;
/**
* @Author 三更 B站: https://space.bilibili.com/663528522
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseResult {
/**
* 状态码
*/
private Integer code;
/**
* 提示信息,如果有错误时,前端可以获取该字段进行提示
*/
private String msg;
/**
* 查询到的结果数据,
*/
private T data;
public ResponseResult(Integer code, String msg) {
this.code = code;
this.msg = msg;
}
public ResponseResult(Integer code, T data) {
this.code = code;
this.data = data;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public ResponseResult(Integer code, String msg, T data) {
this.code = code;
this.msg = msg;
this.data = data;
}
}
package com.ma.common;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class PageResult {
//当前页
private int pageNum;
//每页的数量
private int pageSize;
//当前页的数量
private int size;
//由于startRow和endRow不常用,这里说个具体的用法
//可以在页面中"显示startRow到endRow 共size条数据"
//当前页面第一个元素在数据库中的行号
private int startRow;
//当前页面最后一个元素在数据库中的行号
private int endRow;
//总记录数
private long total;
//总页数
private int pages;
//结果集
private List list;
//前一页
private int prePage;
//下一页
private int nextPage;
//是否为第一页
private boolean isFirstPage;
//是否为最后一页
private boolean isLastPage;
//是否有前一页
private boolean hasPreviousPage;
//是否有下一页
private boolean hasNextPage;
//导航页码数
private int navigatePages;
//所有导航页号
private int[] navigatepageNums;
//导航条上的第一页
private int navigateFirstPage;
//导航条上的最后一页
private int navigateLastPage;
}
public class CheckData {
public static boolean isUsername(String input) {
input = input.trim(); // 去除空格
String regex = "^[a-zA-Z0-9]{5,12}$";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(input);
return matcher.matches();
}
public static boolean isPassword(String password) {
password = password.trim(); // 去除空格
String regex = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=~!])(?=\\S+$).{7,12}$";
return password.matches(regex);
}
public static boolean isQQEmail(String email) {
email = email.trim(); // 去除空格
String regex = "^[1-9]\\d{4,10}@qq\\.com$";
return email.matches(regex);
}
}