easycode相关配置

3 篇文章 0 订阅
  1. easycode相关配置

参考位置:火狐浏览器easycode文件夹

2.模板

Entity

##引入宏定义
$!{define.vm}
 
##使用宏定义设置回调(保存位置与文件后缀)
#save("/entity", ".java")
 
##使用宏定义设置包后缀
#setPackageSuffix("entity")
 
##使用全局变量实现默认包导入
$!{autoImport.vm}
import lombok.Data;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;

##使用宏定义实现类注释信息
#tableComment("实体类")
@Data
public class $!{tableInfo.name} implements Serializable{
private static final long serialVersionUID = $!tool.serial();
#foreach($column in $tableInfo.fullColumn)
#if(${column.comment})/**
* ${column.comment}
*/#end
 @ApiModelProperty(required=true,value="${column.comment}")
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
 
}

Controller

##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Controller"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/controller"))
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end

#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller;

import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import com.emi.appclock.entity.resultmodel.$!{tableInfo.name}Result;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.emi.appclock.entity.responsebean.ResultPageBean;
import com.emi.appclock.entity.responsebean.ResultBeanObj;
import com.github.pagehelper.PageInfo;
import com.emi.appclock.entity.searchbean.PageParam;

/**
 * $!{tableInfo.comment}($!{tableInfo.name})表控制层
 *
 * @author $!author
 * @since $!time.currTime()
 */
@Controller
@RequestMapping("/$!tool.firstLowerCase($tableInfo.name)")
@Api(tags="$tableInfo.name")
@CrossOrigin
public class $!{tableName} {
    /**
     * 服务对象
     */
    @Autowired
    private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;

    /**
     * 分页查询
     */
      @RequestMapping(value="/queryAll" ,method= RequestMethod.POST)
     @ResponseBody
     @ApiResponses({
             @ApiResponse(code = 1,message = "成功",response = $!{tableInfo.name}Result.class),
     })
     @ApiOperation(httpMethod = "POST", value = "查询所有",notes="查询所有(例子)   {\"indexPage\":1,\"pageSize\":10,\"searchbean\":{}}\n-\n")
     public ResultPageBean queryAll(@RequestBody @ApiParam(name="分页对象",value="传入json格式{返回的数据:}",required=true) PageParam<$!{tableInfo.name}Result> pageParam){
       PageInfo pageInfo=  $!{tool.firstLowerCase($tableInfo.name)}Service.queryAll(pageParam);
         return ResultPageBean.success().setData(pageInfo);
     }
     
    /**
     * 通过主键查询单条数据
     * @return 单条数据
     */
         @RequestMapping(value="/queryById" ,method= RequestMethod.POST)
      @ResponseBody
      @ApiResponses({
              @ApiResponse(code = 1,message = "成功",response = $!{tableInfo.name}Result.class),
      })
      @ApiOperation(httpMethod = "POST", value = "根据ID查询",notes="根据ID查询(例子)&nbsp;&nbsp;&nbsp;{\"id\":5}\n-\n")
      public ResultBeanObj queryById(@RequestBody @ApiParam(name="根据ID查询",value="传入json格式{返回的数据:}",required=true) $!{tableInfo.name}Result param){
          try {
           return  $!{tool.firstLowerCase($tableInfo.name)}Service.queryById(param.getId());
          } catch (Exception e) {
              return  ResultBeanObj.fail(e.getMessage());
          }
      }
      
    /**
     * 新增数据
     * @return 新增结果
     */
     @RequestMapping(value="/add$!{tableInfo.name}" ,method= RequestMethod.POST)
     @ResponseBody
     @ApiOperation(httpMethod = "POST", value = "新增$!{tableInfo.name}",notes="新增$!{tableInfo.name}(例子)&nbsp;&nbsp;&nbsp;\n-\n")
     public ResultBeanObj add$!{tableInfo.name}(@RequestBody @ApiParam(name="新增$!{tableInfo.name}",value="传入json格式{返回的数据:}",required=true)$!{tableInfo.name}Result param){
           try {
                return  $!{tool.firstLowerCase($tableInfo.name)}Service.add(param);
             } catch (Exception e) {
                 return  ResultBeanObj.fail(e.getMessage());
             }
     }
     
