[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>
上一篇:pytorch查看模型文件的字典数据


下一篇:解决zookeeper集群重启 Error contacting service. It is probably not running 问题