2019-07-01

作者: 羊1111 | 来源:发表于2019-07-01 16:06 被阅读0次

    单表的curd

    数据库
    image.png

    model层

    /**
     * BZ_FUNDS_CY
     * @author
     */
    @Table(name="BZ_FUNDS_CY")
    @Data
    @NoArgsConstructor
    public class BzFundsCy implements Serializable {
        /**
         * 主记录ID
         */
        @Id
        @Size(max = 32,message = "主记录id长度不能超过32位")
        private String mrsId;
    
        /**
         * 所属培训班
         */
        @Size(max = 32,message = "所属培训班长度不能超过32位")
        private String termId;
    
        /**
         * 购买方名称
         */
        @NotBlank(message = "购买方名称不能为空")
        @Size(max = 32,message = "购买方名称不能超过32位")
        private String buyer;
    
        /**
         * 发票销售方
         */
        @Size(max = 32,message = "发票销售方长度不能超过32位")
        private String saller;
    
        /**
         * 发票编号
         */
        @Size(max = 20,message = "发票编号长度不能超过20位")
        private String billNo;
    
        /**
         * 开票日期
         */
        @JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
        @DateTimeFormat(pattern="yyyy-MM-dd")
        private Date billDate;
    
        /**
         * 价税合计
         */
        @Digits(integer = 10,fraction = 2)
        private BigDecimal billSum;
    
        /**
         * 相关说明
         */
        @Size(max = 500,message = "相关说明长度不能超过500位")
        private String otherDesc;
    
        /**
         * 复印件路径
         */
        @Size(max = 100,message = "复印件路径不能超过100位")
        private String picPath;
    
        /**
         * 文件名称
         */
        @Size(max = 50,message = "文件名称长度不能超过50位")
        private String picName;
    
        /**
         * 文件扩展名
         */
        @Size(max = 10,message = "文件扩展名长度不能超过10位")
        private String picExt;
    
        /**
         * 创建时间
         */
        @JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
        private Date createDate;
    
        /**
         * 创建人ID
         */
        @Size(max = 32,message = "创建人id长度不能超过32位")
        private String createId;
    
        /**
         * 修改时间
         */
        @JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
        private Date modifyDate;
    
        /**
         * 修改人
         */
        @Size(max = 32,message = "修改人长度不能超过32位")
        private String modifyId;
    
        @Transient
        @Valid
        private List<BzFundsDetailCy> bzFundsDetailCyList;
    
        private static final long serialVersionUID = 1L;
    

    dao层 继承通用Mapper适合于单表的增删改查

    @Repository
    public interface BzFundsCyDAO extends Mapper<BzFundsCy> {
    
    }
    

    .xml文件也放在dao层下

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="com.kingomedia.szpx.cy.dao.BzFundsCyDAO">
    
        <!--<select id="selectBzFoundsCyList">
            select bz.MRS_ID,bz.TERM_ID,bz.BUYER,bz.SALLER,bz.BILL_NO,to_char(bz.BILL_DATE,'yyyy-mm-dd')as BILL_DATE,bz.BILL_SUM
            from BZ_FUNDS_CY bz
            where 1=1
        </select>-->
    
        <select id="selectBzFoundsCyList">
            select b.mrs_id,b.bill_no,b.bill_sum,t1.org_name as buyer,t2.org_name as saller,to_char(b.bill_date,'yyyy-mm-dd') as  bill_date,b.create_id,to_char(b.create_date,'yyyy-mm-dd') as create_date
            from bz_funds_cy b inner join bz_org_tree t1 on b.buyer=t1.org_id inner join bz_org_tree t2 on b.saller=t2.org_id
        </select>
    
        <select id="selectBzFoundsCyListCount">
            select count(1)
            from bz_funds_cy b
            where 1=1
        </select>
    </mapper>
    

    service层包含接口和实现类

    public interface IBzFundsCy {
    
        //增加
        public ResultMap insertBzFundsCy(BzFundsCy bzFundsCy);
    
        //删除
        public ResultMap deleteBzFundsCyById(String id);
    
        //更新
        public ResultMap updateBzFundsCy(BzFundsCy bzFundsCy);
    
        //查询
        public ResultMap selectBzFundsCyById(String id);
    
        //自定义查询语句
        public ServiceResult getBzFundsCyList(Map<String, Object> whereMap);
    }
    
    @Service
    public class BzFundsCyService implements IBzFundsCy{
        @Autowired
        BzFundsCyDAO bzFundsCyDAO;
        @Autowired
        GetWhereFromMap getWhereFromMap;
        /**
         * 新增
         * @param bzFundsCy
         * @return
         */
        public ResultMap insertBzFundsCy(BzFundsCy bzFundsCy) {
            if(null == bzFundsCy.getMrsId() || bzFundsCy.getMrsId().equals("")){
    //            bzFundsCy.setMrsId((int)(Math.random() * 1000) + "");
                bzFundsCy.setMrsId(PersonController.getUUID32());
                bzFundsCy.setTermId(PersonController.getUUID32());
    //            bzFundsCy.setBillDate(new Date());
                bzFundsCy.setCreateId(PersonController.getUUID32());
                bzFundsCy.setModifyId(PersonController.getUUID32());
                bzFundsCy.setCreateDate(new Date());
                bzFundsCy.setModifyDate(new Date());
                bzFundsCyDAO.insertSelective(bzFundsCy);
            }
            return ResultMap.success("数据处理成功",null);
        }
    
        /**
         * 删除
         * @param id
         * @return
         */
        public ResultMap deleteBzFundsCyById(String id) {
            int i = bzFundsCyDAO.deleteByPrimaryKey(id);
            return ResultMap.success("数据处理成功",null);
        }
    
        /**
         * 更新
         * @param bzFundsCy
         * @return
         */
        public ResultMap updateBzFundsCy(BzFundsCy bzFundsCy) {
            if(bzFundsCy.getMrsId() != null || !bzFundsCy.getMrsId().equals("")){
                bzFundsCyDAO.updateByPrimaryKeySelective(bzFundsCy);
            }
            return ResultMap.success("数据处理成功",null);
        }
    
        /**
         * 查询
         * @param id
         * @return
         */
        public ResultMap selectBzFundsCyById(String id) {
            BzFundsCy bzFundsCy = bzFundsCyDAO.selectByPrimaryKey(id);
            return ResultMap.success("数据处理成功",null);
        }
    
        /**
         * 根据用户自定义的sql语句查询记录
         * @param whereMap
         * @return
         */
        public ServiceResult getBzFundsCyList(Map<String, Object> whereMap){
            String namespace="com.kingomedia.szpx.cy.dao.BzFundsCyDAO";
            String baseKey = "selectBzFoundsCyList";
            String countKey = "selectBzFoundsCyListCount";
            //String baseSql = jdbcBaseNamedParameterDao.getSqlString(namespace, baseKey);
            //String countSql = jdbcBaseNamedParameterDao.getSqlString(namespace, countKey);
    //        return getWhereFromMap.getOracleListByPage(baseSql,countSql,whereMap);
            return getWhereFromMap.getOracleListByPage(namespace,baseKey,countKey,whereMap);
        }
    }
    

    controller层

    @Controller
    public class BzFundsCyController {
    
        @Autowired
        BzFundsCyService bzFundsCyService;
    
        /**
         * 新增
         * @param bzFundsCy
         * @return
         */
        @RequestMapping("/insert")
        @ResponseBody
        public ResultMap insert(@RequestBody @Validated BzFundsCy bzFundsCy){
            return bzFundsCyService.insertBzFundsCy(bzFundsCy);
        }
    
        /**
         * 删除
         * @param mrsId
         * @return
         */
        @RequestMapping("/delete")
        @ResponseBody
        public ResultMap delete(String mrsId){
    
            return bzFundsCyService.deleteBzFundsCyById(mrsId);
        }
    
        /**
         * 更新
         * @param bzFundsCy
         * @return
         */
        @RequestMapping("/update")
        @ResponseBody
        public ResultMap update(@RequestBody @Validated BzFundsCy bzFundsCy){
            return bzFundsCyService.updateBzFundsCy(bzFundsCy);
        }
    
        /**
         * 查询
         * @param mrsId
         * @return
         */
        @RequestMapping("/select")
        @ResponseBody
        public ResultMap select(String mrsId){
    
            return bzFundsCyService.selectBzFundsCyById(mrsId);
        }
    
        /**
         * 自定义查询
         * @return
         */
        @RequestMapping("/selectList")
        @ResponseBody
        public ServiceResult selectList(@RequestBody Map<String,Object> whereMap){
            return bzFundsCyService.getBzFundsCyList(whereMap);
        }
    }
    

    相关文章

      网友评论

        本文标题:2019-07-01

        本文链接:https://www.haomeiwen.com/subject/iungcctx.html