-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ming.mu
committed
Mar 9, 2023
1 parent
cfbd945
commit 0ac21c6
Showing
85 changed files
with
2,181 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,32 @@ | ||
# SpringBoot-Integration | ||
SpringBoot简单集成示例 | ||
# SpringBoot 整合教程 | ||
- SpringBoot-shiro 整合mybatis和shiro的一个简单实例 | ||
- SpringBoot-swagger 整合swagger的简单实例 | ||
- SpringBoot-aop 调取接口的时候,打印一条输出语句到控制台 | ||
- SpringBoot-jwt (JSON Web Token) 使用拦截器对接口进行授权 | ||
- SpringBoot-slf4j 对日志进行分批存储和打印 | ||
- SpringBoot-easyExcel 简单使用easyExcel进行Web excel的上传和下载 | ||
- SpringBoot-scheduling SpringBoot定时任务简单实例 | ||
- SpringBoot-threadPool SpringBoot线程池 | ||
|
||
### SpringBoot线程池 | ||
> SpringBoot线程池详解:https://www.jianshu.com/p/c82cacd6e356 | ||
> 线程状态详解:https://www.jianshu.com/p/b09392baddfd | ||
### scheduling定时任务详解 | ||
> 默认情况下,如果什么都不进行配置,就会导致一个问题,系统中所有的定时任务都是使用的一个线程去执行的,也就是说,如果如果同一个时刻有2个定时任务需要执行,那么只可能有一个定时任务在执行,如果要解决这个问题可以定义一个自定的任务调度线程池即可。 | ||
> cron表达式详解:https://help.aliyun.com/document_detail/169784.html?spm=5176.13910061.sslink.4.10607fbbHfhVrM | ||
### jwt注意事项 | ||
> jwt详解:https://www.ruanyifeng.com/blog/2018/07/json_web_token-tutorial.html | ||
### swagger注意事项 | ||
> 导入Swagger依赖之后,在配置类中配置swagger的基础信息,需要注意的是要注明接口扫描方式apis() swagger 访问路径: */swagger-ui/index.html | ||
### aop注意事项 | ||
> 这里需要注意的是切点方法test()并不会执行,环绕方法需要手动proceed(),不然被切入方法不会执行 | ||
### shiro授权流程 | ||
> 1. shiro会根据ShiroFilterFactoryBean此处的过滤器配置,在SpringBoot初始化的时候创建过滤器。 | ||
> 2. Web应用通过接口进行认证授权,(1.获取当前用户SecurityUtils.getSubject,2.UsernamePasswordToken生成Token | ||
> 3. subject.login 执行认证,之后如果过滤器里设置了要走授权,那么认证方法走完后还需要走授权方法) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.ming</groupId> | ||
<artifactId>SpringBoot-Integration</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>SpringBoot-aop</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-aop</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
11 changes: 11 additions & 0 deletions
11
SpringBoot-aop/src/main/java/com/ming/aop/AOPApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.ming.aop; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class AOPApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(AOPApplication.class); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
SpringBoot-aop/src/main/java/com/ming/aop/config/AOPAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.ming.aop.config; | ||
|
||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.*; | ||
import org.springframework.stereotype.Component; | ||
|
||
|
||
@Aspect | ||
@Component | ||
public class AOPAdvice { | ||
/** | ||
* execution:在方法执行时触发 | ||
* 第一个 * :返回任意类型 | ||
* 第二个 * :任意类 | ||
* 第三个 * :任意方法 | ||
* 第四个 * :方法里传任意参数 | ||
* 这里需要注意的是test方法并不会执行,环绕方法需要手动proceed(),不然被切入的类或方法不会执行 | ||
*/ | ||
@Pointcut("execution(* com.ming.aop.controller.*.*(..))") | ||
public String test(){ | ||
System.out.println("test"); | ||
return "test"; | ||
} | ||
|
||
|
||
@Before("test()") | ||
public void beforeAdvice(){ | ||
System.out.println("before"); | ||
} | ||
|
||
|
||
@After("test()") | ||
public void afterAdvice(){ | ||
System.out.println("after"); | ||
} | ||
|
||
@Around("test()") | ||
public void aroundAdvice(ProceedingJoinPoint proceedingJoinPoint){ | ||
System.out.println("before"); | ||
try { | ||
Object proceed = proceedingJoinPoint.proceed(); | ||
System.out.println(proceed); | ||
} catch (Throwable e) { | ||
throw new RuntimeException(e); | ||
} | ||
System.out.println("after"); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
SpringBoot-aop/src/main/java/com/ming/aop/controller/AOPController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.ming.aop.controller; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("aop") | ||
public class AOPController { | ||
|
||
@GetMapping("/testAop") | ||
public String testAop(){ | ||
return "aop"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
server: | ||
port: 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
server: | ||
port: 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.ming</groupId> | ||
<artifactId>SpringBoot-Integration</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>SpringBoot-easyExcel</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>easyexcel</artifactId> | ||
<version>3.1.5</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.24</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
18 changes: 18 additions & 0 deletions
18
SpringBoot-easyExcel/src/main/java/com/ming/easyExcel/EasyExcelApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.ming.easyExcel; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* @ClassName: EasyExcelApplication | ||
* @Description: TODO | ||
* @Author: ECRZ | ||
* @Date: 2023/1/10 | ||
*/ | ||
|
||
@SpringBootApplication | ||
public class EasyExcelApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(EasyExcelApplication.class); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
SpringBoot-easyExcel/src/main/java/com/ming/easyExcel/controller/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.ming.easyExcel.controller; | ||
|
||
import com.ming.easyExcel.service.UserService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
/** | ||
* @ClassName: UserController | ||
* @Description: Excel的上传和下载 | ||
* @Author: ECRZ | ||
* @Date: 2023/1/10 | ||
*/ | ||
@RestController | ||
@RequestMapping("excel") | ||
public class UserController { | ||
|
||
// 不建议字段注入 | ||
@Autowired | ||
private UserService userService; | ||
|
||
@GetMapping("download") | ||
public void download(HttpServletResponse response) throws IOException { | ||
userService.download(response); | ||
} | ||
|
||
@PostMapping("upload") | ||
public String upload(@RequestParam("file")MultipartFile file) throws IOException { | ||
return userService.upload(file); | ||
} | ||
|
||
|
||
} |
25 changes: 25 additions & 0 deletions
25
SpringBoot-easyExcel/src/main/java/com/ming/easyExcel/dto/UserDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.ming.easyExcel.dto; | ||
|
||
import com.alibaba.excel.annotation.ExcelProperty; | ||
import lombok.Data; | ||
|
||
/** | ||
* @ClassName: UserDTO | ||
* @Description: TODO | ||
* @Author: ECRZ | ||
* @Date: 2023/1/10 | ||
*/ | ||
@Data | ||
public class UserDTO { | ||
@ExcelProperty(value = "用户id") | ||
private String userId; | ||
|
||
@ExcelProperty(value = "用户名称") | ||
private String userName; | ||
|
||
@ExcelProperty(value = "用户密码") | ||
private String userPassword; | ||
|
||
@ExcelProperty(value = "用户类型") | ||
private int userType; | ||
} |
53 changes: 53 additions & 0 deletions
53
SpringBoot-easyExcel/src/main/java/com/ming/easyExcel/service/UserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.ming.easyExcel.service; | ||
|
||
import com.alibaba.excel.EasyExcel; | ||
import com.alibaba.excel.util.ListUtils; | ||
import com.ming.easyExcel.dto.UserDTO; | ||
import com.ming.easyExcel.utils.EasyExcelReadUtils; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
|
||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.net.URLEncoder; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
/** | ||
* @ClassName: UserService | ||
* @Description: TODO | ||
* @Author: ECRZ | ||
* @Date: 2023/1/10 | ||
*/ | ||
@Service | ||
public class UserService { | ||
|
||
private List<UserDTO> data() { | ||
List<UserDTO> list = ListUtils.newArrayList(); | ||
for (int i = 0; i < 10; i++) { | ||
UserDTO user = new UserDTO(); | ||
user.setUserId(String.valueOf(UUID.randomUUID())); | ||
user.setUserName("张三"); | ||
user.setUserPassword("999999999"); | ||
|
||
list.add(user); | ||
} | ||
return list; | ||
} | ||
|
||
public void download(HttpServletResponse response) throws IOException { | ||
// 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman | ||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); | ||
response.setCharacterEncoding("utf-8"); | ||
// 这里URLEncoder.encode可以防止中文乱码 当然和easyExcel没有关系 | ||
String fileName = URLEncoder.encode("测试", "UTF-8").replaceAll("\\+", "%20"); | ||
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); | ||
EasyExcel.write(response.getOutputStream(), UserDTO.class).sheet("模板").doWrite(data()); | ||
} | ||
|
||
public String upload(MultipartFile file) throws IOException { | ||
EasyExcel.read(file.getInputStream(), UserDTO.class, new EasyExcelReadUtils()).sheet().doRead(); | ||
return "success"; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
SpringBoot-easyExcel/src/main/java/com/ming/easyExcel/utils/EasyExcelReadUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.ming.easyExcel.utils; | ||
|
||
import com.alibaba.excel.context.AnalysisContext; | ||
import com.alibaba.excel.read.listener.ReadListener; | ||
import com.ming.easyExcel.dto.UserDTO; | ||
|
||
/** | ||
* @ClassName: EasyExcelUtils | ||
* @Description: 工具主要实现读、写方法 | ||
* @Author: ECRZ | ||
* @Date: 2023/1/10 | ||
*/ | ||
public class EasyExcelReadUtils implements ReadListener<UserDTO> { | ||
|
||
/** | ||
* @Description: 每一条数据解析都会来调用 | ||
* @Author: ECRZ | ||
* @Date: 2023/1/10 | ||
*/ | ||
@Override | ||
public void invoke(UserDTO userDTO, AnalysisContext analysisContext) { | ||
System.out.println(userDTO.toString()); | ||
} | ||
|
||
/** | ||
* @Description: 所有数据解析完成了都会来调用 | ||
* @Author: ECRZ | ||
* @Date: 2023/1/10 | ||
*/ | ||
@Override | ||
public void doAfterAllAnalysed(AnalysisContext analysisContext) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
server: | ||
port: 8888 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lombok.toString.callSuper = CALL | ||
lombok.equalsAndHashCode.callSuper= CALL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
server: | ||
port: 8888 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lombok.toString.callSuper = CALL | ||
lombok.equalsAndHashCode.callSuper= CALL |
Oops, something went wrong.