MyBatis: 通过注解中写入数据并从数据库获得自增主键、动态SQL写入List类型的数据、动态SQL查询数据

一、通过使用@Options注解,将数据库的自增字段id中的值写到eemLeader对象的id字段,之后在其他地方使用

 @Options(useGeneratedKeys = true, keyColumn = "id" , keyProperty = "id")
    @Insert("insert into eem_leader(code,dept_id,name,gender,birthday,nation,politics_status,education,hire_date,working_state," +
            "del_flag,create_by,create_time,update_by,update_time,remark) " +
            "values(#{code},#{deptId},#{name},#{gender},#{birthday},#{nation},#{politicsStatus},#{education},#{hireDate},#{workingState}," +
            "#{delFlag},#{createBy},null,null,null,remark)")
    int addLeaderBasicInfo(EemLeader eemLeader);
   

二、通过动态SQL写入List类型的数据

 @Insert("")
    int addLeaderDutyInfo(@Param("leaderId") long leaderId,@Param("eemLeaderDutyList") List<EemLeaderDuty> eemLeaderDutyList);

三、通过动态SQL查询数据

    @Select("")
    List<Map<String,Object>> getLeaderListByQueryCondition(QueryCondition queryCondition);

你可能感兴趣的:(SpringBoot,MyBatis,数据库,sql,database)