实现标签分页
环境
MySql 5.0.67
Spring Boot 2.3.1
mysql-connector-java 5.1.37
- Type字段有
id
,name
项目结构
TypeController
@Controller
@RequestMapping("/admin/types")
public class TypeController {
@Autowired
private ITypeService iTypeService;
@GetMapping
public String list(@PageableDefault(size = 5, sort = {
"id"}, direction = Sort.Direction.DESC) Pageable pageable, Model model) {
Page<Type> page = iTypeService.listType(pageable);
model.addAttribute("page", page);
return "admin/types";
}
@GetMapping("{id}/delete")
public String delete(@PathVariable Long id) {
iTypeService.deleteType(id);
return "redirect:/admin/types";
}
@GetMapping("input")
public String input(){
return "admin/types-input";
}
@PostMapping("add")
public String add(Type type){
iTypeService