mybatis插入date类型数据错误.

m0_37536978 2017-03-03 10:51:13
求教各位大神.实体类date数据插入mySql date类型字段一直报错该如何解决.
(添加语句我将jdbcType=DATE 去掉也是报错,将上面javaType="java.util.Date" 改为java.sql.Date 也不行, 请问该如何解决)
这是xml 配置.

<mapper namespace="u">
<resultMap type="useres" id="useresResultMap">
<id column="user_id" property="userId" />
<result column="user_name" property="userName"/>
<result column="user_phone" property="userPhone"/>
<result column="user_level" property="userLevel"/>
<result column="user_startdate" property="userStartDate" jdbcType="DATE" javaType="java.util.Date"/>
<collection property="roleList" column="user_id" ofType="roles" select="getRolesById"></collection>

</resultMap>


实体类属性 userStartDate 是 Date 类型的,数据库 user_startDate 是Date 类型的.
我在添加一条数据时一直报错,这是插入语句

<insert id="addUser" parameterType="useres">
insert into useres (user_name,user_phone,user_level,user_startdate) values (#{userName},#{userPhone},#{userLevel},#{userStartDate})
</insert>


这是错误提示:

严重: Servlet.service() for servlet dispatcherServlet threw exception
org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'useres' on field 'userStartDate': rejected value [2017-03-16]; codes [typeMismatch.useres.userStartDate,typeMismatch.userStartDate,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [useres.userStartDate,userStartDate]; arguments []; default message [userStartDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'userStartDate'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'userStartDate': no matching editors or conversion strategy found]
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doBind(HandlerMethodInvoker.java:749)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:296)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:163)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
...全文
626 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
weare微儿 2017-03-03
  • 打赏
  • 举报
回复
你传的是string类型的,当然不匹配了 Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'userStartDate': no matching editors or conversion strategy found] www.weare.net.cn
lc黑 2017-03-03
  • 打赏
  • 举报
回复
建议把实体类贴出来

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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