本人现在有一个List>集合,里面类容是
[{area=A17, floors=A18, unitname=A13, unitid=1, address=A15, branchid=A11, unitproperty=A16, hight=A19, master=A14, policeid=A12}, {area=A27, floors=A28, unitname=A23, unitid=2, address=A25, branchid=A21, unitproperty=A26, hight=A29, master=A24, policeid=A22}] 本人现在需要将它插入到数据库,其中unitid为主键, 本人是用springMVC+mybatis来完成的。 问一下这个应该怎么操作呢?
解决方案
2
相当于你是要搭建一个springMVC+mybatis的项目(自然还有spring),这个还比较复杂,不是三言两语能说清楚的,建议你去找找相关博客。
参考:SSM框架——详细整合教程(Spring+SpringMVC+MyBatis) – AndyLizh的专栏 – 博客频道 – CSDN.NET http://blog.csdn.net/gebitan505/article/details/44455235
3
最直接的,把这些值取出来拼sql语句
5
Mapper里面用 foreach标签遍历插入
30
这个的parameterType=“hashmap”或map,
insert into table(表名)
area, floors, unitname, unitid, address, branchid, unitproperty, hight, master, policeid
#{area}, #{floors}, #{unitname}, #{unitid}, #{address}, #{branchid}, #{unitproperty}, #{hight}, #{master}, #{policeid}
CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明mybatis插入List集合的值到MySQL数据库中!