博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
几个简单的基类
阅读量:4876 次
发布时间:2019-06-11

本文共 7206 字,大约阅读时间需要 24 分钟。

 

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;    }}

 

转载于:https://www.cnblogs.com/zrui-xyu/p/5362323.html

你可能感兴趣的文章
MySQL存储过程和函数
查看>>
Java 中几种常用设计模式
查看>>
硬盘相关知识
查看>>
[LeetCode] Largest Rectangle in Histogram
查看>>
2345网址导航源码 v3.3
查看>>
字典Dictionary
查看>>
JS重要知识点
查看>>
java解析数据
查看>>
Linux下安装多个tomcat
查看>>
UIPickView之自定义生日键盘和城市键盘
查看>>
改变 C/C++ 控制台程序的输出颜色和样式
查看>>
第1章 游戏之乐——让CPU占用率曲线听你指挥
查看>>
laravel入门教程
查看>>
整理大数据期末考试复习提纲--概念整理
查看>>
线程--promise furture 同步
查看>>
Mybatis3.2.3+mysql第一个例子(入门)
查看>>
Nginx 代理配置
查看>>
跟锦数学171217-180630
查看>>
Python之random
查看>>
【IE大叔开玩笑】之——CSS设置IE6中容器高度的BUG
查看>>