mybatis映射文件使用Map

  1. 映射文件对应的接口中,map 参数添加 @Param(“map”) 注解;
void addZdConfig(@Param("map") Map<String, String> rowMap, @Param("zdName") String zdName);
  1. 映射文件中使用 map :
<insert id="addZdConfig" parameterType="java.util.Map">
    insert into ${
    
    zdName}
    <foreach collection="map.entrySet()" index="key" item="value" open="(" close=")" separator=",">
        <if test="key != 'zdName'">
            ${
    
    key}
        </if>
    </foreach>
    values
    <foreach collection="map.entrySet()" index="key" item="value" open="(" close=")" separator=",">
        <if test="key != 'zdName'">
            #{
    
    value}
        </if>
    </foreach>
</insert>

猜你喜欢

转载自blog.csdn.net/qq_38152400/article/details/113307206