junit 单元测试 insert到数据库时候,mapper.xml文件插入不进去

大東9_9 2017-07-12 09:35:36
[org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
[org.springframework.jdbc.support.SQLErrorCodesFactory] - SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
[org.springframework.context.support.GenericApplicationContext] - Closing org.springframework.context.support.GenericApplicationContext@97e1986: startup date [Wed Jul 12 09:30:35 CST 2017]; root of context hierarchy
...全文
651 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
大東9_9 2017-07-12
  • 打赏
  • 举报
回复
这是配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> <!-- 自动扫描 --> <context:component-scan base-package="com.jinshao" /> <!-- 引入配置文件 --> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:jdbc.properties" /> </bean> <bean id="mysqltemp" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="${mysqltemp_driver}" /> <property name="url" value="${mysqltemp_url}" /> <property name="username" value="${mysqltemp_username}" /> <property name="password" value="${mysqltemp_password}" /> <!-- 初始化连接大小 --> <property name="initialSize" value="${initialSize}"></property> <!-- 连接池最大数量 --> <property name="maxActive" value="${maxActive}"></property> <!-- 连接池最大空闲 --> <property name="maxIdle" value="${maxIdle}"></property> <!-- 连接池最小空闲 --> <property name="minIdle" value="${minIdle}"></property> <!-- 获取连接最大等待时间 --> <property name="maxWait" value="${maxWait}"></property> </bean> <bean id="mysql" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="${mysql_driver}" /> <property name="url" value="${mysql_url}" /> <property name="username" value="${mysql_username}" /> <property name="password" value="${mysql_password}" /> <!-- 初始化连接大小 --> <property name="initialSize" value="${initialSize}"></property> <!-- 连接池最大数量 --> <property name="maxActive" value="${maxActive}"></property> <!-- 连接池最大空闲 --> <property name="maxIdle" value="${maxIdle}"></property> <!-- 连接池最小空闲 --> <property name="minIdle" value="${minIdle}"></property> <!-- 获取连接最大等待时间 --> <property name="maxWait" value="${maxWait}"></property> </bean> <bean id="oracle" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="${ora_driver}" /> <property name="url" value="${ora_url}" /> <property name="username" value="${ora_username}" /> <property name="password" value="${ora_password}" /> <!-- 初始化连接大小 --> <property name="initialSize" value="${initialSize}"></property> <!-- 连接池最大数量 --> <property name="maxActive" value="${maxActive}"></property> <!-- 连接池最大空闲 --> <property name="maxIdle" value="${maxIdle}"></property> <!-- 连接池最小空闲 --> <property name="minIdle" value="${minIdle}"></property> <!-- 获取连接最大等待时间 --> <property name="maxWait" value="${maxWait}"></property> </bean> <!-- 动态配置数据源 --> <bean id ="dataSource" class= "com.jinshao.util.DynamicDataSource" > <property name ="targetDataSources"> <map key-type ="java.lang.String"> <entry value-ref ="mysqltemp" key="mysqltemp"></entry > <entry value-ref ="mysql" key= "mysql"></entry > <entry value-ref ="oracle" key= "oracle"></entry > </map > </property > <property name ="defaultTargetDataSource" ref= "mysql"></property > <!-- 默认使用oracle的数据源 --> </bean > <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <!-- 自动扫描mapping.xml文件 --> <property name="mapperLocations" value="classpath:mybabitsmap/*.xml"></property> <!-- 分页插件设置 --> <property name="plugins"> <array> <bean class="com.github.pagehelper.PageHelper"> <property name="properties"> <value> dialect=mysql reasonable=true pageSizeZero=true </value> </property> </bean> </array> </property> </bean> <!-- DAO接口所在包名,Spring会自动查找其下的类 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.jinshao.dao" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean> <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> </beans>
大東9_9 2017-07-12
  • 打赏
  • 举报
回复
引用 4 楼 minemine0418 的回复:
[quote=引用 1 楼 yu__chen 的回复:] <insert id="insert" parameterType="com.jinshao.entity.Achievement" > insert into zc_achievement (user_id, xn, xq, col01, col02, col03) values (#{userId,jdbcType=VARCHAR}, #{xn,jdbcType=VARCHAR}, #{xq,jdbcType=INTEGER}, #{col01,jdbcType=DOUBLE}, #{col02,jdbcType=DOUBLE}, #{col03,jdbcType=DOUBLE}) </insert>
可以用if标签[/quote] 这是要插入的 com.jinshao.entity.Achievement的 tostring()结果 Achievement [id=null, createBy=null, createDate=null, updateBy=null, updateDate=null, remark=null, delFlag=null, userId=092815110, xn=2016-2017, xq=0, total=null, bjsort=null, col01=11.111, col02=22.222, col03=33.333, col04=null, col05=null, col06=null, col07=null, col08=null, col09=null, col10=null, col11=null, col12=null, col13=null, col14=null, col15=null, col16=null, col17=null, col18=null] 改用了if,还是同样的错误[org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml] [org.springframework.jdbc.support.SQLErrorCodesFactory] - SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase] [org.springframework.context.support.GenericApplicationContext] - Closing org.springframework.context.support.GenericApplicationContext@97e1986: startup date [Wed Jul 12 10:19:42 CST 2017]; root of context hierarchy <insert id="insertSelective" parameterType="com.jinshao.entity.Achievement" > insert into zc_achievement <trim prefix="(" suffix=")" suffixOverrides="," > <if test="id != null" > id, </if> <if test="createBy != null" > create_by, </if> <if test="createDate != null" > create_date, </if> <if test="updateBy != null" > update_by, </if> <if test="updateDate != null" > update_date, </if> <if test="remark != null" > remark, </if> <if test="delFlag != null" > del_flag, </if> <if test="userId != null" > user_id, </if> <if test="xn != null" > xn, </if> <if test="xq != null" > xq, </if> <if test="total != null" > total, </if> <if test="bjsort != null" > bjsort, </if> <if test="col01 != null" > col01, </if> <if test="col02 != null" > col02, </if> <if test="col03 != null" > col03, </if> <if test="col04 != null" > col04, </if> <if test="col05 != null" > col05, </if> <if test="col06 != null" > col06, </if> <if test="col07 != null" > col07, </if> <if test="col08 != null" > col08, </if> <if test="col09 != null" > col09, </if> <if test="col10 != null" > col10, </if> <if test="col11 != null" > col11, </if> <if test="col12 != null" > col12, </if> <if test="col13 != null" > col13, </if> <if test="col14 != null" > col14, </if> <if test="col15 != null" > col15, </if> <if test="col16 != null" > col16, </if> <if test="col17 != null" > col17, </if> <if test="col18 != null" > col18, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides="," > <if test="id != null" > #{id,jdbcType=VARCHAR}, </if> <if test="createBy != null" > #{createBy,jdbcType=VARCHAR}, </if> <if test="createDate != null" > #{createDate,jdbcType=TIMESTAMP}, </if> <if test="updateBy != null" > #{updateBy,jdbcType=VARCHAR}, </if> <if test="updateDate != null" > #{updateDate,jdbcType=TIMESTAMP}, </if> <if test="remark != null" > #{remark,jdbcType=VARCHAR}, </if> <if test="delFlag != null" > #{delFlag,jdbcType=CHAR}, </if> <if test="userId != null" > #{userId,jdbcType=VARCHAR}, </if> <if test="xn != null" > #{xn,jdbcType=VARCHAR}, </if> <if test="xq != null" > #{xq,jdbcType=INTEGER}, </if> <if test="total != null" > #{total,jdbcType=DOUBLE}, </if> <if test="bjsort != null" > #{bjsort,jdbcType=INTEGER}, </if> <if test="col01 != null" > #{col01,jdbcType=DOUBLE}, </if> <if test="col02 != null" > #{col02,jdbcType=DOUBLE}, </if> <if test="col03 != null" > #{col03,jdbcType=DOUBLE}, </if> <if test="col04 != null" > #{col04,jdbcType=DOUBLE}, </if> <if test="col05 != null" > #{col05,jdbcType=DOUBLE}, </if> <if test="col06 != null" > #{col06,jdbcType=DOUBLE}, </if> <if test="col07 != null" > #{col07,jdbcType=DOUBLE}, </if> <if test="col08 != null" > #{col08,jdbcType=DOUBLE}, </if> <if test="col09 != null" > #{col09,jdbcType=DOUBLE}, </if> <if test="col10 != null" > #{col10,jdbcType=DOUBLE}, </if> <if test="col11 != null" > #{col11,jdbcType=DOUBLE}, </if> <if test="col12 != null" > #{col12,jdbcType=DOUBLE}, </if> <if test="col13 != null" > #{col13,jdbcType=DOUBLE}, </if> <if test="col14 != null" > #{col14,jdbcType=DOUBLE}, </if> <if test="col15 != null" > #{col15,jdbcType=DOUBLE}, </if> <if test="col16 != null" > #{col16,jdbcType=DOUBLE}, </if> <if test="col17 != null" > #{col17,jdbcType=DOUBLE}, </if> <if test="col18 != null" > #{col18,jdbcType=DOUBLE}, </if> </trim> </insert>
大東9_9 2017-07-12
  • 打赏
  • 举报
回复
配置文件没问题的,别的插入都可以
minemine0418 2017-07-12
  • 打赏
  • 举报
回复
引用 1 楼 yu__chen 的回复:
<insert id="insert" parameterType="com.jinshao.entity.Achievement" > insert into zc_achievement (user_id, xn, xq, col01, col02, col03) values (#{userId,jdbcType=VARCHAR}, #{xn,jdbcType=VARCHAR}, #{xq,jdbcType=INTEGER}, #{col01,jdbcType=DOUBLE}, #{col02,jdbcType=DOUBLE}, #{col03,jdbcType=DOUBLE}) </insert>
可以用if标签
minemine0418 2017-07-12
  • 打赏
  • 举报
回复
引用 1 楼 yu__chen 的回复:
<insert id="insert" parameterType="com.jinshao.entity.Achievement" > insert into zc_achievement (user_id, xn, xq, col01, col02, col03) values (#{userId,jdbcType=VARCHAR}, #{xn,jdbcType=VARCHAR}, #{xq,jdbcType=INTEGER}, #{col01,jdbcType=DOUBLE}, #{col02,jdbcType=DOUBLE}, #{col03,jdbcType=DOUBLE}) </insert>
应该是配置文件的问题吧。都贴出来看看
大東9_9 2017-07-12
  • 打赏
  • 举报
回复
com.jinshao.entity.Achievement 属性太多了,没有完全插入,只是插入部分!
大東9_9 2017-07-12
  • 打赏
  • 举报
回复
<insert id="insert" parameterType="com.jinshao.entity.Achievement" > insert into zc_achievement (user_id, xn, xq, col01, col02, col03) values (#{userId,jdbcType=VARCHAR}, #{xn,jdbcType=VARCHAR}, #{xq,jdbcType=INTEGER}, #{col01,jdbcType=DOUBLE}, #{col02,jdbcType=DOUBLE}, #{col03,jdbcType=DOUBLE}) </insert>

50,544

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