此SqlMap中没有名为UserEntity.insertUser的语句

时间:2015-06-26 02:26:23

标签: mybatis

我想从mybatis开始。我做了所有的配置但是当我想测试与数据库的连接时我有错误在这个SqlMap中没有名为UserEntity.insertUser的语句。

confif文件

width:66%

sql mapper

 <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE configuration  
                PUBLIC "-//mybatis.org//DTD Config 3.0//EN"  
                "http://mybatis.org/dtd/mybatis-3-config.dtd">

        <configuration>  
                <settings>  
                    <!-- changes from the defaults -->  
                    <setting name="lazyLoadingEnabled" value="false" />  
                </settings>  
                <typeAliases>  
                    <typeAlias alias="User" type="com.hosto.Entity"/>  
                </typeAliases>  
                <environments default="development">  
                    <environment id="development">  
                        <transactionManager type="JDBC"/>  
                        <dataSource type="POOLED">  
                            <property name="driver" value="com.mysql.jdbc.Driver"/>  
                            <property name="url" value="jdbc:mysql://localhost:3306/hospidigest"/>  
                            <property name="username" value="root"/>  
                            <property name="password" value=""/>  
                        </dataSource>  
                    </environment>  
                </environments>  
                <mappers>  
                    <mapper resource="com/hosto/mapper/UserMapper.xml"/>  
                </mappers>  
            </configuration>  

Mybatis Factory

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap  
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"  
        "http://mybatis.org/dtd/mybatis-3-config.dtd">

<sqlMap namespace="com.hosto.dao.UserDao">

<resultMap id="UserResult" class="User">

<result property="lastName" column="LASTNAME"/>
<result property="firstName" column="FIRSTNAME"/>
<result property="password" column="PASSWORD"/>
<result property="email" column="EMAIL"/>
<result property="month" column="MONTH"/>
<result property="day" column="DAY"/>   

<result property="year" column="YEAR"/>
<result property="prefixes" column="PREFIXE"/>
<result property="gender" column="GENDER"/>
<result property="personal" column="BASICPERSONNALINFORMATION"/>

</resultMap>
         <select id="getAllUsers" resultClass="java.util.ArrayList">
             SELECT * FROM user
         </select>
         <insert id="insertUser"  parameterType="com.hosto.Entity.User">
             INSERT INTO user (LASTNAME,FIRSTNAME,USERNAME,PASSWORD,EMAIL,MONTH,DAY,YEAR,PREFIXE,GENDER,BASICPERSONNALINFORMATION)
             VALUES (#{lastName},#{firstName},#{userName}, #{password}, #{email}, #{month}, #{day}, #{year}, #{prefixes}, #{gender},#{personal})
         </insert>
         <update id="updateUser" parameterClass="UserDaotest">
             UPDATE user SET
                 LASTNAME= #{lastName},
                 FIRSTNAME= #{firstName},
                 USERNAME= #{userName},
                 PASSWORD= #{password},
                 EMAIL= #{email},
                 MONTH= #{month},
                 DAY= #{day},
                 YEAR= #{year},
                 PREFIXE= #{prefixes},
                 GENDER= #{gender},
                 BASICPERSONNALINFORMATION= #{personal},
             WHERE ID = #{id}
        </update>
        <delete id="deleteUser"  parameterClass="int">
            DELETE  FROM user where 
              ID = #{id}
        </delete>
        <select id="getUserById" resultClass="UserInterface" parameterClass="int">  
            SELECT *  
                FROM user  
            WHERE ID= #{id}  
       </select> 
</sqlMap>

用户Dao

package com.hosto.daoconfig;
import java.io.IOException;

import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;


public class MyBatisConnectionFactory {

    private static SqlSessionFactory sqlSessionFactory; 

    private static SqlMapClient sqlMapClient = null;

    public static SqlMapClient getSqlMapClient()  {
            try {
            String resource = "SqlMapConfig.xml";
            Reader reader = Resources.getResourceAsReader(resource);
            sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
            reader.close();

            }
            catch (IOException iOException) {
            iOException.printStackTrace();
            }
            return sqlMapClient;
     }

}

1 个答案:

答案 0 :(得分:0)

它告诉你它没有定义,你需要创建一个。

查看example herehere