idea 自定义EasyCode 代码生成格式

如下配置,可自动生成entity、controller、service、serviceImpl、dao、mapper文件

实现简单的CRUD接口

1、entity.java

##引入宏定义
$!define

##使用宏定义设置回调(保存位置与文件后缀)
#save("/model", ".java")

##使用宏定义设置包后缀
#setPackageSuffix("model")

##使用全局变量实现默认包导入
$!autoImport
import java.io.Serializable;
import lombok.Data;
##使用宏定义实现类注释信息
#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
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
    #end
}

2、controller.java

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

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

import com.zjimee.boot.core.vo.requestParam.CommonRequest;
import com.zjimee.boot.rest.common.ResultCode;
import com.zjimee.boot.rest.constant.StatusCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zjimee.boot.core.model.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.service.$!{tool.firstLowerCase($!{tableInfo.name})}.$!{tableInfo.name}Service;
import org.springframework.web.bind.annotation.*;
import com.zjimee.boot.rest.common.ResultCode;
import javax.servlet.http.HttpServletRequest;
import javax.annotation.Resource;
/**
 * $!{tableInfo.comment}($!{tableInfo.name})表控制层
 *
 * @author wangj
 * @since $!time.currTime()
 */
@RestController
@RequestMapping("/$!tool.firstLowerCase($tableInfo.name)")
public class $!{tableName} {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 服务对象
     */
    @Resource
    private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;

    /**
     * 通过主键查询单条数据
     *
     * @param  $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
     * @return 单条数据
     */
    @GetMapping("/selectOne")
    public ResultCode selectOne($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
        try {
            return this.$!{tool.firstLowerCase($tableInfo.name)}Service.queryById($!tool.firstLowerCase($!{tableInfo.name}));
        } catch (Exception e) {
            return new ResultCode(StatusCode.Exception, "查询信息异常");
        }
    }
    
      /**
     * 条件查询
     *
     * @param request commonRequest
     * @return 单条数据
     */
    @PostMapping("/queryList")
    public ResultCode queryList(HttpServletRequest request,@RequestBody CommonRequest commonRequest) {
        try {
            return this.$!{tool.firstLowerCase($!{tableInfo.name})}Service.queryList(request,commonRequest);
        } catch (Exception e) {
            return new ResultCode(StatusCode.Exception, "查询信息异常");
        }
    }

    /**
     * 新增信息
     *
     * @param  $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
     * @return
     */
    @PostMapping("/insert")
    public ResultCode insert(HttpServletRequest request,@RequestBody $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
        try {
            return this.$!{tool.firstLowerCase($!{tableInfo.name})}Service.insert(request,$!tool.firstLowerCase($!{tableInfo.name}));
        } catch (Exception e) {       
            return new ResultCode(StatusCode.Exception, "新增异常");
        }

    }

    /**
     * 修改信息
     *
     * @param  $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
     * @return
     */
    @PostMapping("/up
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wangjie827

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值