mapper写法
来源:互联网 发布:我的淘宝 编辑:程序博客网 时间:2024/06/05 09:29
<?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="cn.itcast.jk.mapper.FactoryMapper">
<!-- resultMap映射 -->
<resultMap type="cn.itcast.jk.domain.Factory" id="factoryRM">
<!-- 主键 -->
<id property="id" column="FACTORY_ID"/>
<!-- 一般属性 -->
<result property="fullName" column="FULL_NAME"/>
<result property="factoryName" column="FACTORY_NAME"/>
<result property="contacts" column="CONTACTS"/>
<result property="phone" column="PHONE"/>
<result property="mobile" column="MOBILE"/>
<result property="fax" column="FAX"/>
<result property="cnote" column="CNOTE"/>
<result property="inspector" column="INSPECTOR"/>
<result property="orderNo" column="ORDER_NO"/>
<result property="state" column="STATE"/>
<result property="createBy" column="CREATE_BY"/>
<result property="createDept" column="CREATE_DEPT"/>
<result property="createTime" column="CREATE_TIME"/>
</resultMap>
<!-- 查询 -->
<select id="find" parameterType="map" resultMap="factoryRM">
select * from factory_c
where 1=1
<if test="state!=null"> and STATE=#{state}</if>
</select>
<!-- 查询一个 -->
<select id="get" parameterType="string" resultMap="factoryRM">
select * from factory_c
where factory_id=#{pid}
</select>
<!-- 新增 oracle jdbc驱动 当这个值为null时,必须告诉它当前字段默认值的类型jdbcType=VARCHAR (mybatis定义),
无效的列类型: 1111; nested exception is java.sql.SQLException
mysql不用写 -->
<insert id="insert" parameterType="cn.itcast.jk.domain.Factory">
insert into factory_c
(FACTORY_ID,FULL_NAME,FACTORY_NAME,CONTACTS,PHONE,MOBILE,FAX,CNOTE,INSPECTOR,ORDER_NO,STATE,CREATE_BY,CREATE_DEPT,CREATE_TIME)
values
( #{id},
#{fullName, jdbcType=VARCHAR},
#{factoryName, jdbcType=VARCHAR},
#{contacts, jdbcType=VARCHAR},
#{phone, jdbcType=VARCHAR},
#{mobile, jdbcType=VARCHAR},
#{fax, jdbcType=VARCHAR},
#{cnote, jdbcType=VARCHAR},
#{inspector, jdbcType=VARCHAR},
#{orderNo, jdbcType=INTEGER},
#{state, jdbcType=VARCHAR},
#{createBy, jdbcType=VARCHAR},
#{createDept, jdbcType=VARCHAR},
#{createTime, jdbcType=TIMESTAMP}
)
</insert>
<!-- 修改 动态SQL语句 -->
<update id="update" parameterType="cn.itcast.jk.domain.Factory">
update factory_c
<set>
<if test="fullName != null">FULL_NAME=#{fullName, jdbcType=VARCHAR},</if>
<if test="factoryName != null">FACTORY_NAME=#{factoryName, jdbcType=VARCHAR},</if>
<if test="contacts != null">CONTACTS=#{contacts, jdbcType=VARCHAR},</if>
<if test="phone != null">PHONE=#{phone, jdbcType=VARCHAR},</if>
<if test="mobile != null">MOBILE=#{mobile, jdbcType=VARCHAR},</if>
<if test="fax != null">FAX=#{fax, jdbcType=VARCHAR},</if>
<if test="cnote != null">CNOTE=#{cnote, jdbcType=VARCHAR},</if>
<if test="inspector != null">INSPECTOR=#{inspector, jdbcType=VARCHAR},</if>
<if test="orderNo != null">ORDER_NO=#{orderNo, jdbcType=INTEGER},</if>
<if test="state != null">STATE=#{state, jdbcType=VARCHAR},</if>
</set>
where FACTORY_ID=#{id}
</update>
<!-- 删除一条 -->
<delete id="deleteById" parameterType="string">
delete from factory_c
where FACTORY_ID=#{pid}
</delete>
<!-- 删除多条(一维字符串数组) -->
<delete id="delete" parameterType="string">
delete from factory_c
where FACTORY_ID in
<foreach collection="array" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</delete>
<!-- 修改状态 -->
<update id="updateState" parameterType="map">
update factory_c set state=#{state}
where FACTORY_ID in
<foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</update>
</mapper>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.itcast.jk.mapper.FactoryMapper">
<!-- resultMap映射 -->
<resultMap type="cn.itcast.jk.domain.Factory" id="factoryRM">
<!-- 主键 -->
<id property="id" column="FACTORY_ID"/>
<!-- 一般属性 -->
<result property="fullName" column="FULL_NAME"/>
<result property="factoryName" column="FACTORY_NAME"/>
<result property="contacts" column="CONTACTS"/>
<result property="phone" column="PHONE"/>
<result property="mobile" column="MOBILE"/>
<result property="fax" column="FAX"/>
<result property="cnote" column="CNOTE"/>
<result property="inspector" column="INSPECTOR"/>
<result property="orderNo" column="ORDER_NO"/>
<result property="state" column="STATE"/>
<result property="createBy" column="CREATE_BY"/>
<result property="createDept" column="CREATE_DEPT"/>
<result property="createTime" column="CREATE_TIME"/>
</resultMap>
<!-- 查询 -->
<select id="find" parameterType="map" resultMap="factoryRM">
select * from factory_c
where 1=1
<if test="state!=null"> and STATE=#{state}</if>
</select>
<!-- 查询一个 -->
<select id="get" parameterType="string" resultMap="factoryRM">
select * from factory_c
where factory_id=#{pid}
</select>
<!-- 新增 oracle jdbc驱动 当这个值为null时,必须告诉它当前字段默认值的类型jdbcType=VARCHAR (mybatis定义),
无效的列类型: 1111; nested exception is java.sql.SQLException
mysql不用写 -->
<insert id="insert" parameterType="cn.itcast.jk.domain.Factory">
insert into factory_c
(FACTORY_ID,FULL_NAME,FACTORY_NAME,CONTACTS,PHONE,MOBILE,FAX,CNOTE,INSPECTOR,ORDER_NO,STATE,CREATE_BY,CREATE_DEPT,CREATE_TIME)
values
( #{id},
#{fullName, jdbcType=VARCHAR},
#{factoryName, jdbcType=VARCHAR},
#{contacts, jdbcType=VARCHAR},
#{phone, jdbcType=VARCHAR},
#{mobile, jdbcType=VARCHAR},
#{fax, jdbcType=VARCHAR},
#{cnote, jdbcType=VARCHAR},
#{inspector, jdbcType=VARCHAR},
#{orderNo, jdbcType=INTEGER},
#{state, jdbcType=VARCHAR},
#{createBy, jdbcType=VARCHAR},
#{createDept, jdbcType=VARCHAR},
#{createTime, jdbcType=TIMESTAMP}
)
</insert>
<!-- 修改 动态SQL语句 -->
<update id="update" parameterType="cn.itcast.jk.domain.Factory">
update factory_c
<set>
<if test="fullName != null">FULL_NAME=#{fullName, jdbcType=VARCHAR},</if>
<if test="factoryName != null">FACTORY_NAME=#{factoryName, jdbcType=VARCHAR},</if>
<if test="contacts != null">CONTACTS=#{contacts, jdbcType=VARCHAR},</if>
<if test="phone != null">PHONE=#{phone, jdbcType=VARCHAR},</if>
<if test="mobile != null">MOBILE=#{mobile, jdbcType=VARCHAR},</if>
<if test="fax != null">FAX=#{fax, jdbcType=VARCHAR},</if>
<if test="cnote != null">CNOTE=#{cnote, jdbcType=VARCHAR},</if>
<if test="inspector != null">INSPECTOR=#{inspector, jdbcType=VARCHAR},</if>
<if test="orderNo != null">ORDER_NO=#{orderNo, jdbcType=INTEGER},</if>
<if test="state != null">STATE=#{state, jdbcType=VARCHAR},</if>
</set>
where FACTORY_ID=#{id}
</update>
<!-- 删除一条 -->
<delete id="deleteById" parameterType="string">
delete from factory_c
where FACTORY_ID=#{pid}
</delete>
<!-- 删除多条(一维字符串数组) -->
<delete id="delete" parameterType="string">
delete from factory_c
where FACTORY_ID in
<foreach collection="array" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</delete>
<!-- 修改状态 -->
<update id="updateState" parameterType="map">
update factory_c set state=#{state}
where FACTORY_ID in
<foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</update>
</mapper>
阅读全文
0 0
- mapper写法
- mybaits mapper.xml的写法
- mybatis 模糊查询 mapper.xml的写法
- mybatis的mapper配置文件的一般写法。
- mybatis映射文件mapper.xml的写法。
- mybatis sql mapper 用map的写法
- 自定义Mapper文件的几种写法
- mybatis批量insert的mapper xml写法
- Mybatis增删改查mapper文件写法
- mybatis中mapper传集合写法
- Mybatis mapper.xml 判断条件写法注意
- mapper.xml中SQL语句in的写法
- Mybatis中Mapper.xml文件中的update语句写法
- mybatis sql in 查询 mapper与service层写法
- mybatis一对多和多对一种mapper的写法
- java mybatis 处理数据库 接口写法(Controller----Service----Mapper)
- mybatis中mapper.xml中模糊查询写法
- 列表上移下移的SQL语句(mybatis mapper.xml写法)
- 使用new创建数组
- 手动实现HashMap
- 关于实现背景为自动循环播放、无声的、宽度自适应视频的相关问题
- 主成分分析PCA
- MongoDB Shell简单入门(增删改查)
- mapper写法
- 11-散列2 Hashing (25分)
- #297. 【CTSC2017】密钥
- springmvc 4
- Android--AIDL基础介绍
- 推荐一款基于 Bootstrap 的 jQuery 表格插件Bootstrap table
- 5.27 JLL--实习日志--
- eclipse使用小技巧
- 定义一个自定义数组(可以像正常使用系统数组的全部功能)