http://blog.csdn.net/java_mr_zheng/article/details/50476757
三、兼容不同的数据库
复制代码
1 <insert id="insert">
2 <selectKey keyProperty="id" resultType="int" order="BEFORE">
3 <if test="_databaseId == 'oracle'">
4 select seq_users.nextval from dual
5 </if>
6 <if test="_databaseId == 'db2'">
7 select nextval for seq_users from sysibm.sysdummy1"
8 </if>
9 </selectKey>
10 insert into users values (#{id}, #{name})
11 </insert>
1 <select id="findActiveBlogLike"
2 resultType="Blog">
3 SELECT * FROM BLOG WHERE state = ‘ACTIVE’
4 <choose>
5 <when test="title != null">
6 AND title like #{title}
7 </when>
8 <when test="author != null and author.name != null">
9 AND author_name like #{author.name}
10 </when>
11 <otherwise>
12 AND featured = 1
13 </otherwise>
14 </choose>
15 </select>
mybatis 兼容两种数据的写法
猜你喜欢
转载自dannyhz.iteye.com/blog/2405585
今日推荐
周排行