引入相关的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>2)
<dependency>
创建一个任务类以及任务功能package com.yjq.dingshi.task;import org.springframework.scheduling.annotation.Scheduled;import org.springframework.stereotype.Component;@Componentpublic 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); }}
2.分页插件PageHelper1)加入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中的方法@RestControllerpublic 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=rootspring.datasource.password=123456spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=Asia/Shanghai&characterEncoding=utf8spring.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层已经建好且内容已书写完毕最后运行主启动类3.thymeleaf模板引擎---JSP了解:
?1)引入相关的依赖<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId></dependency>2)书写配置文件 spring.datasource.username=rootspring.datasource.password=123456spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=Asia/Shanghai&characterEncoding=utf8spring.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层已经建好且内容已书写完毕最后运行主启动类?