mybatis一些使用记录

#MyBatis使用记录

##bean中带集合
  
  1.先在java列中定义List<Answer> answer;
  2.在sqlmap文件中的resultMap标签下设置collection标签,property对应类中的属性,javaType对应类中的集合类,ofType集合类中的参数变量,然后里面按一般的Resultmap写就好了
        
   

 <collection property="answers" javaType="java.util.List" ofType="xx.Answer">
            <id property="id" column="answer_id"/>
            <result property="questionId" column="question_id" />
            <result property="answerNo" column="answer_no" />
    </collection>

 

  3.集合红的元素自己的sqlmap要设置好,它们之间是如何关联起来的,TODO

##搜索条件传入List
传入一个list,list的变量名为id,

  1. parameterType定义为list
  2. foreach

    <update id="recover" parameterType="list">
        update table 
        where id in 
        <foreach collection="list" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

 


##Oracle数据库插入ID设置

<insert id="add" parameterType="xxx.pojo.xxBean">
        <selectKey keyProperty="id" resultType="java.lang.Integer" order="BEFORE">  
                 select seq_item.nextval as id from dual   
        </selectKey>
        insert into table
        (id)
        values
        (#{id})
    </insert>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值