    /**
     * 编辑数据
     * @return 编辑结果
     */
  @RequestMapping(value = "/update$!{tableInfo.name}", method = RequestMethod.POST)
        @ResponseBody
        @ApiOperation(httpMethod = "POST", value = "修改$!{tableInfo.name}",notes="修改$!{tableInfo.name}(例子)&nbsp;&nbsp;&nbsp;\n-\n")
        public ResultBeanObj update$!{tableInfo.name}(@RequestBody @ApiParam(name = "修改$!{tableInfo.name}", value = "传入json格式{返回的数据:}", required = true)$!{tableInfo.name}Result param){
            try {
                 return   $!{tool.firstLowerCase($tableInfo.name)}Service.update(param);
            } catch (Exception e) {
                return ResultBeanObj.fail(e.getMessage());
            }
        }
        
    /**
     * 删除数据
     * @return 删除是否成功
     */
          @RequestMapping(value="/deleteById" ,method= RequestMethod.POST)
        @ResponseBody
        @ApiOperation(httpMethod = "POST", value = "逻辑删除",notes="逻辑删除(例子)&nbsp;&nbsp;&nbsp;{\"id\":1}\n-\n")
        public ResultBeanObj deleteById(@RequestBody @ApiParam(name="逻辑删除",value="传入json格式{返回的数据:}",required=true)$!{tableInfo.name}Result param){
            try {
                  return   $!{tool.firstLowerCase($tableInfo.name)}Service.deleteById(param.getId());
            } catch (Exception e) {
                return  ResultBeanObj.fail(e.getMessage());
            }
        }
}

Dao

##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Mapper"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/Mapper"))

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end

package com.emi.appclock.mapper;
import com.emi.appclock.entity.resultmodel.$!{tableInfo.name}Result;
import org.springframework.stereotype.Repository;
import java.util.List;


/**
 * $!{tableInfo.comment}($!{tableInfo.name})表数据库访问层
 *
 * @author $!author
 * @since $!time.currTime()
 */
 @Repository
public interface $!{tableName} {
    $!{tableInfo.name}Result queryById(Long id);
    int update($!{tableInfo.name}Result param);
    int deleteById(Long id);
    int insertNotNull($!{tableInfo.name}Result param);
    int logicalDeleteById(Long id);
    List<$!{tableInfo.name}Result> queryAll($!{tableInfo.name}Result searchbean);
}

Mapper

##引入mybatis支持
$!mybatisSupport

##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "Mapper.xml"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/mapper"))

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end

<?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="$!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper">

    <!--查询单个-->
    <select id="queryById" resultType="$!{tableInfo.savePackageName}.entity.resultmodel.$!{tableInfo.name}Result">
        select * from $!{tableInfo.obj.parent.name}.$!tableInfo.obj.name
        where $!pk.obj.name = #{$!pk.name}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultType="$!{tableInfo.savePackageName}.entity.resultmodel.$!{tableInfo.name}Result">
        select * from $!{tableInfo.obj.parent.name}.$!tableInfo.obj.name
        limit #{offset}, #{limit}
    </select>

    <!--通过实体作为筛选条件查询-->
    <select id="queryAll" resultType="$!{tableInfo.savePackageName}.entity.resultmodel.$!{tableInfo.name}Result">
        select * from $!{tableInfo.obj.parent.name}.$!tableInfo.obj.name
        <where>
#foreach($column in $tableInfo.fullColumn)
            <if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
                and $!column.obj.name = #{$!column.name}
            </if>
#end
        </where>
    </select>

    <!--通过主键修改数据-->
    <update id="update">
        update $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}
        <set>
#foreach($column in $tableInfo.otherColumn)
            <if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
                $!column.obj.name = #{$!column.name},
            </if>
