经过尝试下面是一种可以实现的方式,分享一下
1 java 代码
public String insertChildReport(ChildReport childReport) {childReport.setCreateTime(DateUtils.getNowDate());LoginUser loginUser = getLoginUser();childReport.setCreateBy(loginUser.getUsername());childReport.setId(IdUtils.fastUUID());int i = childReportMapper.insertChildReport(childReport);return childReport.getId(); }
2 mybatis部分
<insert id="insertChildReport" parameterType="ChildReport" useGeneratedKeys="true" keyProperty="id">insert into child_report<trim prefix="(" suffix=")" suffixOverrides=","><if test="id != null">id,</if><if test="userId != null">user_id,</if><if test="userName != null">user_name,</if><if test="cid != null">cid,</if><if test="name != null">name,</if><if test="url != null">url,</if><if test="createTime != null">create_time,</if><if test="createBy != null">create_by,</if><if test="updateTime != null">update_time,</if><if test="updateBy != null">update_by,</if><if test="manualReportApp != null">manual_report_app,</if><if test="manualReport != null">manual_report,</if><if test="machineReport != null">machine_report,</if><if test="screeningChildId != null">screening_child_id,</if><if test="phone != null">phone,</if><if test="type != null">type,</if></trim><trim prefix="values (" suffix=")" suffixOverrides=","><if test="id != null">#{id},</if><if test="userId != null">#{userId},</if><if test="userName != null">#{userName},</if><if test="cid != null">#{cid},</if><if test="name != null">#{name},</if><if test="url != null">#{url},</if><if test="createTime != null">#{createTime},</if><if test="createBy != null">#{createBy},</if><if test="updateTime != null">#{updateTime},</if><if test="updateBy != null">#{updateBy},</if><if test="manualReportApp != null">#{manualReportApp},</if><if test="manualReport != null">#{manualReport},</if><if test="machineReport != null">#{machineReport},</if><if test="screeningChildId != null">#{screeningChildId},</if><if test="phone != null">#{phone},</if><if test="type != null">#{type},</if></trim>
</insert>