Mybatis用法小结
select
1.基本用法
<select id="selectTableOne" resultType="com.test.entity.tableOne">
? ?? ?select * from tableOne
? </select>
2.內(nèi)連接
<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.帶參數(shù)
<select>
select * from table
where?? id? =?? #{id}
</select>
<select>
select * from table
where?? id? like ? CONCAT('%',#{name},'%')???? //這里是mysql的寫法如果是其他數(shù)據(jù)庫參見::? 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
?
轉(zhuǎn)載于:https://www.cnblogs.com/wangxiangstudy/p/4917338.html
總結(jié)
以上是生活随笔為你收集整理的Mybatis用法小结的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MessageBox只弹出一次
- 下一篇: 软件测试流程参考一