[Mybatis] SpringBoot -mybatis 常用mysql数据库交互
2021/6/9 19:25:48
本文主要是介绍[Mybatis] SpringBoot -mybatis 常用mysql数据库交互,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
返回主键ID<insert id="insertSelective" parameterType="cn.showclear.utio.plan.pojo.plan.PlanDeGroup" useGeneratedKeys="true" keyProperty="groupId"> insert into T_PLAN_DE_GROUP ... </insert>自定义构造对象返回
<!--预案组对象--> <resultMap id="PlanGroupVOResultMap" type="cn.showclear.utio.plan.pojo.plan.PlanDeGroup" > <id column="group_id" jdbcType="INTEGER" property="groupId" javaType="java.lang.Integer" /> <result column="group_name" jdbcType="VARCHAR" property="groupName" javaType="java.lang.String" /> <result column="group_work_scope" jdbcType="VARCHAR" property="groupWorkScope" javaType="java.lang.String" /> <result column="is_delete" jdbcType="TINYINT" property="isDelete" javaType="java.lang.Byte" /> <result column="gmt_create" jdbcType="TIMESTAMP" property="gmtCreate" javaType="java.util.Date" /> <result column="gmt_update" jdbcType="TIMESTAMP" property="gmtUpdate" javaType="java.util.Date" /> <result column="plan_id" jdbcType="INTEGER" property="planId" javaType="java.lang.Integer" /> <result column="mem_ids" jdbcType="VARCHAR" property="memIds" javaType="java.lang.String" /> </resultMap> <!--查询预案组--> <select id="loadPlanGroupList" resultMap="PlanGroupVOResultMap"> SELECT pdg.*, GROUP_CONCAT(pdm.member_id) AS mem_ids FROM T_PLAN_DE_GROUP pdg LEFT JOIN T_PLAN_DE_MEMBER pdm ON pdg.group_id = pdm.group_id WHERE pdg.is_delete = 0 AND pdm.is_delete = 0 AND pdg.plan_id = #{planId,jdbcType=INTEGER} GROUP BY pdg.group_id </select>自定义参数
/** * 加载预案响应信息 * @param respLevel * @param planId * @return */ PlanDeRespone loadPlanRespBasicInfo(@Param("planId") Integer planId,@Param("respLevel") Byte respLevel);
<!--加载预案响应信息--> <!--自定义对象Map--> <resultMap id="PlanRespResultMap" type="cn.showclear.utio.plan.pojo.plan.PlanDeRespone" > <id column="resp_id" jdbcType="INTEGER" javaType="java.lang.Integer" property="respId"/> <result column="resp_name" jdbcType="VARCHAR" javaType="java.lang.String" property="respName"/> <result column="resp_level" jdbcType="TINYINT" javaType="java.lang.Byte" property="respLevel"/> <result column="resp_used_scope" jdbcType="VARCHAR" javaType="java.lang.String" property="respUsedScope"/> <result column="verify_userids" jdbcType="VARCHAR" javaType="java.lang.String" property="verifyUserids"/> <result column="is_delete" jdbcType="TINYINT" javaType="java.lang.Byte" property="isDelete"/> <result column="gmt_create" jdbcType="TIMESTAMP" javaType="java.util.Date" property="gmtCreate"/> <result column="gmt_update" jdbcType="TIMESTAMP" javaType="java.util.Date" property="gmtUpdate"/> <result column="plan_id" jdbcType="INTEGER" property="planId" javaType="java.lang.Integer" /> </resultMap> <select id="loadPlanRespBasicInfo" resultMap="PlanRespResultMap"> select * from T_PLAN_DE_RESPONE where plan_id = #{planId,jdbcType=INTEGER} AND resp_level = #{respLevel,jdbcType=TINYINT} AND is_delete = 0 </select>
报错:
Parameter ‘respLevel’ not found. Available parameters are [1, 0, param1, param2]
> 解决方法:
<select id="loadPlanRespBasicInfo" resultMap="PlanRespResultMap"> select * from T_PLAN_DE_RESPONE where plan_id = #{0} AND resp_level = #{1} AND is_delete = 0 </select>
>数字与传入参数的位置下标保持一致!for循环实现 IN(…)
> mapper层
/*** * 根据resIds字符串(逗号分隔)查询AmsvGeRes集合 * @param resIds * @return * @throws Exception */ List<AmsvGeRes> selectListByResIds(String[] resIds) throws Exception;
> mapper-sql层
<select id="selectListByResIds" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from T_GE_RES where res_id IN <foreach item="item" index="index" collection="array" open="(" separator="," close=")"> #{item} </foreach> </select>
这篇关于[Mybatis] SpringBoot -mybatis 常用mysql数据库交互的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南