问题描述
数据获取都是正确的,就是数据插不进表,麻烦各位帮忙看看!/* * 插入 */@Testpublic void testInsertBlog() throws Exception{BlogMapper mapper = openSession().getMapper(BlogMapper.class); Blog b=new Blog(); b.setTitle("title2"); b.setContent("content2"); b.setCreateDate(new Date()); mapper.insertBlog(b); sessionClose() ;}BlogMapper.xml<?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.tony.mybatis.mapper.BlogMapper"> <resultMap type="com.tony.model.Blog" id="blog"> <!--column数据库要查询的字段 property对应java文件的字段名--> <result column="create_date" jdbcType="TIMESTAMP" property="createDate" javaType="java.util.Date"/> </resultMap> <insert id="insertBlog" parameterType="com.tony.model.Blog" > insert into t_blog (title,content,create_date) values (#{title},#{content},#{createDate, jdbcType=TIMESTAMP}); </insert></mapper>后台显示log:DEBUG - ==> Preparing: insert into t_blog (title,content,create_date) values (?,?,?); DEBUG - ==> Parameters: title2(String), content2(String), 2013-07-27 17:30:37.877(Timestamp)在表定义里面我把表的create_date定义成Timestamp类型是不是xml映射的时候date类型有什么配置我没有做。 问题补充:config.xml:<?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/mybatis_test"/> <property name="username" value="root"/> <property name="password" value="huhuawen@"/> </dataSource> </environment> </environments> <mappers> <mapper resource="com/tony/mybatis/BlogMapper.xml"/> </mappers></configuration>
解决方案
没有事务吧
解决方案二:
你的mybatis 的映射配置文件呢?????