BaseController
package com.yunzainfo.common.base;import java.util.List;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;import com.yunzainfo.common.pojo.BasePage;import com.yunzainfo.common.pojo.GridReturn;import com.yunzainfo.common.pojo.MsgReturn;public abstract class BaseController{ protected abstract BaseService getBaseService(); @RequestMapping("/insert") @ResponseBody public MsgReturn insert(T t){ if(this.getBaseService().insert(t)>0){ return new MsgReturn(true, "新增成功!"); } return new MsgReturn(false, "新增失败!"); } @RequestMapping("/delete") @ResponseBody public MsgReturn delete(T t){ if(this.getBaseService().delete(t)>0){ return new MsgReturn(true, "删除成功!"); } return new MsgReturn(false, "删除失败!"); } @RequestMapping("/update") @ResponseBody public MsgReturn update(T t){ if(this.getBaseService().update(t)>0){ return new MsgReturn(true, "修改成功!"); } return new MsgReturn(false, "修改失败!"); } @RequestMapping("/get") @ResponseBody public T get(T t){ return (T) this.getBaseService().get(t); } /** * 分页查询 * @param c 查询参数类 * @return */ @RequestMapping("/findList") @ResponseBody public GridReturn findList(C c){ if (c.getLimit() != null||c.getLength() != null) { c.setLength(c.getLimit()); c.setLimit(c.getLimit()); c.setOracleEnd(c.getLimit() + c.getStart()); c.setOracleStart(c.getStart()); } List lsit = this.getBaseService().findList(c); int count = this.getBaseService().getTotalCount(c); return new GridReturn(c.getDraw(), count, count, lsit); }}
BaseMapper
package com.yunzainfo.common.base;import java.util.List;public interface BaseMapper{ public int insert(T t); public int delete(T t); public int update(T t); public T get(T t); public List findList(C c); public int getTotalCount(C c);}
BaseService
package com.yunzainfo.common.base;import java.util.List;public interface BaseService{ public int insert(T t); public int delete(T t); public int update(T t); public T get(T t); public List findList(C c); public int getTotalCount(C c);}
BaseServiceImpl
package com.yunzainfo.common.base;import java.util.List;public abstract class BaseServiceImpl{ public abstract BaseMapper getChildMapper(); public int insert(T t){ return this.getChildMapper().insert(t); } public int delete(T t){ return this.getChildMapper().delete(t); } public int update(T t){ return this.getChildMapper().update(t); } public T get(T t){ return this.getChildMapper().get(t); } public List findList(C c){ return this.getChildMapper().findList(c); } public int getTotalCount(C c){ return this.getChildMapper().getTotalCount(c); }}
BasePage
package com.yunzainfo.common.pojo;public class BasePage { protected int start; protected Integer limit; protected Integer length; protected int draw; protected Integer oracleStart; protected Integer oracleEnd; public int getStart() { return start; } public void setStart(int start) { this.start = start; } public Integer getLimit() { return limit; } public void setLimit(Integer limit) { this.limit = limit; } public Integer getLength() { return length; } public void setLength(Integer length) { this.length = length; } public int getDraw() { return draw; } public void setDraw(int draw) { this.draw = draw; } public Integer getOracleStart() { return oracleStart; } public void setOracleStart(Integer oracleStart) { this.oracleStart = oracleStart; } public Integer getOracleEnd() { return oracleEnd; } public void setOracleEnd(Integer oracleEnd) { this.oracleEnd = oracleEnd; } }
GridReturn
package com.yunzainfo.common.pojo; import java.util.List;public class GridReturn { private int draw;//请求次数 private long recordsTotal;//总记录数 private long recordsFiltered;//过滤后记录数 private List data; public GridReturn(int draw,long recordsTotal,long recordsFiltered,List data){ this.data=data; this.draw=draw; this.recordsFiltered=recordsFiltered; this.recordsTotal=recordsTotal; } public int getDraw() { return draw; } public void setDraw(int draw) { this.draw = draw; } public long getRecordsTotal() { return recordsTotal; } public void setRecordsTotal(long recordsTotal) { this.recordsTotal = recordsTotal; } public long getRecordsFiltered() { return recordsFiltered; } public void setRecordsFiltered(long recordsFiltered) { this.recordsFiltered = recordsFiltered; } public List getData() { return data; } public void setData(List data) { this.data = data; } }
MsgReturn
package com.yunzainfo.common.pojo; public class MsgReturn { private boolean success; // 是否成功 private Object msg; // 返回消息 private Object otherObject;// 其他对象 public MsgReturn() { } /** * 是否更新成功的构造方法 * * @param success * 是否成功 * @param msg * 消息 */ public MsgReturn(boolean success, Object msg) { this.success = success; this.msg = msg; this.otherObject = ""; } /** * 是否更新成功的构造方法 * * @param success * 是否成功 * @param msg * 消息 * @param otherObject * 其他对象 */ public MsgReturn(boolean success, Object msg, Object otherObject) { this.success = success; this.msg = msg; this.otherObject = otherObject; } /** * 异常时的构造函数 * * @param errormsg * 异常消息 */ public MsgReturn(Object errormsg) { this.success = false; this.msg = false; this.otherObject = ""; } /** * 判断是否成功 * * @return */ public boolean isSuccess() { return success; } /** * 设置返回是否成功的状态 * * @param success */ public void setSuccess(boolean success) { this.success = success; } /** * 设置其他对象 * * @return */ public Object getOtherObject() { return otherObject; } /** * 获取其他对象 * * @param otherObject */ public void setOtherObject(Object otherObject) { this.otherObject = otherObject; } /** * 获取返回的消息 * * @return */ public Object getMsg() { return msg; } /** * 设置返回的消息 * * @param msg */ public void setMsg(Object msg) { this.msg = msg; }}