纠结了好一阵子, 最终给我解决了。

直接上代码了:

mapper文件:

	<insert >
		INSERT INTO blog (user_id, blog_id) VALUES
		<foreach collection="blogs" item="blog" separator=",">
		(#{userId}, #{blog})
		</foreach>
	</insert>

java代码:

        public void saveBlogs(Integer userId, List
  
    blogs) {
                Map
   
     param = new HashMap
    
     ();
                param.put("userId", userId);
                param.put("blogs", blogs);
                getSqlSession().insert("Blog.saveBlogs", blogs);
        }

    
   
  

<forEach/>的collection属性填map参数里的key, 不要用list、array等关键字。。

相关文章:

  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
  • 2022-02-28
  • 2022-01-16
  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-12
相关资源
相似解决方案