1.Mysql相关问题
1.1字段数组转字符串
group_concat(filed)
2.Mybatis相关问题
2.1.批量插入
使用foreach函数
INSERT INTO am_devtype_cloudI ( filed1, filed2 ) VALUES <foreach collection="list" item="item" index="index" separator=","> ( #{item.filed1}, #{item.filed2} ) </foreach>foreach元素的属性主要有 item,index,collection,open,separator,close。
- item表示集合中每一个元素进行迭代时的别名,
- index指定一个名字,用于表示在迭代过程中,每次迭代到的位置,
- open表示该语句以什么开始,
- separator表示在每次进行迭代之间以什么符号作为分隔符,
- close表示以什么结束
2.2插入数据库后返回自增长主键信息
在insert结构中添加两个参数:
useGeneratedKeys="true"表示给主键设置自增长
keyProperty="id"表示数据插入数据库后产生的自增长id赋值给实体对象的id字段
parameterType传参应该为实体类
<insert id="addRelation" useGeneratedKeys="true" keyProperty="id" parameterType
待续....