56gt 发表于 2016-11-26 01:01:29

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>
页: [1]
查看完整版本: mybatis一些使用记录