You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
webcrawler/web/src/main/java/web/controller/TableController.java

48 lines
1.7 KiB

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<T extends AbstractModel,E extends BaseService> extends BaseController<T,E> {
@RequestMapping("table")
public <T extends AbstractModel> 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<T>(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;
}
}