mybatis嵌套map或者map嵌套的parameterType

Spring的重要注解

https://www.cnblogs.com/rolandlee/p/11014923.html

一:首先是map嵌套:

例1:

 

例2:

总结:

paramterType无论是MAP或者是map嵌套的类型都可以,只是在取得参数时的层次不同而已:

 

 <foreach collection="batchStatus" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>

 

二:list嵌套MAP

sevice:

List<Map<String, Object>> device = new ArrayList<>();
for (int i = 0; i < 2 ; i++) {
Map<String, Object> map = new HashMap<>();
map.put("deviceName", "摄像头");
map.put("logicId", 1 + i);
device.add(map);
}
List<DeviceDetail> list = deviceDetailMapper.selectByNameLogicId(device);

 

dao:

List<DeviceDetail> selectByNameLogicId(List<Map<String, Object>> device);

对应的mapper.xml:

<select id="selectByNameLogicId" parameterType="java.util.ArrayList" resultType="DeviceDetail">
    select * from device_detail
    <where>
        (device_name,logic_id) in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            (#{item.deviceName},#{item.logicId})
        </foreach>
    </where>
</select>

 

 https://blog.csdn.net/sjmuvx/article/details/79495900

mybatis的parameterType使用map实现真正的sql随意写

https://www.cnblogs.com/YingYue/p/4126231.html 

 

posted @ 2019-06-14 16:35  不死码农  阅读(4081)  评论(0编辑  收藏  举报