package web.controller; import core.service.BaseService; import core.util.DBAction; import db.model.AbstractModel; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import java.util.List; /** * Created by reborn on 2017/9/14. */ public abstract class BaseController{ protected Logger log=LogManager.getLogger(); @Resource public BaseService baseService; @ResponseBody @RequestMapping(value = "{action}", produces = "application/json;charset=UTF-8") public T curd(@PathVariable DBAction action,T model) { log.info(model.tableNote()+ "进行" + action.getCh() + "操作请求"); return baseService.curd(action, model); } @ResponseBody @RequestMapping(value = "batch/{action}", produces = "application/json;charset=UTF-8") public List find(@PathVariable DBAction action,T queryCommand,Integer firstResult,Integer maxResults){ if(action.equals(DBAction.BR)) { return baseService.find(queryCommand, firstResult, maxResults); }else{ throw new RuntimeException("非法操作:" + action); } } public abstract boolean checkAction(DBAction action); }