myibatis的写法
来源:互联网 发布:怎样装饰淘宝店铺2016 编辑:程序博客网 时间:2024/05/01 18:07
!!!!!!!!!!!!!!!!!!!!!!!!特别注意地方(坑)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
aa如果传的int型 下面的if条件是不会进入的,因为有 and aa !=''" 这个说明aa只能为string
<if test="aa!= null and aa !=''">
and bb.aa1= #{aa}
</if>
1. 普通的 work_no = '001'
<if test="workNo!=null and workNo!=''">
and work_no=#{workNo}
</if>
2. 普通的 work_no in ( '001')
workNos可以为List<String> 或者String[]
<if test="workNos!=null and workNos.size()>0">
and work_no in
<foreach item="item" index="index" collection="workNos" open="(" separator="," close=")">
#{item}
</foreach>
</if>
对应的SQL:work_no in ('001','002')
3. 普通的 and ( (work_no = ( '001') ) or (work_no = ( '002') ) )
workList 为:List<Map<String,Object>> workList = new ArrayList<Map<String,Object>>();
<if test="workList !=null and workList.size()>0">
and<foreach item="item" index="index" collection="works" open="(" separator="or" close=")" >
(work_no = #{item.workNo} and order_num = #{item.orderNum})
//或者 work_no = #{item}
</foreach></if>
对应的SQL:and ( (work_no = '001' } and order_num = '0' ) or (work_no = '002' and order_num = '1' ) )
4.插入语法:
<insert id="insertSelective" parameterType="com.**.**.某某pojo类" >
insert into tableName
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="creator != null" >
creator,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="creator != null" >
#{creator,jdbcType=VARCHAR},
</if>
</trim>
<selectKey resultType="java.lang.Long" keyProperty="id" > //主键自增
SELECT LAST_INSERT_ID()
</selectKey>
</insert>
5. update写法
<update id="updateByPrimaryKeySelective" parameterType="com.**.**.某某pojo类" >
update tableName
<set >
<if test="creator != null" >
creator = #{creator,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
6. 包含写法
<mapper namespace="com.company.dal.mapper.modle.UserMapper" >
<resultMap id="bbb" type="com.company.dal.domain.modle.User" >
<id column="id" property="id" jdbcType="BIGINT" />
.....
</resultMap>
<sql id="Base_Column_List" >
a.id .....
</sql>
<sql id="COMMON_CONDITION">
<if test="status != null and status != ''">
and a.status=#{status}
</if>
........
</sql>
select
<include refid="Base_Column_List" />
from table_name a
where a.is_deleted='n'
<include refid="COMMON_CONDITION" />
</select>
- myibatis的写法
- myibatis的学习
- myIbatis
- Spring与myibatis的整合
- Myibatis和spring(mvc)的集成
- myibatis--以接口的方式编程
- 讨论Hibernate和myibatis的优缺点
- Ibatis和myIbatis 返回插入的主键ID
- MyiBatis总结
- Myibatis foreach
- MyIbatis学习 (二)--利用Generator插件生成基于数据库方言的分页语句
- Log4j properties myibatis配置文件
- myibatis学习笔记
- myibatis动态插入主键
- myibatis--增删查改
- myibatis--学习点滴
- myibatis传多个参数
- myibatis 嵌套查询
- ERROR 1148 (42000): The used command is not allowed with this MySQL version
- jrebel 热部署工具
- 当服务器空间不足的时候,删除属于自己的版本。
- 如何将BMP文件转换为JPG文件
- 学习Ajax技术
- myibatis的写法
- struts2采用convention-plugin实现零配置
- 谷歌调试工具祝你一臂之力买火车票,简单安全方便
- epoll_create, epoll_ctl和epoll_wait 讲解
- Tomcat中实现IP访问限制
- IOS APP配置.plist汇总
- VC实现HTTP上传和下载
- computer system study Part1
- 基本Kmeans算法介绍及其实现(转载)