简体   繁体   English

插入带有MyBatis批注的对象列表

[英]Insert list of objects with MyBatis annotation

I know how to insert list of values with xml config mapper, but I want to do it with annotation. 我知道如何使用xml config映射器插入值列表,但是我想通过注释来完成。

Something like this, but working 这样的东西,但工作

@Insert("insert into  tableName (param1, param2) values (#{obj1.param1}, #{obj1.param2})")
void insert(@Param("obj1") List<MyObject> obj1);

I guess in XML you do it with foreach , then it is the same in annotation, just surround with <script> tags. 我猜在XML中,您可以使用foreach ,然后在注释中也是如此,只是用<script>标记包围。

@Insert({"<script>", 
         "insert into  tableName (param1, param2) values ", 
         "<foreach collection='obj1' item='o' separator = ', ' open ="(" close=")" >#{o}</foreach>",
         "</script>"})
void insert(@Param("obj1") List<MyObject> obj1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM