|
|
|
@ -15,10 +15,7 @@ import org.springframework.core.ResolvableType; |
|
|
|
|
import org.springframework.dao.DataAccessException; |
|
|
|
|
import org.springframework.http.MediaType; |
|
|
|
|
import org.springframework.util.ClassUtils; |
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody; |
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
import web.service.BaseService; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -49,38 +46,64 @@ public abstract class BaseController<T extends AbstractModel,A extends T,E exten |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ResponseBody |
|
|
|
|
@RequestMapping(value = "{action}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) |
|
|
|
|
public JsonResult curd(@PathVariable DBAction action, T model) { |
|
|
|
|
log.info(tableName+ "进行" + action.getCh() + "操作请求"); |
|
|
|
|
if(checkAction(action)) { |
|
|
|
|
@RequestMapping(produces = MediaType.APPLICATION_JSON_UTF8_VALUE,method = RequestMethod.POST) |
|
|
|
|
public JsonResult save(T model){ |
|
|
|
|
JsonResult result=new JsonResult(); |
|
|
|
|
result.setAction(DBAction.C); |
|
|
|
|
try { |
|
|
|
|
return new JsonResult<>(service.curd(action, model), Type.success, action); |
|
|
|
|
}catch (DataAccessException e){ |
|
|
|
|
log.error(e); |
|
|
|
|
return new JsonResult<>("非法操作", Type.fail, action); |
|
|
|
|
service.save(model); |
|
|
|
|
result.setType(Type.success); |
|
|
|
|
} catch (DataAccessException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
result.setType(Type.fail); |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
return new JsonResult<>(tableName + "不允许" + action.getCh() + "操作", Type.fail,action); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ResponseBody |
|
|
|
|
@RequestMapping(produces = MediaType.APPLICATION_JSON_UTF8_VALUE,method = RequestMethod.GET) |
|
|
|
|
public JsonResult get(T model){ |
|
|
|
|
JsonResult result=new JsonResult(); |
|
|
|
|
result.setAction(DBAction.R); |
|
|
|
|
try { |
|
|
|
|
service.get(model); |
|
|
|
|
result.setType(Type.success); |
|
|
|
|
} catch (DataAccessException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
result.setType(Type.fail); |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ResponseBody |
|
|
|
|
@RequestMapping(value = "batch/{action}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) |
|
|
|
|
public JsonResult find(@PathVariable DBAction action, A queryCommand, @RequestParam Integer firstResult, @RequestParam Integer maxResults){ |
|
|
|
|
log.info(tableName + "进行批量" + action.getCh() + "操作请求"); |
|
|
|
|
if(checkAction(action)) { |
|
|
|
|
@RequestMapping(produces = MediaType.APPLICATION_JSON_UTF8_VALUE,method = RequestMethod.PUT) |
|
|
|
|
public JsonResult update(T model){ |
|
|
|
|
JsonResult result=new JsonResult(); |
|
|
|
|
result.setAction(DBAction.U); |
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
return new JsonResult<>(service.find(getDetachedCriteria(queryCommand), firstResult, maxResults), Type.success, action); |
|
|
|
|
service.update(model); |
|
|
|
|
result.setType(Type.success); |
|
|
|
|
} catch (DataAccessException e) { |
|
|
|
|
log.error(e); |
|
|
|
|
return new JsonResult<>("非法操作", Type.fail, action); |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
result.setType(Type.fail); |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
return new JsonResult<>(tableName + "不允许" + action.getCh() + "操作", Type.fail,action); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ResponseBody |
|
|
|
|
@RequestMapping(produces = MediaType.APPLICATION_JSON_UTF8_VALUE,method = RequestMethod.DELETE) |
|
|
|
|
public JsonResult delete(T model){ |
|
|
|
|
JsonResult result=new JsonResult(); |
|
|
|
|
result.setAction(DBAction.D); |
|
|
|
|
try { |
|
|
|
|
service.delete(model); |
|
|
|
|
result.setType(Type.success); |
|
|
|
|
} catch (DataAccessException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
result.setType(Type.fail); |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Class<?> getResolvableType() { |
|
|
|
@ -95,5 +118,9 @@ public abstract class BaseController<T extends AbstractModel,A extends T,E exten |
|
|
|
|
return DetachedCriteria.forClass(getResolvableType()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected abstract boolean checkAction(DBAction action); |
|
|
|
|
|
|
|
|
|
protected boolean checkAction(DBAction action) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|