mybatis对象的插入

 

 

 

 

或者:

 

 

传入JAVA对象

mapper接口代码:

public int findUserList(User user);   

xml代码:

 

复制代码
<select id="findUserList" parameterType="User" resultType="java.lang.Integer"> SELECT COUNT(*) FROM USER user <where> <if test="code != null"> and user.CODE = #{code} </if> <if test="id != null"> and user.ID = #{id} </if> <if test="idList !=null "> and user.ID in ( <foreach collection="idList" item="id" index="index" separator=","> #{id} </foreach> ) </if> </where> </select> 
复制代码

 JAVA对象中有list或array时,foreach中的collection必须是具体list或array的变量名。

比如这里User含有一个名为idList的list,所以User中用idList取值,这点和单独传list或array时不太一样。

 

注解@Param

   注解单一属性;这个类似于将参数重命名了一次

例子1:

mapper接口代码:

List<User> selectUserByTime(@Param(value="startdate")String startDate);  

xml代码:

<select id="selectUserByTime" resultType="User" parameterType="java.lang.String"> select * from t_user where create_time >= to_date(#{startdate,jdbcType=VARCHAR},'YYYY-MM-DD') </select> 

例子2:

注解javaBean

mapper接口代码:

List<User> selectUserByTime(@Param(value="dateVO")DateVO dateVO);  

xml代码:

<select id="selectUserByTime" resultType="User" parameterType="DateVO"> select * from t_user where create_time >= to_date(#{dateVO.startDate,jdbcType=VARCHAR},'YYYY-MM-DD') and create_time < to_date(#{dateVO.endDate,jdbcType=VARCHAR},'YYYY-MM-DD') </select> 

 

转载于:https://www.cnblogs.com/leeego-123/p/10497127.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值