分页查询
Controller层
Controller层:MVC架构中的接口层,用户访问请求时对接;是对项目里的功能做统一的调度。
@Controller @RequestMapping("/api/v1/TStorageRecord") public class TStorageRecordController { @Autowired private TStorageRecordService tStorageRecordService; @RequestMapping("/listpage") public String listpage(TStorageRecord tStorageRecord, Model model){ List<TStorageRecord> list=tStorageRecordService.getlist(tStorageRecord); Page01 page01=new Page01(); // model.addAttribute("page",page01); model.addAttribute("tslist",list); return "list.jsp"; } @RequestMapping("/goadd") public String goadd(){ return "add.jsp"; } @RequestMapping("/add") public String add(TStorageRecord tStorageRecord){ tStorageRecordService.add(tStorageRecord); return "redirect:/api/v1/TStorageRecord/listlimit"; } @RequestMapping("/del") public String del(int id){ tStorageRecordService.del(id); return "redirect:/api/v1/TStorageRecord/listlimit"; } @RequestMapping("/update") public String update(TStorageRecord tStorageRecord){ tStorageRecordService.update(tStorageRecord); return "redirect:/api/v1/TStorageRecord/listlimit"; } @RequestMapping("/gotupdate") public String gotupdate(Integer id,Model model){ TStorageRecord tStorageRecord=tStorageRecordService.gettStorage(id); model.addAttribute("TSto",tStorageRecord); return "update.jsp"; } @RequestMapping("getRoleLimit") public String getRolelimit(HttpServletRequest request){ Page01 page01=new Page01(); String currPageNostr=request.getParameter("currPageNo"); if(currPageNostr==null||"".equals(currPageNostr)){ page01.setCurrPageNo(1); }else{ page01.setCurrPageNo(Integer.parseInt(currPageNostr)); } String pageSizeStr=request.getParameter("pageSize"); if(pageSizeStr==null||"".equals(pageSizeStr)){ page01.setPageSize(2); }else{ page01.setPageSize(Integer.parseInt(pageSizeStr)); } page01.setTotalCount(tStorageRecordService.getRoleCount()); page01.settStorageRecords(tStorageRecordService.getSysRoleList(page01.getCurrPageNo(),page01.getPageSize())); request.setAttribute("page",page01); request.setAttribute("Records",page01.gettStorageRecords()); return "list.jsp"; } }
mapper层
mapper层的作用是对数据库进行数据持久化操作,他的方法语句是直接针对数据库操作的现在用mybatis逆向工程生成的
public interface TStorageRecordMapper { List<TStorageRecord> getlist(TStorageRecord tStorageRecord); int add(TStorageRecord tStorageRecord); TStorageRecord gettStorage(Integer id); int update (TStorageRecord tStorageRecord); int del(Integer id); int getRoleCount(); List<TStorageRecord> getSysRoleList(@Param("num")int num,@Param("pageSize")int pageSize); }
service层
Service层主要负责业务模块的逻辑应用设计。同样是首先设计接口,再设计其实现的类,接着再Spring的配置文件中配置其实现的关联
public interface TStorageRecordService { List<TStorageRecord> getlist(TStorageRecord tStorageRecord); int add(TStorageRecord tStorageRecord); TStorageRecord gettStorage(Integer id); int update (TStorageRecord tStorageRecord); int del(Integer id); int getRoleCount(); List<TStorageRecord> getSysRoleList(@Param("pageSize")int pageSize, @Param("currPageNo")int currPageNo); }
@Service public class TStorageRecordServiceimpl implements TStorageRecordService { @Autowired private TStorageRecordMapper tStorageRecordMapper; @Override public List<TStorageRecord> getlist(TStorageRecord tStorageRecord) { return tStorageRecordMapper.getlist(tStorageRecord); } @Override public int add(TStorageRecord tStorageRecord) { return tStorageRecordMapper.add(tStorageRecord); } @Override public TStorageRecord gettStorage(Integer id) { return tStorageRecordMapper.gettStorage(id); } @Override public int update(TStorageRecord tStorageRecord) { return tStorageRecordMapper.update(tStorageRecord); } @Override public int del(Integer id) { return tStorageRecordMapper.del(id); } @Override public int getRoleCount() { return tStorageRecordMapper.getRoleCount(); } @Override public List<TStorageRecord> getSysRoleList(int currPageNo , int pageSize) { int num=(currPageNo-1)*pageSize; return tStorageRecordMapper.getSysRoleList(num,pageSize); } }