这是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>



以上的代码在oracle中是完全能通过的但是在mysql中,insert的情况是不报错,每次也都会显示插入一个学生 但是在数据库中就是没有记录

经过请教师兄,才发现在oracle中每次操作不需要都提交 而在mysql中进行insert或update后必须提交 也就是说session.commit必须要有