mybatis自动生成mapper.xml的方法
来源:互联网 发布:源代码如何变成软件 编辑:程序博客网 时间:2024/05/05 11:14
1. 首先添加maven插件
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>src/test/resources/config/generatorConfig.xml</configurationFile> //这是与数据库的配置地址
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
2.其次填写与数据库连接配置文件<?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 >
<classPathEntry location="/Users/seabook.liu/.m2/repository/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar" />
<context id="context1" >
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/test" userId="root" password="" />(数据库连接)
<javaModelGenerator targetPackage="com.dianping.poi.updateflow.biz.model" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="config.sqlmap.updateflow" targetProject="src/main/resources" >(生成的mapper文件)
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<javaClientGenerator targetPackage="com.dianping.poi.updateflow.biz.dao" targetProject="src/main/java" type="XMLMAPPER" >(生成的dao层接口)
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<table schema="" tableName="POI_Shop"(数据库表名) domainObjectName="PoiShop"(生产的实体对象)
enableCountByExample="true"
enableUpdateByExample="true"
enableDeleteByExample="true"
enableSelectByExample="true"
selectByExampleQueryId="true"
>
</table>
</context>
</generatorConfiguration>
3.利用maven命令自动生成
mybatis-generator:generate
4.最后能生成如下文件
只是实例一个
<?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.dianping.poi.updateflow.biz.dao.ProcInfoDao" >
<resultMap id="BaseResultMap" type="com.dianping.poi.updateflow.biz.model.ProcInfo" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Tue Jul 28 16:24:30 CST 2015.
-->
<id column="proc_id" property="procId" jdbcType="INTEGER" />
<result column="flow_id" property="flowId" jdbcType="INTEGER" />
<result column="entry_id" property="entryId" jdbcType="INTEGER" />
<result column="proc_type" property="procType" jdbcType="VARCHAR" />
<result column="proc_status" property="procStatus" jdbcType="TINYINT" />
<result column="editer_id" property="editerId" jdbcType="VARCHAR" />
<result column="result" property="result" jdbcType="VARCHAR" />
<result column="explain" property="explain" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
<result column="ext" property="ext" jdbcType="VARCHAR" />
</resultMap>
<sql id="Example_Where_Clause" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Tue Jul 28 16:24:30 CST 2015.
-->
<where >
<foreach collection="oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<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 collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Tue Jul 28 16:24:30 CST 2015.
-->
<where >
<foreach collection="example.oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<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 collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Tue Jul 28 16:24:30 CST 2015.
-->
proc_id, flow_id, entry_id, proc_type, proc_status, editer_id, result, explain, create_time,
update_time, ext
</sql>
<select id="selectByExample" resultMap="BaseResultMap" parameterType="com.dianping.poi.updateflow.biz.model.ProcInfoExample" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Tue Jul 28 16:24:30 CST 2015.
-->
select
<if test="distinct" >
distinct
</if>
'true' as QUERYID,
<include refid="Base_Column_List" />
from POI_ProcInfo
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Tue Jul 28 16:24:30 CST 2015.
-->
select
<include refid="Base_Column_List" />
from POI_ProcInfo
where proc_id = #{procId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Tue Jul 28 16:24:30 CST 2015.
-->
delete from POI_ProcInfo
where proc_id = #{procId,jdbcType=INTEGER}
</delete>
<delete id="deleteByExample" parameterType="com.dianping.poi.updateflow.biz.model.ProcInfoExample" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Tue Jul 28 16:24:30 CST 2015.
-->
delete from POI_ProcInfo
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.dianping.poi.updateflow.biz.model.ProcInfo" useGeneratedKeys="true" keyProperty="procId">
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Tue Jul 28 16:24:30 CST 2015.
-->
insert into POI_ProcInfo (proc_id, flow_id, entry_id,
proc_type, proc_status, editer_id,
result, explain, create_time,
update_time, ext)
values (#{procId,jdbcType=INTEGER}, #{flowId,jdbcType=INTEGER}, #{entryId,jdbcType=INTEGER},
#{procType,jdbcType=VARCHAR}, #{procStatus,jdbcType=TINYINT}, #{editerId,jdbcType=VARCHAR},
#{result,jdbcType=VARCHAR}, #{explain,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP}, #{ext,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.dianping.poi.updateflow.biz.model.ProcInfo" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Tue Jul 28 16:24:30 CST 2015.
-->
insert into POI_ProcInfo
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="procId != null" >
proc_id,
</if>
<if test="flowId != null" >
flow_id,
</if>
<if test="entryId != null" >
entry_id,
</if>
<if test="procType != null" >
proc_type,
</if>
<if test="procStatus != null" >
proc_status,
</if>
<if test="editerId != null" >
editer_id,
</if>
<if test="result != null" >
result,
</if>
<if test="explain != null" >
explain,
</if>
<if test="createTime != null" >
create_time,
</if>
<if test="updateTime != null" >
update_time,
</if>
<if test="ext != null" >
ext,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="procId != null" >
#{procId,jdbcType=INTEGER},
</if>
<if test="flowId != null" >
#{flowId,jdbcType=INTEGER},
</if>
<if test="entryId != null" >
#{entryId,jdbcType=INTEGER},
</if>
<if test="procType != null" >
#{procType,jdbcType=VARCHAR},
</if>
<if test="procStatus != null" >
#{procStatus,jdbcType=TINYINT},
</if>
<if test="editerId != null" >
#{editerId,jdbcType=VARCHAR},
</if>
<if test="result != null" >
#{result,jdbcType=VARCHAR},
</if>
<if test="explain != null" >
#{explain,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="ext != null" >
#{ext,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.dianping.poi.updateflow.biz.model.ProcInfoExample" resultType="java.lang.Integer" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Tue Jul 28 16:24:30 CST 2015.
-->
select count(*) from POI_ProcInfo
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Tue Jul 28 16:24:30 CST 2015.
-->
update POI_ProcInfo
<set >
<if test="record.procId != null" >
proc_id = #{record.procId,jdbcType=INTEGER},
</if>
<if test="record.flowId != null" >
flow_id = #{record.flowId,jdbcType=INTEGER},
</if>
<if test="record.entryId != null" >
entry_id = #{record.entryId,jdbcType=INTEGER},
</if>
<if test="record.procType != null" >
proc_type = #{record.procType,jdbcType=VARCHAR},
</if>
<if test="record.procStatus != null" >
proc_status = #{record.procStatus,jdbcType=TINYINT},
</if>
<if test="record.editerId != null" >
editer_id = #{record.editerId,jdbcType=VARCHAR},
</if>
<if test="record.result != null" >
result = #{record.result,jdbcType=VARCHAR},
</if>
<if test="record.explain != null" >
explain = #{record.explain,jdbcType=VARCHAR},
</if>
<if test="record.createTime != null" >
create_time = #{record.createTime,jdbcType=TIMESTAMP},
</if>
<if test="record.updateTime != null" >
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
</if>
<if test="record.ext != null" >
ext = #{record.ext,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Tue Jul 28 16:24:30 CST 2015.
-->
update POI_ProcInfo
set proc_id = #{record.procId,jdbcType=INTEGER},
flow_id = #{record.flowId,jdbcType=INTEGER},
entry_id = #{record.entryId,jdbcType=INTEGER},
proc_type = #{record.procType,jdbcType=VARCHAR},
proc_status = #{record.procStatus,jdbcType=TINYINT},
editer_id = #{record.editerId,jdbcType=VARCHAR},
result = #{record.result,jdbcType=VARCHAR},
explain = #{record.explain,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=TIMESTAMP},
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
ext = #{record.ext,jdbcType=VARCHAR}
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.dianping.poi.updateflow.biz.model.ProcInfo" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Tue Jul 28 16:24:30 CST 2015.
-->
update POI_ProcInfo
<set >
<if test="flowId != null" >
flow_id = #{flowId,jdbcType=INTEGER},
</if>
<if test="entryId != null" >
entry_id = #{entryId,jdbcType=INTEGER},
</if>
<if test="procType != null" >
proc_type = #{procType,jdbcType=VARCHAR},
</if>
<if test="procStatus != null" >
proc_status = #{procStatus,jdbcType=TINYINT},
</if>
<if test="editerId != null" >
editer_id = #{editerId,jdbcType=VARCHAR},
</if>
<if test="result != null" >
result = #{result,jdbcType=VARCHAR},
</if>
<if test="explain != null" >
explain = #{explain,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="ext != null" >
ext = #{ext,jdbcType=VARCHAR},
</if>
</set>
where proc_id = #{procId,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.dianping.poi.updateflow.biz.model.ProcInfo" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Tue Jul 28 16:24:30 CST 2015.
-->
update POI_ProcInfo
set flow_id = #{flowId,jdbcType=INTEGER},
entry_id = #{entryId,jdbcType=INTEGER},
proc_type = #{procType,jdbcType=VARCHAR},
proc_status = #{procStatus,jdbcType=TINYINT},
editer_id = #{editerId,jdbcType=VARCHAR},
result = #{result,jdbcType=VARCHAR},
explain = #{explain,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP},
ext = #{ext,jdbcType=VARCHAR}
where proc_id = #{procId,jdbcType=INTEGER}
</update>
</mapper>
- mybatis自动生成mapper.xml的方法
- mybatis自动生成mapper xml 映射 文件
- mybatis自动生成domain,service,mapper,xml
- Mybatis--使用mybatis generator插件映射数据库,自动生成pojo对象,dao接口,mapper.xml文件的方法
- 【mybatis】mapper.xml文件自动扫描注入的方法
- MyBatis-自动生成pojo、mapper和mapper.xml
- mybatis 自动生成 mapper
- 增加Mybatis-generator生成的Mapper类和Mapper.xml里的方法
- 用mybatis-gennerator插件自动生成mybatis所需要的dao、bean、mapper xml文件
- ssm项目使用mybatis-generator工具自动生成实体类、*mapper.xml、dao层方法
- mybatis 自动生成实体类、mapper.xml文件
- mybatis自动生成mapper.xml和接口实体类工具
- mybatis反转自动生成dao、实体类和mapper.xml
- mybatis-generatorConfig.xml 文件编写自动生成MAPPER文件
- 如何利用maven配置mybatis-generator自动生成mapper.xml
- mybatis自动生成dao, model, mapper xml文件
- Mybatis自动生成实体类、mapper.xml和dao
- mybatis使用---利用mybatis-generator自动生成mapper、model、mapper.xml
- hdu 5348 MZL's endless loop 暴搜
- 怎么去掉Xcode工程中的某种类型的警告
- jquery选中checkbox的问题
- 指针数组的应用场景之main函数
- 基于caffe特征可视化 以及 用训练好的模型进行分类
- mybatis自动生成mapper.xml的方法
- 素数伴侣
- 高质量CSS
- 【转】Qt5.2.1移植新唐n32905测试 转的一位朋友的过程,基本能够通过。
- Android底部导航中间突起
- 彻底理解webservice SOAP WSDL
- CSS3圆圈旋转的样式
- ffmpeg 烧写 字幕到视频中命令
- SQL Sever MD5加密。