Spring Boot 实现博客的增删改查与分页功能
1.TypeController
@Controller
@RequestMapping("/admin/types")
public class TypeController {
@Autowired
private ITypeService typeService;
@GetMapping
public String list(@PageableDefault(size = 5,sort = {
"id"},direction = Sort.Direction.DESC) Pageable pageable, Model model){
Page<Type> page=typeService.listType(pageable);
model.addAttribute("page",page);
return "admin/types";
}
@GetMapping("/{id}/delete")
public String delete(@PathVariable Long id){
typeService.deleteType(id);
return "redirect:/admin/types";
}
@GetMapping("input")
public String input(){
return "admin/types-input";
}
@PostMapping("add")
public String add(Type type){
typeService.addType(type);
return "redirect:/admin/types";
}
@GetMapping("{id}/toupdate")
public String toupdate(@PathVariable Long id,Model model){
Type type=typeService.getType(id);
model.addAttribute("type",type);
return "admin/types-input";