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.
53 lines
2.0 KiB
53 lines
2.0 KiB
package web.controller;
|
|
|
|
import core.service.BaseService;
|
|
import core.util.DBAction;
|
|
import db.model.AbstractModel;
|
|
import db.model.JsonResult;
|
|
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.Arrays;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* Created by reborn on 2017/9/14.
|
|
*/
|
|
public abstract class BaseController<T extends AbstractModel>{
|
|
protected Logger log=LogManager.getLogger();
|
|
|
|
@Resource
|
|
public BaseService baseService;
|
|
|
|
@ResponseBody
|
|
@RequestMapping(value = "{action}", produces = "application/json;charset=UTF-8")
|
|
public <T extends AbstractModel> JsonResult curd(@PathVariable DBAction action, T model) {
|
|
log.info(model.tableNote()+ "进行" + action.getCh() + "操作请求");
|
|
if(checkAction(action)) {
|
|
model=baseService.curd(action, model);
|
|
}else{
|
|
// model.setException(new Exception(model.tableNote()+"不允许" + action.getCh()+"操作"));
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@ResponseBody
|
|
@RequestMapping(value = "batch/{action}", produces = "application/json;charset=UTF-8")
|
|
public <T extends AbstractModel> List<T> find(@PathVariable DBAction action,T queryCommand,Integer firstResult,Integer maxResults){
|
|
log.info(queryCommand.tableNote()+ "进行批量" + action.getCh() + "操作请求");
|
|
if(checkAction(action)) {
|
|
return baseService.find(queryCommand, firstResult, maxResults);
|
|
}else{
|
|
// queryCommand.setException(new Exception(queryCommand.tableNote()+"不允许批量" + action.getCh()+"操作"));
|
|
}
|
|
return Arrays.asList(queryCommand);
|
|
}
|
|
|
|
|
|
public abstract boolean checkAction(DBAction action);
|
|
}
|
|
|