手记系列之二 ----- 关于IDEA的一些使用方法经验( 五 )

6.mapper模板
HTML##引入mybatis支持$!mybatisSupport##设置保存名称与保存位置$!callback.setFileName($tool.append($!{tableInfo.name}, "Mapper.xml"))$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/guard/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}Dao"><resultMap type="$!{tableInfo.savePackageName}.vo.$!{tableInfo.name}VO" id="$!{tableInfo.name}Map">#foreach($column in $tableInfo.fullColumn)<result property="$!column.name" column="$!column.obj.name" jdbcType="$!column.ext.jdbcType"/>#end</resultMap><!--查询单个--><select id="queryById" resultMap="$!{tableInfo.name}Map">select#allSqlColumn()from $!tableInfo.obj.namewhere $!pk.obj.name = #{$!pk.name}</select><!--通过实体查询一条数据--><select id="findOne" resultMap="$!{tableInfo.name}Map">select#allSqlColumn()from $!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>limit 1</select><!--通过实体作为筛选条件查询--><select id="queryAll" resultMap="$!{tableInfo.name}Map">select#allSqlColumn()from $!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><!--新增所有列--><insert id="insert" keyProperty="$!pk.name" useGeneratedKeys="true">insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)values (#foreach($column in $tableInfo.otherColumn)#{$!{column.name}}#if($velocityHasNext), #end#end)</insert><insert id="insertBatch" keyProperty="$!pk.name" useGeneratedKeys="true">insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)values<foreach collection="entities" item="entity" separator=",">(#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($velocityHasNext), #end#end)</foreach></insert><insert id="insertOrUpdateBatch" keyProperty="$!pk.name" useGeneratedKeys="true">insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)values<foreach collection="entities" item="entity" separator=",">(#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($velocityHasNext), #end#end)</foreach>on duplicate key update#foreach($column in $tableInfo.otherColumn)$!column.obj.name = values($!column.obj.name) #if($velocityHasNext), #end#end</insert><!--通过主键修改数据--><update id="update">update $!{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.name} where $!pk.obj.name = #{$!pk.name}</delete></mapper>7.model模板
Kotlin##引入宏定义$!define##使用宏定义设置回调(保存位置与文件后缀)#save("/model", ".java")##使用宏定义设置包后缀#setPackageSuffix("model")##使用全局变量实现默认包导入$!autoImportimport com.alibaba.fastjson.JSONObject;import lombok.Data;import javax.persistence.Column;import javax.persistence.Table;import java.io.Serializable;import java.util.Date; /*** @Title: $!{tableInfo.comment}($!{tableInfo.name})实体类* @Description: * @Version:1.0.0 * @Since:jdk1.8 * @author $author* @date $!time.currTime()*/@Data@Table(name = "$tableInfo.obj.name")public class $!{tableInfo.name}implements Serializable{private static final long serialVersionUID = $!tool.serial();#foreach($column in $tableInfo.fullColumn)#if(${column.comment})/*** ${column.comment}*/#end@Column(name = "$column.obj.name")private $!{tool.getClsNameByFullName($column.type)} $!{column.name};#end@Overridepublic String toString(){return JSONObject.toJSONString(this);}}使用配置1.前提
该插件使用IDEA连接数据库,若未连接数据库,则需手动添加数据库.
MySql数据库添加示例:
点击IDEA右侧的database,点击+号,选择DataSource->MySQL,需要MySql驱动的jar,可以从maven仓库里面选择对应的jar 。
示例图:

手记系列之二 ----- 关于IDEA的一些使用方法经验

推荐阅读