mybatis insert语句

复制代码
<insert id="saveExportField" parameterType="com.seeyii.base.bean.ExportRecord" keyProperty="id" keyColumn="id" useGeneratedKeys="true">
INSERT INTO export_record
<trim prefix="(" suffix=")" suffixOverrides=",">

<if test="taskId != null">
taskId,
</if>
<if test="userId != null">
userId,
</if>
<if test="ptNo != null">
ptNo,
</if>
<if test="type != null">
type,
</if>
<if test="status != null">
status,
</if>
<if test="inter != null">
inter,
</if>
<if test="queryCondition != null">
queryCondition,
</if>
<if test="conditionName != null">
conditionName,
</if>
<if test="createTime != null">
createTime,
</if>
<if test="finishTime != null">
finishTime,
</if>
<if test="url != null">
url,
</if>
<if test="fileName != null">
fileName,
</if>
<if test="fileType != null">
fileType,
</if>
<if test="requestTotal != null">
requestTotal,
</if>
<if test="resultTotal != null">
resultTotal,
</if>
<if test="exportField != null">
exportField,
</if>
<if test="fingerId != null">
fingerId,
</if>
<if test="queryId != null">
queryId,
</if>
</trim>
<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
<if test="taskId != null" >
#{taskId},
</if>
<if test="userId != null" >
#{userId},
</if>
<if test="ptNo != null" >
#{ptNo},
</if>
<if test="type != null" >
#{type},
</if>
<if test="status != null" >
#{status},
</if>
<if test="inter != null" >
#{inter},
</if>
<if test="queryCondition != null" >
#{queryCondition},
</if>
<if test="conditionName != null" >
#{conditionName},
</if>
<if test="createTime != null" >
#{createTime},
</if>
<if test="finishTime != null" >
#{finishTime},
</if>
<if test="url != null" >
#{url},
</if>
<if test="fileName != null" >
#{fileName},
</if>
<if test="fileType != null" >
#{fileType},
</if>
<if test="requestTotal != null" >
#{requestTotal},
</if>
<if test="resultTotal != null" >
#{resultTotal},
</if>
<if test="exportField != null" >
#{exportField},
</if>
<if test="fingerId != null" >
#{fingerId},
</if>
<if test="queryId != null" >
#{queryId},
</if>
</trim>
</insert>
复制代码
useGeneratedKeys:是否返回生成的主键,service层用对象.getid()获取主键

keyProperty:传入对象中的主键列名

keyColumn:表中主键名
<trim prefix="(" suffix=")" suffixOverrides=",">:
prefix :需要添加的前缀  , suffix :需要添加的后缀 , suffixOverrides:需要去掉的后缀,因为最后会有一个逗号多余
posted @   杨吃羊  阅读(1629)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
历史上的今天:
2021-04-27 安装jenkins
2021-04-27 安装gitlab
点击右上角即可分享
微信分享提示