List<Emp> emps = empDao.selectAll();
PageInfo<Emp> pageInfo=new PageInfo<>(emps);
return new Result(200,"查询成功",pageInfo);
}
}
(6)controller接口层
package com.zjw.controller;
import com.zjw.entity.Emp;
import com.zjw.service.EmpService;
import com.zjw.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/emp")
public class EmpController {
@Autowired
private EmpService empService;
@DeleteMapping
public Result deleteById(Integer id){
return empService.deleteById(id);
}
@PostMapping
public Result insert(@RequestBody Emp emp){
return empService.insert(emp);
}
@PutMapping
public Result update(@RequestBody Emp emp){
return empService.update(emp);
}
@GetMapping
public Result getById(Integer id){
return empService.findById(id);
}
@GetMapping("/getAll")
public Result getAll(Integer current,Integer pageSize){
return empService.findAll(current, pageSize);
}
}
8. springboot整合定时器。
可以在规定的时间内执行相应的代码。
比如: OSS文件上传---OSS的文件冗余的文件。----OSS的浪费。---->指定的时间自动删除。[夜间删除]
比如: 下单--->30分钟未支付---取消订单。
(1)引入定时器的依赖--
<!--引入定时器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
(2)编写定义的业务代码
@Component
public class My {
@Autowired
private EmpDao empDao;
//定时任务执行的代码
@Scheduled(cron = "0 0 2 * * ?")
public void show(){
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~");
//可以写自己的写完代码
empDao.delete();
}
}
(3)开启定时的注解驱动