添加接口扫描
3.2 easycode
Test connected Download… ok
四 boot整合其他
4.1 整合定时器
在线Cron表达式生成器https://cron.qqe2.com/
十秒钟执行一次:
App :
package com.aaa.haha;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication //haha-common pom.xml spring-boot-starter-web
@MapperScan("com.aaa.haha.mapper") //扫包 否则将会com.aaa.haha.mapper.StudentMapper not fount
@EnableScheduling //开启定时任务
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class,args);
}
}
MySchdule :
package com.aaa.haha.schedule;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class MySchdule {
@Scheduled(fixedDelay = 10000) //10秒
public void haha() {
System.out.println("你好 该吃药了");
}
}
每分钟的第五秒执行一次:
MySchdule :
package com.aaa.haha.schedule;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class MySchdule {
// @Scheduled(fixedDelay = 10000) //10秒
// public void haha() {
// System.out.println("你好 该吃药了");
// }
@Scheduled(cron = "5 * * * * ?") //每分钟的第5秒执行一次
public void haha() {
System.out.println("你好 该吃药了");
}
}
4.2 异步任务
异步操作:
StudentService :
package com.aaa.haha.service;
import com.aaa.haha.entity.Student;
import java.util.List;
public interface StudentService {
List<Student> listAllStudent();
void sendCode();
}
StudentServiceImpl :
package com.aaa.haha.service.impl;
import com.aaa.haha.entity.Student;
import com.aaa.haha.mapper.StudentMapper;
import com.aaa.haha.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class StudentServiceImpl implements StudentService {
@Resource
private StudentMapper studentMapper;
@Override
public List<Student> listAllStudent() {
return studentMapper.listAllStudent();
}
@Override
@Async
public void sendCode() {
System.out.println("开始发送");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("发送成功");
}
}
App :
package com.aaa.haha;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication //haha-common pom.xml spring-boot-starter-web
@MapperScan("com.aaa.haha.mapper") //扫包 否则将会com.aaa.haha.mapper.StudentMapper not fount
@EnableScheduling //开启定时任务
@EnableAsync //开启异步
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class,args);
}
}
StudentController :
package com.aaa.haha.controller;
import com.aaa.haha.domain.AjaxResult;
import com.aaa.haha.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("student")
public class StudentController {
@Autowired
private StudentService studentService;
@RequestMapping("list")
public AjaxResult list(){
return AjaxResult.success( studentService.listAllStudent());
}
@RequestMapping("tongbu")
public String tongbu(){
studentService.sendCode();
return "同步操作";
}
@RequestMapping("yibu")
public String yibu(){
studentService.sendCode();
return "异步操作";
}
}
同步操作
将(@EnableAsync //异步 @Async )注解去掉,访问:http://localhost:8090/boot/student/tongbu 即使同步操作。
4.9 Knife4j
错误:Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception is java.lang.NullPoi
解决:在properties配置文件中添加如下代码:(如果是yml配置,则参考以下链接)
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
参考:
解决方案之‘Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception is java.lang.NullPoi
https://blog.csdn.net/hadues/article/details/123753888
spring boot配置数据库连接
https://blog.csdn.net/weixin_41463944/article/details/122710121
http://localhost:8090/doc.html#/home
ApiPost7
list GetMapping:
添加 PostMapping:
获取 GetMapping
删除 DeleteMapping:
4.3 整合事务
Mybatis 开启控制台打印sql语句
Mybatis 开启控制台打印sql语句
https://blog.csdn.net/qq_37495786/article/details/82799910
入参校验
整合全局异常
整合logback日志
拦截器
SpringBoot 拦截器的简单配置及用法
https://blog.csdn.net/qq_36014509/article/details/81453291
整合模板引擎(了解)
springboot项目父子多模块打jar包
参考:springboot项目父子多模块打jar包
https://blog.csdn.net/Peanutfight/article/details/116401877?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166574389716781432959429%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=166574389716781432959429&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduend~default-1-116401877-null-null.142v56pc_rank_34_2,201v3control_1&utm_term=springboot%E7%88%B6%E5%AD%90%E9%A1%B9%E7%9B%AE%E6%89%93%E5%8C%85&spm=1018.2226.3001.4187
【Maven打包报错解决方案】Using ‘UTF-8‘ encoding to copy filtered resources.
https://blog.csdn.net/weixin_44985880/article/details/119844661
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- 指定该Main Class为全局的唯一入口 -->
<mainClass>com.example.main.MainApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中-->
</goals>
</execution>
</executions>
</plugin>
<!--【Maven打包报错解决方案】Using ‘UTF-8‘ encoding to copy filtered resources.-->
<!--https://blog.csdn.net/weixin_44985880/article/details/119844661-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
</plugins>
</build>
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/118004.html