SQL语句编写

mybatis插入数据

  • 下面的item.avatarUrl取出的是java实体类里面的属性,所有需要大写
  • 插入的SQL:
INSERT  INTO `one` VALUES(1,"第一个","123"),(2,"第二个","123");
点击查看代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mapper.SysUserMapper">
    <insert id="insertImportFile" parameterType="list">
        insert into `sys_user`(username,password,nickname,email,phone,address,avatar_url) values
        <foreach collection="sysUsers" item="item"  separator=",">
            (#{item.username},#{item.password},#{item.nickname}
            ,#{item.email},#{item.phone},#{item.address},#{item.avatarUrl})
        </foreach>
    </insert>
</mapper>

posted @ 2022-04-30 12:35  雨同我  阅读(139)  评论(0编辑  收藏  举报