IDEAL编码常用工具

本文介绍了如何使用MybatisX和EasyCode工具自动化生成Java代码,包括实体类、DAO、Service和Controller,提升开发效率。同时提到了Lombok用于简化getter/setter等方法的编写,以及Alibaba Java Coding Guidelines确保代码规范。此外,还讨论了git提交模板、快捷键提示工具和装逼神器PowerModeii。
摘要由CSDN通过智能技术生成

1 MybatisX 与 EasyCode 一键自动生成代码

2 Lombok Lombok能通过注解的方式,在编译时自动为属性生成构造器、getter/setter、equals、hashcode、toString方法

3 Alibaba_Java_Coding_Guidelines 自动核实代码规范

4 Commit_Template git提交模板

5 ke_ Promoter_X 快捷键提示工具

6 Power Mode ii 装逼神器

EasyCode 模板
entity

##引入宏定义
$!define

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

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

##使用全局变量实现默认包导入
$!autoImport
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
 * $!{tableInfo.comment}($!{tableInfo.name})
 *
 * @author $!author
 * @since $!time.currTime()
 */
@Data
@TableName("${tableInfo.obj.name}") 
public class $!{tableInfo.name} implements Serializable {

	private static final long serialVersionUID = $!tool.serial();

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


	@TableId(value = "${pk.obj.name}", type = IdType.AUTO)
	private ${pk.shortType} ${pk.name};
	
	#foreach($column in $tableInfo.otherColumn)
	
    #if(${column.comment})
/**
     * ${column.comment}
     */#end
	 
    @TableField(value = "$!{column.obj.name}")
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
	#end

}

dao
 

##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Mapper"))

##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/dao"))


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

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

import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;

/**
 * $!{tableInfo.comment}($!{tableInfo.name})
 *
 * @author $!author
 * @since $!time.currTime()
 */
 @Mapper
 public interface $!{tableName} extends BaseMapper<$!{tableInfo.name}>{
	 
	public Page<$!{tableInfo.name}> findPageList($!{tableInfo.name} page ,@Param("req") $!{tableInfo.name} req);
	 
	 
 }

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 com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
/**
 * $!{tableInfo.comment}($!{tableInfo.name})
 *
 * @author $!author
 * @since $!time.currTime()
 */
public interface $!{tableName} extends IService<$!{tableInfo.name}>{
	
	public IPage<$!{tableInfo.name}> findPageList(Page<$!{tableInfo.name}> page ,$!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name));
	
}

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 $!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Mapper;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import javax.annotation.Resource;
/**
 * $!{tableInfo.comment}($!{tableInfo.name})
 *
 * @author $!author
 * @since $!time.currTime()
 */
@Service
public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Mapper,$!{tableInfo.name}> implements $!{tableInfo.name}Service{
	
	/**
     * 服务对象
	 */
	@Resource
	private $!{tableInfo.name}Mapper $!tool.firstLowerCase($tableInfo.name)Mapper;
	 

    @Override
    public IPage<$!{tableInfo.name}> findPageList(Page<$!{tableInfo.name}> page ,$!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name)){
    	
        return  getBaseMapper().findPageList(page,$!tool.firstLowerCase($tableInfo.name));
    }
	
}

mapper

##引入mybatis支持
$!mybatisSupport

##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "Mapper.xml"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/config/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}.dao.$!{tableInfo.name}Mapper">

    <resultMap type="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}" id="BaseResultMap">
#foreach($column in $tableInfo.fullColumn)
        <result property="$!column.name" column="$!column.obj.name" jdbcType="$!column.ext.jdbcType"/>
#end
    </resultMap>
	
	<!-- 基本字段 -->
    <sql id="Base_Column_List">
        #allSqlColumn()
        
    </sql>
	<!--通过实体作为筛选条件查询-->
    <select id="findPageList" resultMap="BaseResultMap">
        select
          <include refid="Base_Column_List" />
        from $!tableInfo.obj.name
        <where>
#foreach($column in $tableInfo.fullColumn)
            <if test="req.$!column.name != null#if($column.type.equals("java.lang.String")) and req.$!column.name != ''#end">
                and $!column.obj.name = #{$!column.name}
            </if>
#end
        </where>
    </select>
</mapper>

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 org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * $!{tableInfo.comment}($!{tableInfo.name})
 *
 * @author $!author
 * @since $!time.currTime()
 */
 @RestController
 @RequestMapping("$!tool.firstLowerCase($tableInfo.name)")
 public class $!{tableName}{
	 
	/**
     * 服务对象
	 */
	@Resource
	private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;
	 
	 
	@RequestMapping("/$!tool.firstLowerCase($tableInfo.name)Page")
    public ResultVO<Object>  $!tool.firstLowerCase($tableInfo.name)page($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name)) {
        Page<$!{tableInfo.name}> page = new Page<>(1,10);
		$!tool.firstLowerCase($tableInfo.name)Service. findPageList(page,$!tool.firstLowerCase($tableInfo.name));
    }
	 
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

程治铭

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

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

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

打赏作者

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

抵扣说明:

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

余额充值
>