Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 将列表插入单独的表MYBATIS_Spring_Mybatis - Fatal编程技术网

Spring 将列表插入单独的表MYBATIS

Spring 将列表插入单独的表MYBATIS,spring,mybatis,Spring,Mybatis,我需要帮助插入以下数据到数据库 我有两张表,分别是employee和employee_skills (1名员工可以具备多种技能) mapper.xml <insert id='addEmp1' parameterType='Employee' useGeneratedKeys='true '> INSERT INTO "PUBLIC"."EMPLOYEE"("ADDRESS", "AGE", "CITY", "DEPT", "FNAME","LNAME", "

我需要帮助插入以下数据到数据库 我有两张表,分别是employee和employee_skills (1名员工可以具备多种技能)

mapper.xml

<insert id='addEmp1' parameterType='Employee'
    useGeneratedKeys='true '>
    INSERT INTO "PUBLIC"."EMPLOYEE"("ADDRESS", "AGE", "CITY", "DEPT",
    "FNAME","LNAME", "SALARY", "STATE")
    values(#{address},#{age},#{city},#{dept},#{fname},#{lname},#{salary},#{state});

</insert>

这似乎不起作用我是mybatis的新手请帮助

如果使用
SqlSession
,则必须将xml中指定的名称空间和查询id组合起来。
请参阅。

生成的sql不正确。有关插入列表的答案,请参见。
<insert id='addskills' parameterType='Employee'
    useGeneratedKeys='true '>
    INSERT INTO "PUBLIC"."EMPLOYEE_SKILLS"
    ( "EMPLOYEE_E_ID", "SKILLS" )
    VALUES (
    <foreach collection="skills" item="skill" separator=",">
        #{id},#{employee.skills}</foreach>)
     </insert>
    SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
      try{
      EmployeeDAO userMapper = sqlSession.getMapper(EmployeeDAO.class);                                        //sqlSession.getMapper(UserMapper.class);
      // userMapper.addEmp(employee);                                                                       //userMapper.insertUser(employee);
    sqlSession.insert("addEmp1",employee);
    sqlSession.insert("addskill",employee);

      sqlSession.commit();
      }finally{
       sqlSession.close();
      }