1.springboot自动装配原理


2.springboot整合定时器Quartz
https://cron.qqe2.com/ 定时相关网站
1)引入相关的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
2)创建一个任务类以及任务功能
package com.yjq.dingshi.task;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class Task1 {
@Scheduled(cron = "0/10 * * * * ?")
public void task1(){
System.out.println("============");
}
}
3)启动定时器的注解
package com.yjq.dingshi;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@ComponentScan(basePackages = {"com.yjq"}) //认为的指定扫描那些包
@EnableScheduling//开启定时器的注解
public class DingshiApplication {
public static void main(String[] args) {
SpringApplication.run(DingshiApplication.class, args);
}
}
3.分页插件PageHelper
1)加入PageHelper的启动依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.13</version>
</dependency>
2)书写controller的代码
package com.yjq.dingshi.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yjq.dingshi.entry.Test1;
import com.yjq.dingshi.mapper.TestMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
//controller调用mapper中的方法
@RestController
public class TestController {
@Resource
private TestMapper testMapper;
@GetMapping("list")
public PageInfo<Test1> list(@RequestParam Integer currentPage,@RequestParam Integer pageSize){
PageHelper.startPage(currentPage,pageSize);
List<Test1> all=testMapper.selectTest();
PageInfo<Test1> pageInfo=new PageInfo<>(all);
return pageInfo;
}
}
3)书写配置文件
spring.datasource.username=root spring.datasource.password=123456 spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=Asia/Shanghai&characterEncoding=utf8 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver #配置映射文件所在路径 mybatis.mapper-locations=classpath:/mapper/*.xml #打印sql日志 logging.level.com.yjq.yinqing.mapper=debug
注:相应的mapper层,entry实体层,xml层已经建好且内容已书写完毕
最后运行主启动类
4.thymeleaf模板引擎---JSP
了解:

1)引入相关的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2)书写配置文件
spring.datasource.username=root spring.datasource.password=123456 spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=Asia/Shanghai&characterEncoding=utf8 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver #配置映射文件所在路径 mybatis.mapper-locations=classpath:/mapper/*.xml #打印sql日志 logging.level.com.yjq.yinqing.mapper=debug #指定thymeleaf的前缀 spring.thymeleaf.prefix=classpath:/templates/views/
3)书写控制层
controller层:

4)必须在jsp网页中引入
<html xmlns:th="http://www.thymeleaf.org">
5)可以使用thymeleaf标签库
jsp前端网页:

注:相应的mapper层,entry实体层,xml层已经建好且内容已书写完毕
最后运行主启动类
本文介绍了如何在Spring Boot应用中利用Quartz创建定时任务,并配合PageHelper进行分页操作,包括依赖引入、任务类编写、启动注解配置和分页插件的使用实例。

1065

被折叠的 条评论
为什么被折叠?



