package web.controller; import core.service.BaseService; import db.AbstractModel; import db.DBAction; import db.PageResult; import db.Type; import org.springframework.dao.DataAccessException; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import java.util.List; public abstract class TableController extends BaseController { @RequestMapping("table") public String find(Model model, T queryCommand, @RequestParam Integer firstResult, @RequestParam Integer maxResults){ DBAction action=DBAction.R; log.info(queryCommand.tableNote()+ "进行批量" + action.getCh() + "操作请求"); PageResult result; if(checkAction(action)) { try { Long rowCount=service.rowCount(queryCommand.getClass()); if(rowCount>0) { List list = service.find(queryCommand, firstResult*maxResults, maxResults); result=new PageResult(rowCount, firstResult,list,maxResults , Type.success); }else{ result=new PageResult(Type.fail,"没有记录"); } } catch (DataAccessException e) { log.error(e); result=new PageResult(Type.fail,"非法操作"); } }else{ result=new PageResult(Type.fail,queryCommand.tableNote() + "不允许" + action.getCh() + "操作"); } model.addAttribute("datas", result); return "table"; } @Override protected boolean checkAction(DBAction action) { return false; } }