#end
        </set>
        where $!pk.obj.name = #{$!pk.name}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name}
    </delete>

   <!--通过主键(逻辑)删除-->
    <update id="logicalDeleteById">
        update $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}  set isdel=1 where $!pk.obj.name = #{$!pk.name}
    </update>
    
      <!--是否存在-->
    <select id="isExist$!{tableInfo.name}" parameterType="$!{tableInfo.savePackageName}.entity.resultmodel.$!{tableInfo.name}Result">
        select * from $!{tableInfo.obj.parent.name}.$!tableInfo.obj.name where $!pk.obj.name = #{$!pk.name} limit 1 
    </select>
    
       <!--新增实体属性不为null的列-->
    <insert id="insertNotNull" keyProperty="$!pk.name" useGeneratedKeys="true" parameterType="$!{tableInfo.savePackageName}.entity.resultmodel.$!{tableInfo.name}Result">
        insert into  $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}
        <trim prefix="(" suffix=")" suffixOverrides=",">
#foreach($column in  $tableInfo.fullColumn)
          <if test="$!column.name != null">
             $!column.obj.name,
          </if>
#end          
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
#foreach($column in  $tableInfo.fullColumn)
          <if test="$!column.name != null">
             #{$!column.name},
          </if>
#end
        </trim>
    </insert>
</mapper>

Service

##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Service"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/service"))

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end

#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service;

import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import com.emi.appclock.entity.CUser;
import com.emi.appclock.entity.responsebean.ResultBeanObj;
import com.github.pagehelper.PageInfo;
import com.emi.appclock.entity.CUserResult;
import com.emi.appclock.entity.searchbean.PageParam;
import com.emi.appclock.entity.resultmodel.$!{tableInfo.name}Result;

/**
 * $!{tableInfo.comment}($!{tableInfo.name})表服务接口
 *
 * @author $!author
 * @since $!time.currTime()
 */
public interface $!{tableName}{
    ResultBeanObj add($!{tableInfo.name}Result param);
    ResultBeanObj deleteById(Long id);
    ResultBeanObj update($!{tableInfo.name}Result param);
    ResultBeanObj queryById(Long id);
    PageInfo queryAll(PageParam<$!{tableInfo.name}Result> pageParam);

}

ServiceImpl

##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "ServiceImpl"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/service/impl"))

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end

#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service.impl;

import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import com.emi.appclock.mapper.$!{tableInfo.name}Mapper;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import com.emi.appclock.entity.responsebean.ResultBeanObj;
import com.emi.appclock.entity.searchbean.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.PageHelper;
import com.emi.appclock.until.StringUtil;
import java.util.List;
import com.emi.appclock.entity.resultmodel.$!{tableInfo.name}Result;

/**
 * $!{tableInfo.comment}($!{tableInfo.name})表服务实现类
 *
 * @author $!author
 * @since $!time.currTime()
 */
@Service("$!tool.firstLowerCase($!{tableInfo.name})Service")
public class $!{tableName} implements $!{tableInfo.name}Service {
     @Autowired
    private $!{tableInfo.name}Mapper $!tool.firstLowerCase($!{tableInfo.name})Mapper;

    /**
     * 通过ID查询单条数据
     * @return 实例对象
     */
        @Override
    public ResultBeanObj queryById(Long id) {
          $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})=this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.queryById(id);
         return  ResultBeanObj.success().setData($!tool.firstLowerCase($!{tableInfo.name}));
    }

   
    @Override
    public PageInfo queryAll(PageParam<$!{tableInfo.name}Result> pageParam) {
        PageHelper.startPage( pageParam.getIndexPage(),  pageParam.getPageSize());
        List<$!{tableInfo.name}Result> list = this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.queryAll(pageParam.getSearchbean());
        if (!StringUtil.isNullObject(list) && list.size() > 0) {
            for ($!{tableInfo.name}Result item : list) {

            }
        }
        return new PageInfo<>(list);
    }
    
     /**
     * 新增数据
     * @return 实例对象
     */
    @Override
    public ResultBeanObj add($!{tableInfo.name}Result param) {
        this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.insertNotNull(param);
      return ResultBeanObj.success().setData(param);
    }

    /**
     * 修改数据
     * @return 实例对象
     */
    @Override
    public ResultBeanObj update($!{tableInfo.name}Result param) {
        this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.update(param);
       return ResultBeanObj.success();
    }

    /**
     * 通过主键删除数据
     * @return 是否成功
     */
    @Override
    public ResultBeanObj deleteById(Long id) {
         this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.deleteById(id);
          return ResultBeanObj.success();
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值