1.批量新增,参数为List<Map>:

<insert id="insertAreaVehicle" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
INSERT INTO tr_area_vehicle
(id,area_id,vid)
VALUES
<foreach collection="list" item="item" separator=",">
(#{item.id}, #{item.areaId}, #{item.vehicleId})
</foreach>
</insert>

2.查询或修改,希望改动满足某一个字段的多个值得情况:

<delete id="deleteAreaVehicle">
delete from tr_area_vehicle
where find_in_set(area_id,#{areaIdsArr})
</delete>

   使用find_in_set, 参数为逗号分隔的字符串

3.大于等于

第一种写法(1):
  
  原符号       <        <=      >       >=       &        '        "
  替换符号    &lt;    &lt;=   &gt;    &gt;=   &amp;   &apos;  &quot;
  例如:sql如下:
  create_date_time &gt;= #{startTime} and  create_date_time &lt;= #{endTime}
  
  第二种写法(2):
  大于等于
  <![CDATA[ >= ]]>
  小于等于
  <![CDATA[ <= ]]>
  例如:sql如下:
  create_date_time <![CDATA[ >= ]]> #{startTime} and  create_date_time <![CDATA[ <= ]]> #{endTime}

4. 模糊查询


   <if test="name != null and name != ''"> AND name LIKE  '%${name}%'  </if>

  

5.使用到实体类

  在mybatis配置文件中用到了SysUser实体类,但没有配置或引入这个实体类,这时会报错。

  解决方案:在mybatis-config中加入配置,写上实体类地址:

mybatis.typeAliasesPackage=com.sinoiov.etims.haikwanQingDao.entity

6.批量update操作
 使用foreach批量update报错:sql injection violation, multi-statement not allow 

 错误信息说明不允许批量语句.

 解决方案:在数据库地址url后加参数:

?allowMultiQueries=true

 同时去掉

spring.datasource.filters=wall配置。到此已解决。

网上还有的解决方案是修改wall配置(在wall必须使用的情况下):

@Bean(name = "wallFilter")
@DependsOn("wallConfig")
public WallFilter wallFilter(WallConfig wallConfig){
WallFilter wallFilter = new WallFilter();
wallFilter.setConfig(wallConfig);
return wallFilter;
}

@Bean(name = "wallConfig")
public WallConfig wallConfig(){
WallConfig wallConfig = new WallConfig();
wallConfig.setMultiStatementAllow(true);//允许一次执行多条语句
wallConfig.setNoneBaseStatementAllow(true);//允许一次执行多条语句
return wallConfig;
}