mybatis-generator-core-1.3.6.jar代码生成器的使用
使用代码生成器能快速的生成mapper、实体类、以及mapper映射文件,大大提高了开发效率,具体步骤如下:
1、新建一个格式为XML的配置文件 名称generatorConfig
我把配置文件放在了resources目录下的generator下
-
<?xml version="1.0" encoding="UTF-8"?>
-
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
-
<generatorConfiguration>
-
<!-- 1、生成文件的命令:java -jar mybatis-generator-core-1.3.6.jar -configfile generatorConfig.xml -overwrite
-
2、在mybatis-generator-core-1.3.6.jar所在目录按住Shift键,右键鼠标选择"在此处打开命令窗口",复制粘贴生成文件的命令即可。 -->
-
-
<!-- 数据库驱动包位置 -->
-
<classPathEntry location="D:\apache-maven-3.6.1\repository\mysql\mysql-connector-java\5.1.6\mysql-connector-java-5.1.6.jar" />
-
<context id="DB2Tables" targetRuntime="MyBatis3">
-
<plugin type="org.mybatis.generator.plugins.RowBoundsPlugin"></plugin>
-
<commentGenerator>
-
<property name="suppressAllComments" value="true" />
-
</commentGenerator>
-
<!-- 数据库链接URL、用户名、密码 -->
-
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
-
connectionURL="jdbc:mysql://localhost:8080/mp?characterEncoding=utf-8"
-
userId="root"
-
password="123456">
-
</jdbcConnection>
-
<javaTypeResolver>
-
<property name="forceBigDecimals" value="false" />
-
</javaTypeResolver>
-
<!-- pojo -->
-
<javaModelGenerator targetPackage="com.caochenlei.mpdemo.pojo"
-
targetProject="E:\Test\mp-demo\src\main\java">
-
<property name="enableSubPackages" value="true" />
-
<property name="trimStrings" value="true" />
-
</javaModelGenerator>
-
<!-- xml -->
-
<sqlMapGenerator targetPackage="com.caochenlei.mpdemo.mapper"
-
targetProject="E:\Test\mp-demo\src\main\resources">
-
<property name="enableSubPackages" value="true" />
-
</sqlMapGenerator>
-
-
<!-- DAo -->
-
<javaClientGenerator type="XMLMAPPER"
-
targetPackage="com.caochenlei.mpdemo.mapper"
-
targetProject="E:\Test\mp-demo\src\main\java">
-
<property name="enableSubPackages" value="true" />
-
</javaClientGenerator>
-
-
<table tableName="Test_case" domainObjectName="TestCaseDO" enableDeleteByExample="false" >
-
</table>
-
-
</context>
-
</generatorConfiguration>
需要修改的有:
1、数据库驱动包位置
2、数据库地址以及账号密码
3、实体类的包名以及路径
4、xml映射文件的包名及路径
5、DAO的路径
6、tableName表名称 domainObjectName 需要生成的类名(会根据配置的库名中的表名生成实体类、mapper、mapper映射文件)
二、下载 mybatis-generator-core-1.3.6.jar
链接:https://pan.百度.com/s/1URuElNFllYMNCIBWBYfrbw
提取码:obqj
和XML文件放在同一个目录下
三、进入Terminal命令界面 cd到jar包放置的目录
resources目录下的generator下
cd src\main\resources\generator
输入如下命令java -jar mybatis-generator-core-1.3.6.jar -configfile generatorConfig.xml -overwrite
回车即可
四、看看效果
实体类:
-
package com.caochenlei.mpdemo.pojo;
-
-
-
import java.sql.Date;
-
-
public class SysUserDO {
-
private Long uid;
-
-
private String userName;
-
-
private String passWord;
-
-
private String nickName;
-
-
private String mobile;
-
-
private String email;
-
-
private String createTime;
-
-
private String updateTime;
-
-
public Long getUid() {
-
return uid;
-
}
-
-
public void setUid(Long uid) {
-
this.uid = uid;
-
}
-
-
public String getUserName() {
-
return userName;
-
}
-
-
public void setUserName(String userName) {
-
this.userName = userName == null ? null : userName.trim();
-
}
-
-
public String getPassWord() {
-
return passWord;
-
}
-
-
public void setPassWord(String passWord) {
-
this.passWord = passWord == null ? null : passWord.trim();
-
}
-
-
public String getNickName() {
-
return nickName;
-
}
-
-
public void setNickName(String nickName) {
-
this.nickName = nickName == null ? null : nickName.trim();
-
}
-
-
public String getMobile() {
-
return mobile;
-
}
-
-
public void setMobile(String mobile) {
-
this.mobile = mobile == null ? null : mobile.trim();
-
}
-
-
public String getEmail() {
-
return email;
-
}
-
-
public void setEmail(String email) {
-
this.email = email == null ? null : email.trim();
-
}
-
-
public String getCreateTime() {
-
return createTime;
-
}
-
-
public void setCreateTime(String createTime) {
-
this.createTime = createTime;
-
}
-
-
public String getUpdateTime() {
-
return updateTime;
-
}
-
-
public void setUpdateTime(String updateTime) {
-
this.updateTime = updateTime;
-
}
-
}
mapper:
-
package com.caochenlei.mpdemo.mapper;
-
-
import com.caochenlei.mpdemo.pojo.SysUserDO;
-
import com.caochenlei.mpdemo.pojo.SysUserDOExample;
-
import java.util.List;
-
import org.apache.ibatis.annotations.Param;
-
import org.apache.ibatis.session.RowBounds;
-
-
public interface SysUserDOMapper {
-
long countByExample(SysUserDOExample example);
-
-
int deleteByPrimaryKey(Long uid);
-
-
int insert(SysUserDO record);
-
-
int insertSelective(SysUserDO record);
-
-
List<SysUserDO> selectByExampleWithRowbounds(SysUserDOExample example, RowBounds rowBounds);
-
-
List<SysUserDO> selectByExample(SysUserDOExample example);
-
-
SysUserDO selectByPrimaryKey(Long uid);
-
-
int updateByExampleSelective(; SysUserDO record, SysUserDOExample example)
-
-
int updateByExample(; SysUserDO record, SysUserDOExample example)
-
-
int updateByPrimaryKeySelective(SysUserDO record);
-
-
int updateByPrimaryKey(SysUserDO record);
-
-
List<SysUserDO> queryByPage(; Integer pageNo, Integer pageSize)
-
}
xml映射文件:
-
<?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.caochenlei.mpdemo.mapper.SysUserDOMapper">
-
<resultMap id="BaseResultMap" type="com.caochenlei.mpdemo.pojo.SysUserDO">
-
<id column="uid" jdbcType="BIGINT" property="uid" />
-
<result column="user_name" jdbcType="VARCHAR" property="userName" />
-
<result column="pass_word" jdbcType="VARCHAR" property="passWord" />
-
<result column="nick_name" jdbcType="VARCHAR" property="nickName" />
-
<result column="mobile" jdbcType="VARCHAR" property="mobile" />
-
<result column="email" jdbcType="VARCHAR" property="email" />
-
<result column="create_time" jdbcType="DATE" property="createTime" />
-
<result column="update_time" jdbcType="DATE" property="updateTime" />
-
</resultMap>
-
<sql id="Example_Where_Clause">
-
<where>
-
<foreach collection="oredCriteria" item="criteria" separator="or">
-
<if test="criteria.valid">
-
<trim prefix="(" prefixOverrides="and" suffix=")">
-
<foreach collection="criteria.criteria" item="criterion">
-
<choose>
-
<when test="criterion.noValue">
-
and ${criterion.condition}
-
</when>
-
<when test="criterion.singleValue">
-
and ${criterion.condition} #{criterion.value}
-
</when>
-
<when test="criterion.betweenValue">
-
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
-
</when>
-
<when test="criterion.listValue">
-
and ${criterion.condition}
-
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
-
#{listItem}
-
</foreach>
-
</when>
-
</choose>
-
</foreach>
-
</trim>
-
</if>
-
</foreach>
-
</where>
-
</sql>
-
<sql id="Update_By_Example_Where_Clause">
-
<where>
-
<foreach collection="example.oredCriteria" item="criteria" separator="or">
-
<if test="criteria.valid">
-
<trim prefix="(" prefixOverrides="and" suffix=")">
-
<foreach collection="criteria.criteria" item="criterion">
-
<choose>
-
<when test="criterion.noValue">
-
and ${criterion.condition}
-
</when>
-
<when test="criterion.singleValue">
-
and ${criterion.condition} #{criterion.value}
-
</when>
-
<when test="criterion.betweenValue">
-
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
-
</when>
-
<when test="criterion.listValue">
-
and ${criterion.condition}
-
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
-
#{listItem}
-
</foreach>
-
</when>
-
</choose>
-
</foreach>
-
</trim>
-
</if>
-
</foreach>
-
</where>
-
</sql>
-
<sql id="Base_Column_List">
-
uid, user_name, pass_word, nick_name, mobile, email, create_time, update_time
-
</sql>
-
<select id="selectByExample" parameterType="com.caochenlei.mpdemo.pojo.SysUserDOExample" resultMap="BaseResultMap">
-
select
-
<if test="distinct">
-
distinct
-
</if>
-
<include refid="Base_Column_List" />
-
from user_base
-
<if test="_parameter != null">
-
<include refid="Example_Where_Clause" />
-
</if>
-
<if test="orderByClause != null">
-
order by ${orderByClause}
-
</if>
-
</select>
-
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
-
select
-
<include refid="Base_Column_List" />
-
from user_base
-
where uid = #{uid,jdbcType=BIGINT}
-
</select>
-
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
-
delete from user_base
-
where uid = #{uid,jdbcType=BIGINT}
-
</delete>
-
<insert id="insert" parameterType="com.caochenlei.mpdemo.pojo.SysUserDO">
-
insert into user_base (uid, user_name, pass_word,
-
nick_name, mobile, email,
-
create_time, update_time)
-
values (#{uid,jdbcType=BIGINT}, #{userName,jdbcType=VARCHAR}, #{passWord,jdbcType=VARCHAR},
-
#{nickName,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR},
-
#{createTime,jdbcType=DATE}, #{updateTime,jdbcType=DATE})
-
</insert>
-
<insert id="insertSelective" parameterType="com.caochenlei.mpdemo.pojo.SysUserDO">
-
insert into user_base
-
<trim prefix="(" suffix=")" suffixOverrides=",">
-
<if test="uid != null">
-
uid,
-
</if>
-
<if test="userName != null">
-
user_name,
-
</if>
-
<if test="passWord != null">
-
pass_word,
-
</if>
-
<if test="nickName != null">
-
nick_name,
-
</if>
-
<if test="mobile != null">
-
mobile,
-
</if>
-
<if test="email != null">
-
email,
-
</if>
-
<if test="createTime != null">
-
create_time,
-
</if>
-
<if test="updateTime != null">
-
update_time,
-
</if>
-
</trim>
-
<trim prefix="values (" suffix=")" suffixOverrides=",">
-
<if test="uid != null">
-
#{uid,jdbcType=BIGINT},
-
</if>
-
<if test="userName != null">
-
#{userName,jdbcType=VARCHAR},
-
</if>
-
<if test="passWord != null">
-
#{passWord,jdbcType=VARCHAR},
-
</if>
-
<if test="nickName != null">
-
#{nickName,jdbcType=VARCHAR},
-
</if>
-
<if test="mobile != null">
-
#{mobile,jdbcType=VARCHAR},
-
</if>
-
<if test="email != null">
-
#{email,jdbcType=VARCHAR},
-
</if>
-
<if test="createTime != null">
-
#{createTime,jdbcType=DATE},
-
</if>
-
<if test="updateTime != null">
-
#{updateTime,jdbcType=DATE},
-
</if>
-
</trim>
-
</insert>
-
<select id="countByExample" parameterType="com.caochenlei.mpdemo.pojo.SysUserDOExample" resultType="java.lang.Long">
-
select count(*) from user_base
-
<if test="_parameter != null">
-
<include refid="Example_Where_Clause" />
-
</if>
-
</select>
-
<update id="updateByExampleSelective" parameterType="map">
-
update user_base
-
<set>
-
<if test="record.uid != null">
-
uid = #{record.uid,jdbcType=BIGINT},
-
</if>
-
<if test="record.userName != null">
-
user_name = #{record.userName,jdbcType=VARCHAR},
-
</if>
-
<if test="record.passWord != null">
-
pass_word = #{record.passWord,jdbcType=VARCHAR},
-
</if>
-
<if test="record.nickName != null">
-
nick_name = #{record.nickName,jdbcType=VARCHAR},
-
</if>
-
<if test="record.mobile != null">
-
mobile = #{record.mobile,jdbcType=VARCHAR},
-
</if>
-
<if test="record.email != null">
-
email = #{record.email,jdbcType=VARCHAR},
-
</if>
-
<if test="record.createTime != null">
-
create_time = #{record.createTime,jdbcType=DATE},
-
</if>
-
<if test="record.updateTime != null">
-
update_time = #{record.updateTime,jdbcType=DATE},
-
</if>
-
</set>
-
<if test="_parameter != null">
-
<include refid="Update_By_Example_Where_Clause" />
-
</if>
-
</update>
-
<update id="updateByExample" parameterType="map">
-
update user_base
-
set uid = #{record.uid,jdbcType=BIGINT},
-
user_name = #{record.userName,jdbcType=VARCHAR},
-
pass_word = #{record.passWord,jdbcType=VARCHAR},
-
nick_name = #{record.nickName,jdbcType=VARCHAR},
-
mobile = #{record.mobile,jdbcType=VARCHAR},
-
email = #{record.email,jdbcType=VARCHAR},
-
create_time = #{record.createTime,jdbcType=DATE},
-
update_time = #{record.updateTime,jdbcType=DATE}
-
<if test="_parameter != null">
-
<include refid="Update_By_Example_Where_Clause" />
-
</if>
-
</update>
-
<update id="updateByPrimaryKeySelective" parameterType="com.caochenlei.mpdemo.pojo.SysUserDO">
-
update user_base
-
<set>
-
<if test="userName != null">
-
user_name = #{userName,jdbcType=VARCHAR},
-
</if>
-
<if test="passWord != null">
-
pass_word = #{passWord,jdbcType=VARCHAR},
-
</if>
-
<if test="nickName != null">
-
nick_name = #{nickName,jdbcType=VARCHAR},
-
</if>
-
<if test="mobile != null">
-
mobile = #{mobile,jdbcType=VARCHAR},
-
</if>
-
<if test="email != null">
-
email = #{email,jdbcType=VARCHAR},
-
</if>
-
<if test="createTime != null">
-
create_time = #{createTime,jdbcType=DATE},
-
</if>
-
<if test="updateTime != null">
-
update_time = #{updateTime,jdbcType=DATE},
-
</if>
-
</set>
-
where uid = #{uid,jdbcType=BIGINT}
-
</update>
-
<update id="updateByPrimaryKey" parameterType="com.caochenlei.mpdemo.pojo.SysUserDO">
-
update user_base
-
set user_name = #{userName,jdbcType=VARCHAR},
-
pass_word = #{passWord,jdbcType=VARCHAR},
-
nick_name = #{nickName,jdbcType=VARCHAR},
-
mobile = #{mobile,jdbcType=VARCHAR},
-
email = #{email,jdbcType=VARCHAR},
-
create_time = #{createTime,jdbcType=DATE},
-
update_time = #{updateTime,jdbcType=DATE}
-
where uid = #{uid,jdbcType=BIGINT}
-
</update>
-
<select id="selectByExampleWithRowbounds" parameterType="com.caochenlei.mpdemo.pojo.SysUserDOExample" resultMap="BaseResultMap">
-
select
-
<if test="distinct">
-
distinct
-
</if>
-
<include refid="Base_Column_List" />
-
from user_base
-
<if test="_parameter != null">
-
<include refid="Example_Where_Clause" />
-
</if>
-
<if test="orderByClause != null">
-
order by ${orderByClause}
-
</if>
-
</select>
-
-
<select id="queryByPage" resultMap="BaseResultMap">
-
select * from user_base limit #{pageNo},#{pageSize}
-
</select>
-
</mapper>
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhhkigkh
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
微信运动停用后别人还能看到步数吗
PHP中文网 07-22