MyBatis总结
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MyBatis总结相关的知识,希望对你有一定的参考价值。
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总结的主要内容,如果未能解决你的问题,请参考以下文章