springboot自动装配原理,整合定时器Quartz,分页插件PageHelper以及thymeleaf模板引擎

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层已经建好且内容已书写完毕

最后运行主启动类

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值