整合定时任务
1.引入依赖`
<!--定时任务的依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
简单测试
@Component
public class OrderQuartz {
@Scheduled(cron = "0/2 * * * * ? ") //定时器 这里设置两秒执行一次
public void orderQuartz(){
System.out.println("~~~~~~~~~~");
}
}
2.在主启动类上加注解来开启定时驱动@EnableScheduling//开启Quarz注解的驱动
springboot整合swagger
1.引入依赖
<!--swagger-->
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
<version>1.9.1.RELEASE</version>
</dependency>
<!--好看的ui-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.6</version>
</dependency>
2.创建一个swagger配置类
@Configuration //配置类
public class SwaggerConfig {
@Bean
public Docket getDocket(){
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.groupName("Toyota")
.select()
//设置哪些包下的类生产api接口文档
.apis(RequestHandlerSelectors.basePackage("com.ganin.controller"))
//设置哪些请求路径生产接口文档(任意一个)
.paths(PathSelectors.any())
.build()
;
return docket;
}
private ApiInfo apiInfo(){
Contact contact = new Contact("豆加宁", "www.xxx.com", "xxx@xx.com");
ApiInfo apiInfo = new ApiInfo("Api Documentation", "Api Documentation", "1.0", "urn:tos", contact, "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", new ArrayList());
return apiInfo;
}
}
3.在主启动类上加@EnableSwagger2//开启swagger2注解
开启swagger2的注解
4.访问 swagger-bootstrap-ui 的页面
http://localhost:8080/doc.html
结果图
thymeleaf 模板引擎
1.在pom.xml引入依赖
<!--thymeleaf模板引擎-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2.创建一个hello.html页面(简单的例子)
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"> <!--把原来的html标签内容换掉-->
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<table th:width="1500" border="1px">
<tr>
<th>编号</th>
<th>姓名</th>
<th>性别</th>
<th>邮箱</th>
<th>部门</th>
<th>创建时间</th>
</tr>
<tr align="center" th:each="list:${list}">
<td th:text="${list.getEmpId()}"></td>
<td th:text="${list.getEmpName()}"></td>
<td th:text="${list.getGender()=='M'?'男':'女'}"></td>
<td th:text="${list.getEmail()}"></td>
<td th:text="${list.getEmpId()==1?'开发部':'测试部'}"></td>
<td th:text="${#dates.format(list.getCreatetime(),'yyyy-MM-dd HH:mm:ss')}"></td>
</tr>
</table>
</body>
</html>
controller层代码实现
@Controller
public class HelloController {
@Autowired
private EmpService empService;
@GetMapping("/list")
@ApiOperation(value = "getAll 查询所有数据")
public String getAll(Model model){
List<Emp> list = empService.selcetAll();
model.addAttribute("list",list);
return "hello";
}
}
结果图:
谢谢!!!!!!!!