1.spring-boot 整合定时器
一、pom文件中引入依赖
<!--定时器依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
二、我们需要创建一个任务类
在类的上方加入一个帮我们创建对象的注解 在方法上面加上开启定时器的注解 cron = " " 里面根据自己需求定义启动的时间 可以从https://cron.qqe2.com/ 网站取
@Component //交于spring容器创建该类的对象
public class MyTask {
@Scheduled(cron="0/1 * * * * ?")
public void task(){
System.out.println("定时器执行了一次");//代码逻辑
}
}
三、给启动类加上开启定时器注解@EnableScheduling
@SpringBootApplication
@MapperScan("com.zhang.springbootdept.mapper")
@EnableScheduling //开启定时器的注解
public class SpringBootDeptApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootDeptApplication.class, args);
}
}
执行
2.Spring-Boot整合分页插件PageHeper
首先在pom文件下引入依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.13</version>
</dependency>
service实现类代码
@Override
public PageInfo<Dept> findAll(Integer currentPage,Integer pageSize) {
Page<Object> page = PageHelper.startPage(currentPage, pageSize);
List<Dept> dept = deptMapper.findAll();
PageInfo<Dept> info = new PageInfo<>(dept);
return info;
}
3.Spring-Boot 整合 thymeleaf模板引擎
模板引擎:就是用来操作模板的引擎,就是用来渲染模板的,模板就是页面,就是用来生成页面的
thymeleaf是一款用于渲染XML/XHTML/HTML5内容的模板引擎,与JSP不同,thymeLeaf是使用html的标签来完成逻辑和数据的传入进行渲染, 而且不用像jsp一样作为一个servlet被编译再生成。并且可以被浏览器直接打开。
打开项目 可以看到 static是用来放我们的静态资源的 它可以被浏览器直接访问
templates是模板引擎 他无法通过浏览器来访问
使用步骤
一、在pom文件中引入thymeleaf依赖
<!--引入thymeleaf依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
二、在我们的网页中引入
<html xmlns:th="http://www.thymeleaf.org">
要确保项目可以联网
然后就可以用thymeleaf标签库来写代码了
可以使用 each循环 if判断 这里if也是没有else 如果像else 只能再写一个if判断
格式
th:each=“item : x x x x " 他 需 要 写 到 标 签 里 面 t h : t e x t = " {xxxx}" 他需要写到标签里面 th:text="xxxx"他需要写到标签里面th:text="{xxxx}” 输出
th:if="${item.xxxx}"
<table>
<tr>
<th>编号</th>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
<th>操作</th>
</tr>
<tr th:each="item : ${pageInfo.list}">
<th th:text="${item.id}"></th>
<th th:text="${item.name}">姓名</th>
<th th:if="${item.sex==0}">男</th>
<th th:if="${item.sex!=0}">女</th>
<th >
<a href="#">删除</a>
<a href="#">修改</a>
</th>
</tr>
</table>