天天看点

mybatis 在mysql上数据不能insert

这是XsglService

//加入一个学生
    public String add(XsxxModel xs)
    {
        String result="suc";
        SqlSession session = Util.getSqlSessionFactory().openSession();  
        try{
            int a=session.insert("XxwhMapper.insertstu",xs);
     //       session.commit();  
            System.out.println("插入"+a+"个学生");
        }
        catch(Exception e){
            result="fail";
            e.printStackTrace();
        }
        finally{
             session.close();  
        }
        return result;    
    }      

这是configuration

<?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>  

    <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/webexample?useUnicode=true&characterEncoding=UTF-8" />
<property name="username" value="root" />
<property name="password" value="" /> 
            </dataSource>    
        </environment>       
    </environments>    
    <mappers>    
        <mapper resource="Mapper/XxwhMapper.xml"/>    
    </mappers>  

</configuration>      

这是XxwhMapper

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
<mapper namespace="XxwhMapper">

   <!-- 原先insert的数值对应有问题  现已经修改 -->
    <insert id="insertstu" parameterType="Model.XsxxModel">
        INSERT INTO
            xsxxb 
            (name,xh,xy,mima)                     
         VALUES (
                #{name,jdbcType=VARCHAR},
                #{xh,jdbcType=VARCHAR},
                #{xy,jdbcType=VARCHAR},
                #{mima,jdbcType=VARCHAR}
            );
    </insert>
 </mapper>