Mybatis用法小结
2015-10-28 14:49
441 查看
select
1.基本用法
<select id="selectTableOne" resultType="com.test.entity.tableOne">
select * from tableOne
</select>
2.内连接
<sql id="joins">
INNER JOIN rich.PSUBDAYBOOK ON rich.PMAINDAYBOOK.SALENO = rich.PSUBDAYBOOK.SALENO
INNER JOIN rich.BITEM ON rich.PSUBDAYBOOK.ICODE = rich.BITEM.ICODE
</sql>
<select id="getAllTest" resultMap="BaseResultMap" parameterType="java.lang.String">
select * from test
<include refid="joins"/>
</select>
2.带参数
<select>
select * from table
where id = #{id}
</select>
<select>
select * from table
where id like CONCAT('%',#{name},'%') //这里是mysql的写法如果是其他数据库参见:: http://w6513017.iteye.com/blog/1512761
</select>
update
<update parameterType="com.trade2cn.im.bean.testTable">
update testTable
<set>
<if test="id!=null">
id=#{id}
</if>
</set>
where name=#{name}
</update>
insert
<insert id="insertTestBale" parameterType="com.test.TestTable">
insert into test
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
t_id,
</if>
<if test="name != null">
t_name
</if>
</trim>
<trim prefix="values(" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id},
</if>
<if test="name != null">
#{name}
</if>
</trim>
</insert>
delete
1.基本用法
<select id="selectTableOne" resultType="com.test.entity.tableOne">
select * from tableOne
</select>
2.内连接
<sql id="joins">
INNER JOIN rich.PSUBDAYBOOK ON rich.PMAINDAYBOOK.SALENO = rich.PSUBDAYBOOK.SALENO
INNER JOIN rich.BITEM ON rich.PSUBDAYBOOK.ICODE = rich.BITEM.ICODE
</sql>
<select id="getAllTest" resultMap="BaseResultMap" parameterType="java.lang.String">
select * from test
<include refid="joins"/>
</select>
2.带参数
<select>
select * from table
where id = #{id}
</select>
<select>
select * from table
where id like CONCAT('%',#{name},'%') //这里是mysql的写法如果是其他数据库参见:: http://w6513017.iteye.com/blog/1512761
</select>
update
<update parameterType="com.trade2cn.im.bean.testTable">
update testTable
<set>
<if test="id!=null">
id=#{id}
</if>
</set>
where name=#{name}
</update>
insert
<insert id="insertTestBale" parameterType="com.test.TestTable">
insert into test
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
t_id,
</if>
<if test="name != null">
t_name
</if>
</trim>
<trim prefix="values(" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id},
</if>
<if test="name != null">
#{name}
</if>
</trim>
</insert>
delete
相关文章推荐
- Js实现对中文进行排序
- PHP加密解密函数详解
- iOS界面编程-UIPageControl
- DIY Ruby CPU 分析——Part III
- hdu1422(简单dp)
- 碎片Fragment
- SQL Server编程(03)自定义存储过程
- 做重要决定的时候
- C++11:变长模板的迭代与递归扩展
- IOS SWIFT alte形式获取手机的相册和相机
- Android Volley完全解析(一),初识Volley的基本用法
- OpenAL基本介绍
- Vmware虚拟机下三种网络模式配置
- 认识REST
- Codevs 1427 特种部队
- Android --DOM SAX XML 的解析
- Leetcode -- Word Break
- 浅谈Swift集合类型
- OC学习笔记(六)
- 混淆后显示行号