【分页+增删查改】中:
- 分页:即原来的findAll升级之后的findPage
- 增: insert 插入一条
- 删: delete 删除一条
- 查: findById 为了【改】,一般不单独用
- 改: update
- Map接收参数必须加@RequestParam
- Admin实体类接收参数无需加参数
- 路径参数需要出现 3 次
/**
* @CreateTime: 2023/5/29 21:13
* @Description: 管理员控制层
*
* Map接收参数必须加@RequestParam
* Admin实体类接收参数无需加参数
*
* 路径参数需要出现 3 次
*/
@Controller
@RequestMapping("/admin")
public class AdminController {
private static final String PAGE_INDEX = "admin/index";
private static final String PAGE_SUCCESS = "common/successPage";
private static final String LIST_ACTION = "redirect:/admin";
private static final String PAGE_EDIT = "admin/edit";
@Autowired
private AdminService adminService;
//分页(findAll升级版)
@RequestMapping
public String index(@RequestParam Map<String,String> filters, Model model){
//1.调用业务层查询分页数据
PageInfo<Admin> page = adminService.findPageList(filters);
//2.传入共享域并且回显过滤条件
model.addAttribute("page",page);
model.addAttribute("filters",filters);
//3.返回页面
return PAGE_INDEX;
}
//增
@PostMapping("/insert")
public String insert(Admin admin,Model model){
//1.调用业务层插入数据
boolean success = adminService.insert(admin);
//2.若成功则返回成功页面
model.addAttribute("messagePage","新增admin信息成功");
return PAGE_SUCCESS;
}
//删
@GetMapping("/delete/{id}")
public String delete(@PathVariable("id") Integer id,Model model){
//1.调用删除业务
boolean success = adminService.delete(id);
//2.删除后重定向到:/admin 再显示一下
return LIST_ACTION;
}
//查:根据ID查询:改之前先查询信息并回显
@GetMapping("/find/{id}")
public String find(@PathVariable("id")Integer id,Model model){
//1.调用findById业务
Admin admin = adminService.findById(id);
//2.将结果放到请求域
model.addAttribute("admin",admin);
//3.返回修改视图
return PAGE_EDIT;
}
//改:在【查】后的修改视图修改
@PostMapping("/update")
public String update(Admin admin,Model model){
//1.调用update业务
boolean success = adminService.update(admin);
//2.返回成功页面
model.addAttribute("messagePage","修改admin信息成功");
return PAGE_SUCCESS;
}
}
标签:String,admin,PAGE,SSM,public,查改,增删,model,id
From: https://www.cnblogs.com/newleesoo/p/17444073.html