码迷,mamicode.com
首页 > 其他好文 > 详细

MyBatis总结

时间:2017-04-14 15:42:59      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:select   uri   lis   and   alt   批量添加数据   engine   bsp   ble   

1.insert后 主键的使用

   

<insert id="insert" parameterType="cn.QualitySupervision.model.Projectinformation" useGeneratedKeys="true" keyProperty="projectnaid">

insert into projectinformation (projectnaid, projectname, projecttype,
project_status, divide_status, investment,
engineeringstatus, projectsite, subordinatejurisdiction,
declarationorgan, startorgan, approvalnumber,
approvaltime, schedule, approvalmoney,
qualityorganname, qualityorganaddress,
starttime, endtime, idpath,
userId, construction_content, memo,
lpoint, rpoint, delete_flag,
is_end, is_append, is_acceptance,
is_supervision_plan, is_sampling_plan, is_supervision_check,
is_rectify_report, is_check_approval, is_intermediate,
is_completion_acceptance, project_status_dictionary
)
values (#{projectnaid,jdbcType=INTEGER}, #{projectname,jdbcType=VARCHAR}, #{projecttype,jdbcType=INTEGER},
#{projectStatus,jdbcType=INTEGER}, #{divideStatus,jdbcType=INTEGER}, #{investment,jdbcType=VARCHAR},
#{engineeringstatus,jdbcType=INTEGER}, #{projectsite,jdbcType=VARCHAR}, #{subordinatejurisdiction,jdbcType=INTEGER},
#{declarationorgan,jdbcType=VARCHAR}, #{startorgan,jdbcType=VARCHAR}, #{approvalnumber,jdbcType=VARCHAR},
#{approvaltime,jdbcType=DATE}, #{schedule,jdbcType=VARCHAR}, #{approvalmoney,jdbcType=DOUBLE},
#{qualityorganname,jdbcType=VARCHAR}, #{qualityorganaddress,jdbcType=VARCHAR},
#{starttime,jdbcType=DATE}, #{endtime,jdbcType=DATE}, #{idpath,jdbcType=VARCHAR},
#{userid,jdbcType=INTEGER}, #{constructionContent,jdbcType=VARCHAR}, #{memo,jdbcType=VARCHAR},
#{lpoint,jdbcType=VARCHAR}, #{rpoint,jdbcType=VARCHAR}, #{deleteFlag,jdbcType=INTEGER},
#{isEnd,jdbcType=INTEGER}, #{isAppend,jdbcType=INTEGER}, #{isAcceptance,jdbcType=INTEGER},
#{isSupervisionPlan,jdbcType=INTEGER}, #{isSamplingPlan,jdbcType=INTEGER}, #{isSupervisionCheck,jdbcType=INTEGER},
#{isRectifyReport,jdbcType=INTEGER}, #{isCheckApproval,jdbcType=INTEGER}, #{isIntermediate,jdbcType=INTEGER},
#{isCompletionAcceptance,jdbcType=INTEGER}, #{projectStatusDictionary,jdbcType=INTEGER}
)
</insert>

2.   时间区间查询的使用

   

<if test="startTime != null and startTime != ‘‘">
<!-- and apply_time >= #{startTime,jdbcType=TIMESTAMP} -->
<![CDATA[and date_format(starttime,‘%Y-%m-%d‘)>=date_format(#{startTime},‘%Y-%m-%d‘)]]>
</if>
<if test="endTime != null and endTime != ‘‘">
<!-- and apply_time >= #{startTime,jdbcType=TIMESTAMP} -->
<![CDATA[and date_format(starttime,‘%Y-%m-%d‘)<=date_format(#{endTime},‘%Y-%m-%d‘)]]>
</if>

3.模糊查询的使用

<if test="projectname != null and projectname != ‘‘">
and pjf.projectname like ‘%${projectname}%‘
</if>

4.批量添加数据

<insert id="insertList">
insert into acceptance_check

  (  id, project_id, project_type, check_user_id, check_date,

     check_status, quality_level, conclusion, competent_desc, accreditation,

    idpath,acceptance_check_status,part_unit_num,finished_unit_num,great_unit_num

  )
  <foreach collection="list" index="index" item="item" separator="union all">
  select
  #{item.id},
  #{item.projectId},
  #{item.projectType},
  #{item.checkUserId},
  #{item.checkDate},
  #{item.checkStatus},
  #{item.qualityLevel},
  #{item.conclusion},
  #{item.competentDesc},
  #{item.accreditation},
  #{item.idpath} ,
  #{item.acceptanceCheckStatus},
  #{item.partUnitNum},
  #{item.finishedUnitNum},
  #{item.greatUnitNum}
  from dual
  </foreach>
  </insert>

后台java dao层代码 void insertList(@Param("list")List<AcceptanceCheck> list);

 

MyBatis总结

标签:select   uri   lis   and   alt   批量添加数据   engine   bsp   ble   

原文地址:http://www.cnblogs.com/zb347954263/p/6709135.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!