feat:
- 添加mysql配置 - 添加数据连接池 - 添加mybatis配置 - 添加log配置 - 添加User实体类 - 添加UserMapper - 添加User测试
This commit is contained in:
parent
acf4c56b2b
commit
09be5b02e1
17
.idea/dataSources.xml
Normal file
17
.idea/dataSources.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||||
|
<data-source source="LOCAL" name="@122.152.201.90" uuid="a3d85aef-f993-4fcd-8b75-c4caadf67022">
|
||||||
|
<driver-ref>mysql.8</driver-ref>
|
||||||
|
<synchronize>true</synchronize>
|
||||||
|
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||||
|
<jdbc-url>jdbc:mysql://122.152.201.90:9912</jdbc-url>
|
||||||
|
<jdbc-additional-properties>
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||||
|
</jdbc-additional-properties>
|
||||||
|
<working-dir>$ProjectFileDir$</working-dir>
|
||||||
|
</data-source>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
7
.idea/sqldialects.xml
Normal file
7
.idea/sqldialects.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="SqlDialectMappings">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources/db/data.sql" dialect="MySQL" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources/db/schema.sql" dialect="MySQL" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
15
pom.xml
15
pom.xml
@ -28,7 +28,6 @@
|
|||||||
</scm>
|
</scm>
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
<mail.version>1.6.2</mail.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -44,6 +43,16 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-mail</artifactId>
|
<artifactId>spring-boot-starter-mail</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
|
<version>3.0.3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
<version>8.3.0</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||||
@ -59,8 +68,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sun.mail</groupId>
|
<groupId>com.sun.mail</groupId>
|
||||||
<artifactId>javax.mail</artifactId>
|
<artifactId>jakarta.mail</artifactId>
|
||||||
<version>${mail.version}</version>
|
<version>2.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|||||||
77
src/main/java/asia/yulinling/workflow/entity/User.java
Normal file
77
src/main/java/asia/yulinling/workflow/entity/User.java
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
package asia.yulinling.workflow.entity;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 用户实体类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author yulinling
|
||||||
|
* @since 2025/6/4
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class User {
|
||||||
|
/**
|
||||||
|
* 主键id
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密后的密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密使用盐
|
||||||
|
*/
|
||||||
|
private String salt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号
|
||||||
|
*/
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态 -1:删除 0:警用 1:启用
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上次登录时间
|
||||||
|
*/
|
||||||
|
private Date lastLoginTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上次更新时间
|
||||||
|
*/
|
||||||
|
private Date lastUpdateTime;
|
||||||
|
}
|
||||||
55
src/main/java/asia/yulinling/workflow/mapper/UserMapper.java
Normal file
55
src/main/java/asia/yulinling/workflow/mapper/UserMapper.java
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package asia.yulinling.workflow.mapper;
|
||||||
|
|
||||||
|
import asia.yulinling.workflow.entity.User;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 用户Mapper
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author yulinling
|
||||||
|
* @since 2025/6/4
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
@Component
|
||||||
|
public interface UserMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有用户
|
||||||
|
*
|
||||||
|
* @return 用户列表
|
||||||
|
*/
|
||||||
|
@Select("SELECT * FROM orm_user")
|
||||||
|
List<User> selectAllUser();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询用户
|
||||||
|
*
|
||||||
|
* @param id 主键id
|
||||||
|
* @return 当前id的用户,不存在则是{@code null}
|
||||||
|
*/
|
||||||
|
@Select("SELECT * FROM orm_user WHERE id = #{id}")
|
||||||
|
User selectUserById(@Param("id")Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存用户
|
||||||
|
*
|
||||||
|
* @param user 用户
|
||||||
|
* @return 成功 - {@code 1} 失败 - {@code 0}
|
||||||
|
*/
|
||||||
|
int saveUser(@Param("user") User user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除用户
|
||||||
|
*
|
||||||
|
* @param id 主键id
|
||||||
|
* @return 成功 - {@code 1} 失败 - {@code 0}
|
||||||
|
*/
|
||||||
|
int deleteById(@Param("id")Long id);
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
package asia.yulinling.workflow.service;
|
package asia.yulinling.workflow.service;
|
||||||
|
|
||||||
import javax.mail.MessagingException;
|
import jakarta.mail.MessagingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@ -8,7 +8,7 @@ import javax.mail.MessagingException;
|
|||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author yulinling
|
* @author yulinling
|
||||||
* @date Create in 2025/6/3 22:49
|
* @since Create in 2025/6/3 22:49
|
||||||
*/
|
*/
|
||||||
public interface MailService {
|
public interface MailService {
|
||||||
/**
|
/**
|
||||||
@ -46,14 +46,15 @@ public interface MailService {
|
|||||||
void sendAttachmentsMail(String to, String subject, String content, String filePath, String... cc) throws MessagingException;
|
void sendAttachmentsMail(String to, String subject, String content, String filePath, String... cc) throws MessagingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送带附件邮件
|
* 发送正文带静态资源的邮件
|
||||||
*
|
*
|
||||||
* @param to 收件人地址
|
* @param to 收件人地址
|
||||||
* @param subject 邮件主题
|
* @param subject 邮件主题
|
||||||
* @param content 邮件内容
|
* @param content 邮件内容
|
||||||
* @param rscPath 静态资源地址
|
* @param rscPath 静态资源地址
|
||||||
|
* @param rscId 静态资源id
|
||||||
* @param cc 抄送地址
|
* @param cc 抄送地址
|
||||||
* @throws MessagingException 邮件发送异常
|
* @throws MessagingException 邮件发送异常
|
||||||
*/
|
*/
|
||||||
void sendResourceMail(String to, String subject, String content, String rscPath, String... cc) throws MessagingException;
|
void sendResourceMail(String to, String subject, String content, String rscPath, String rscId, String... cc) throws MessagingException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,11 +4,15 @@ import asia.yulinling.workflow.service.MailService;
|
|||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.core.io.FileSystemResource;
|
||||||
import org.springframework.mail.SimpleMailMessage;
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
import org.springframework.mail.javamail.JavaMailSender;
|
import org.springframework.mail.javamail.JavaMailSender;
|
||||||
|
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.mail.MessagingException;
|
import jakarta.mail.internet.MimeMessage;
|
||||||
|
import jakarta.mail.MessagingException;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@ -36,6 +40,7 @@ public class MailServiceImpl implements MailService {
|
|||||||
@Override
|
@Override
|
||||||
public void sendSimpleMail(String to, String subject, String content, String... cc) {
|
public void sendSimpleMail(String to, String subject, String content, String... cc) {
|
||||||
SimpleMailMessage message = new SimpleMailMessage();
|
SimpleMailMessage message = new SimpleMailMessage();
|
||||||
|
|
||||||
message.setFrom(from);
|
message.setFrom(from);
|
||||||
message.setTo(to);
|
message.setTo(to);
|
||||||
message.setSubject(subject);
|
message.setSubject(subject);
|
||||||
@ -43,6 +48,7 @@ public class MailServiceImpl implements MailService {
|
|||||||
if (ArrayUtil.isNotEmpty(cc)) {
|
if (ArrayUtil.isNotEmpty(cc)) {
|
||||||
message.setCc(cc);
|
message.setCc(cc);
|
||||||
}
|
}
|
||||||
|
|
||||||
mailSender.send(message);
|
mailSender.send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +63,18 @@ public class MailServiceImpl implements MailService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void sendHtmlMail(String to, String subject, String content, String... cc) throws MessagingException {
|
public void sendHtmlMail(String to, String subject, String content, String... cc) throws MessagingException {
|
||||||
|
MimeMessage message = mailSender.createMimeMessage();
|
||||||
|
|
||||||
|
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
||||||
|
helper.setFrom(from);
|
||||||
|
helper.setTo(to);
|
||||||
|
helper.setSubject(subject);
|
||||||
|
helper.setText(content, true);
|
||||||
|
if (ArrayUtil.isNotEmpty(cc)) {
|
||||||
|
helper.setCc(cc);
|
||||||
|
}
|
||||||
|
|
||||||
|
mailSender.send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,21 +89,47 @@ public class MailServiceImpl implements MailService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void sendAttachmentsMail(String to, String subject, String content, String filePath, String... cc) throws MessagingException {
|
public void sendAttachmentsMail(String to, String subject, String content, String filePath, String... cc) throws MessagingException {
|
||||||
|
MimeMessage message = mailSender.createMimeMessage();
|
||||||
|
|
||||||
|
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
||||||
|
helper.setFrom(from);
|
||||||
|
helper.setTo(to);
|
||||||
|
helper.setSubject(subject);
|
||||||
|
helper.setText(content, true);
|
||||||
|
if (ArrayUtil.isNotEmpty(cc)) {
|
||||||
|
helper.setCc(cc);
|
||||||
|
}
|
||||||
|
FileSystemResource file = new FileSystemResource(new File(filePath));
|
||||||
|
helper.addAttachment(file.getFilename(), file);
|
||||||
|
|
||||||
|
mailSender.send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送带附件邮件
|
* 发送正文带静态资源的邮件
|
||||||
*
|
*
|
||||||
* @param to 收件人地址
|
* @param to 收件人地址
|
||||||
* @param subject 邮件主题
|
* @param subject 邮件主题
|
||||||
* @param content 邮件内容
|
* @param content 邮件内容
|
||||||
* @param rscPath 静态资源地址
|
* @param rscPath 静态资源地址
|
||||||
|
* @param rscId 静态资源id
|
||||||
* @param cc 抄送地址
|
* @param cc 抄送地址
|
||||||
* @throws MessagingException 邮件发送异常
|
* @throws MessagingException 邮件发送异常
|
||||||
*/
|
*/
|
||||||
@Override
|
public void sendResourceMail(String to, String subject, String content, String rscPath, String rscId, String... cc) throws MessagingException {
|
||||||
public void sendResourceMail(String to, String subject, String content, String rscPath, String... cc) throws MessagingException {
|
MimeMessage message = mailSender.createMimeMessage();
|
||||||
|
|
||||||
|
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
||||||
|
helper.setFrom(from);
|
||||||
|
helper.setTo(to);
|
||||||
|
helper.setSubject(subject);
|
||||||
|
helper.setText(content, true);
|
||||||
|
if (ArrayUtil.isNotEmpty(cc)) {
|
||||||
|
helper.setCc(cc);
|
||||||
|
}
|
||||||
|
FileSystemResource file = new FileSystemResource(new File(rscPath));
|
||||||
|
helper.addAttachment(rscId, file);
|
||||||
|
|
||||||
|
mailSender.send(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,33 @@
|
|||||||
|
|
||||||
|
# mysql??
|
||||||
|
spring.datasource.url=jdbc:mysql://122.152.201.90:9912/workflow?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&failOverReadOnly=false&serverTimezone=GMT%2B8
|
||||||
|
spring.datasource.username=root
|
||||||
|
spring.datasource.password=0andrx
|
||||||
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
|
spring.sql.init.mode=always
|
||||||
|
spring.sql.init.continue-on-error=true
|
||||||
|
spring.sql.init.schema-locations=classpath:db/schema.sql
|
||||||
|
spring.sql.init.data-locations=classpath:db/data.sql
|
||||||
|
# ?????
|
||||||
|
spring.datasource.hikari.minimum-idle=5
|
||||||
|
spring.datasource.hikari.connection-test-query=SELECT 1
|
||||||
|
spring.datasource.hikari.maximum-pool-size=20
|
||||||
|
spring.datasource.hikari.auto-commit=true
|
||||||
|
spring.datasource.hikari.idle-timeout=30000
|
||||||
|
spring.datasource.hikari.pool-name=MyAppHikariCP
|
||||||
|
spring.datasource.hikari.max-lifetime=300000
|
||||||
|
spring.datasource.hikari.connection-timeout=30000
|
||||||
|
|
||||||
|
# mybatis??
|
||||||
|
mybatis.configuration.map-underscore-to-camel-case=true
|
||||||
|
mybatis.mapper-locations=classpath:mapper/*.xml
|
||||||
|
mybatis.type-aliases-package=asia/yulinling/workflow/entity
|
||||||
|
|
||||||
|
# log??
|
||||||
|
logging.level.asia.yulinling=debug
|
||||||
|
logging.level.asia.yulinling.workflow.mapper=trace
|
||||||
|
|
||||||
|
# mail??
|
||||||
spring.mail.host=smtp.qq.com
|
spring.mail.host=smtp.qq.com
|
||||||
spring.mail.port=587
|
spring.mail.port=587
|
||||||
spring.mail.username=2712495353@qq.com
|
spring.mail.username=2712495353@qq.com
|
||||||
|
|||||||
2
src/main/resources/db/data.sql
Normal file
2
src/main/resources/db/data.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
INSERT INTO `orm_user`(`id`,`name`,`password`,`salt`,`email`,`phone`) VALUES (1, 'user_1', 'ff342e862e7c3285cdc07e56d6b8973b', '412365a109674b2dbb1981ed561a4c70', 'user1@xkcoding.com', '17300000001');
|
||||||
|
INSERT INTO `orm_user`(`id`,`name`,`password`,`salt`,`email`,`phone`) VALUES (2, 'user_2', '6c6bf02c8d5d3d128f34b1700cb1e32c', 'fcbdd0e8a9404a5585ea4e01d0e4d7a0', 'user2@xkcoding.com', '17300000002');
|
||||||
13
src/main/resources/db/schema.sql
Normal file
13
src/main/resources/db/schema.sql
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
DROP TABLE IF EXISTS `orm_user`;
|
||||||
|
CREATE TABLE `orm_user` (
|
||||||
|
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '主键',
|
||||||
|
`name` VARCHAR(32) NOT NULL UNIQUE COMMENT '用户名',
|
||||||
|
`password` VARCHAR(32) NOT NULL COMMENT '加密后的密码',
|
||||||
|
`salt` VARCHAR(32) NOT NULL COMMENT '加密使用的盐',
|
||||||
|
`email` VARCHAR(32) NOT NULL UNIQUE COMMENT '邮箱',
|
||||||
|
`phone` VARCHAR(15) NOT NULL UNIQUE COMMENT '手机号码',
|
||||||
|
`status` INT(2) NOT NULL DEFAULT 1 COMMENT '状态,-1:逻辑删除,0:禁用,1:启用',
|
||||||
|
`create_time` DATETIME NOT NULL DEFAULT NOW() COMMENT '创建时间',
|
||||||
|
`last_login_time` DATETIME DEFAULT NULL COMMENT '上次登录时间',
|
||||||
|
`last_update_time` DATETIME NOT NULL DEFAULT NOW() COMMENT '上次更新时间'
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Spring Boot Demo Orm 系列示例表';
|
||||||
22
src/main/resources/email/test.html
Normal file
22
src/main/resources/email/test.html
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Test Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="welcome">
|
||||||
|
<h3>
|
||||||
|
欢迎使用 TEST HTML
|
||||||
|
<span th:text="${project}">- Powered By <span th:text="${author}"></span></span>
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<span style="text-align: center; padding: 10px">
|
||||||
|
<a style="text-decoration: none" href="#" th:href="@{${url}}" target="_blank">
|
||||||
|
<strong>Spring Boot入门首选</strong>
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
28
src/main/resources/mapper/UserMapper.xml
Normal file
28
src/main/resources/mapper/UserMapper.xml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?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="asia.yulinling.workflow.mapper.UserMapper">
|
||||||
|
<insert id="saveUser">
|
||||||
|
INSERT INTO `orm_user` (`name`,
|
||||||
|
`password`,
|
||||||
|
`salt`,
|
||||||
|
`email`,
|
||||||
|
`phone`,
|
||||||
|
`status`,
|
||||||
|
`create_time`,
|
||||||
|
`last_login_time`,
|
||||||
|
`last_update_time`)
|
||||||
|
VALUES (#{user.name},
|
||||||
|
#{user.password},
|
||||||
|
#{user.salt},
|
||||||
|
#{user.email},
|
||||||
|
#{user.phone},
|
||||||
|
#{user.status},
|
||||||
|
#{user.createTime},
|
||||||
|
#{user.lastLoginTime},
|
||||||
|
#{user.lastUpdateTime})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<delete id="deleteById">
|
||||||
|
DELETE FROM `orm_user` WHERE id = #{id}
|
||||||
|
</delete>
|
||||||
|
</mapper>
|
||||||
BIN
src/main/resources/static/GitHub.ico
Normal file
BIN
src/main/resources/static/GitHub.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 170 KiB |
22
src/main/resources/templates/welcome.html
Normal file
22
src/main/resources/templates/welcome.html
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="welcome">
|
||||||
|
<h3>
|
||||||
|
欢迎使用
|
||||||
|
<span th:text="${project}">- Powered By <span th:text="${author}"></span></span>
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<span style="text-align: center; padding: 10px">
|
||||||
|
<a style="text-decoration: none" href="#" th:href="@{${url}}" target="_blank">
|
||||||
|
<strong>Spring Boot入门首选</strong>
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -0,0 +1,73 @@
|
|||||||
|
package asia.yulinling.workflow.mapper;
|
||||||
|
|
||||||
|
import asia.yulinling.workflow.WorkFlowMainTests;
|
||||||
|
import asia.yulinling.workflow.entity.User;
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.crypto.SecureUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.annotation.Rollback;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 用户Mapper测试
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author yulinling
|
||||||
|
* @since 2025/6/4
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class UserMapperTest extends WorkFlowMainTests {
|
||||||
|
@Autowired
|
||||||
|
private UserMapper userMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void selectAllUser() {
|
||||||
|
List<User> users = userMapper.selectAllUser();
|
||||||
|
Assert.assertTrue(CollUtil.isNotEmpty(users));
|
||||||
|
log.info("users={}", users);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void selectUserById() {
|
||||||
|
User user = userMapper.selectUserById(1L);
|
||||||
|
Assert.assertNotNull(user);
|
||||||
|
log.info("user={}", user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
@Rollback
|
||||||
|
public void saveUser() {
|
||||||
|
String salt = IdUtil.simpleUUID();
|
||||||
|
User user = User.builder()
|
||||||
|
.name("yulinling_test")
|
||||||
|
.password(SecureUtil.md5("123456" + salt))
|
||||||
|
.salt(salt)
|
||||||
|
.email("2712495353@qq.com")
|
||||||
|
.phone("17770898274")
|
||||||
|
.status(1)
|
||||||
|
.lastLoginTime(new DateTime())
|
||||||
|
.createTime(new DateTime())
|
||||||
|
.lastUpdateTime(new DateTime())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
int i = userMapper.saveUser(user);
|
||||||
|
Assert.assertEquals(1, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
@Rollback
|
||||||
|
public void deleteById() {
|
||||||
|
int i = userMapper.deleteById(1L);
|
||||||
|
Assert.assertEquals(1, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,101 @@
|
|||||||
|
package asia.yulinling.workflow.service;
|
||||||
|
|
||||||
|
import asia.yulinling.workflow.WorkFlowMainTests;
|
||||||
|
import cn.hutool.core.io.resource.ResourceUtil;
|
||||||
|
import jakarta.mail.MessagingException;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.thymeleaf.context.Context;
|
||||||
|
import org.thymeleaf.TemplateEngine;
|
||||||
|
import org.thymeleaf.spring6.templateresolver.SpringResourceTemplateResolver;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 邮件测试
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author yulinling
|
||||||
|
* @date 2025/6/4
|
||||||
|
*/
|
||||||
|
public class EmailServiceTest extends WorkFlowMainTests {
|
||||||
|
@Autowired
|
||||||
|
private MailService mailService;
|
||||||
|
@Autowired
|
||||||
|
private TemplateEngine templateEngine;
|
||||||
|
@Autowired
|
||||||
|
private ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试简单邮件
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void sendSimpleMail() {
|
||||||
|
mailService.sendSimpleMail("rsgltzyd@hotmail.com", "test", "test content");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试发送HTML邮件
|
||||||
|
*
|
||||||
|
* @throws MessagingException 邮件异常
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void sendHtmlMail() throws MessagingException {
|
||||||
|
Context context = new Context();
|
||||||
|
context.setVariable("project", "mail test");
|
||||||
|
context.setVariable("author", "yulinlng");
|
||||||
|
context.setVariable("url", "https://github.com/xkcoding/spring-boot-demo");
|
||||||
|
|
||||||
|
String emailTemplate = templateEngine.process("welcome", context);
|
||||||
|
|
||||||
|
mailService.sendHtmlMail("rsgltzyd@hotmail.com", "test", emailTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试自定义模板HTML邮件
|
||||||
|
*
|
||||||
|
* @throws MessagingException 邮件异常
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void sendHtmlMail2() throws MessagingException {
|
||||||
|
|
||||||
|
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
|
||||||
|
resolver.setApplicationContext(applicationContext);
|
||||||
|
resolver.setCacheable(false);
|
||||||
|
resolver.setPrefix("classpath:/email/");
|
||||||
|
resolver.setSuffix(".html");
|
||||||
|
|
||||||
|
templateEngine.setTemplateResolver(resolver);
|
||||||
|
|
||||||
|
Context context = new Context();
|
||||||
|
context.setVariable("project", "mail test");
|
||||||
|
context.setVariable("author", "yulinlng");
|
||||||
|
context.setVariable("url", "https://github.com/xkcoding/spring-boot-demo");
|
||||||
|
|
||||||
|
String emailTemplate = templateEngine.process("test", context);
|
||||||
|
|
||||||
|
mailService.sendHtmlMail("rsgltzyd@hotmail.com", "test", emailTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试附件邮件
|
||||||
|
*
|
||||||
|
* @throws MessagingException
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void sendAttachmentsMail() throws MessagingException {
|
||||||
|
URL resource = ResourceUtil.getResource("static/GitHub.ico");
|
||||||
|
mailService.sendAttachmentsMail("rsgltzyd@hotmail.com", "test", "邮件中有附件,请注意查收", resource.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sendResourceMail() throws MessagingException {
|
||||||
|
String rscId = "rscId";
|
||||||
|
String content = "<html><body><img src=\"cid:rscId\"></body></html>";
|
||||||
|
URL resource = ResourceUtil.getResource("static/GitHub.ico");
|
||||||
|
|
||||||
|
mailService.sendResourceMail("rsgltzyd@hotmail.com", "test", content, resource.getPath(), rscId);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user