为什么时间老插入不了数据路啊?
public void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String account = request.getParameter("account"); String name = request.getParameter("name"); String sex = request.getParameter("sex"); String idNumber = request.getParameter("idNumber"); String info = request.getParameter("info"); Date bornDate = null; try { bornDate = new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("bornDate")); } catch (ParseException e) { e.printStackTrace(); } Integer did = Integer.parseInt(request.getParameter("did")); Staff staff = new Staff(); staff.setAccount(account); staff.setName(name); staff.setSex(sex); staff.setIdNumber(idNumber); staff.setInfo(info); staff.setBornDate(bornDate); staff.setDid(did); staffService.add(staff); response.sendRedirect("list.do"); }
这里Entity和Controller里的时间类型也都是java.util.Date类的呀,而且ResultMap定义的时候也指定了类型,打断点看这里是有值的,也没有异常。为什么插到数据库里就是null呢?
1
收起
正在回答
4回答
<result property="bornTime" column="born_time" javaType="java.util.Date"/>
这一句写错了,应该改成:
<result property="bornDate" column="born_date" javaType="java.util.Date"/>
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
渐丶忘
2018-11-08 10:03:58
<?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.imooc.sm.dao.StaffDAO"> <resultMap id="resultMap" type="Staff"> <id property="id" column="id" javaType="Integer"/> <result property="account" column="account" javaType="String"/> <result property="password" column="password" javaType="String"/> <result property="status" column="status" javaType="String"/> <result property="did" column="did" javaType="Integer"/> <result property="name" column="name" javaType="String"/> <result property="sex" column="sex" javaType="String"/> <result property="idNumber" column="id_number" javaType="String"/> <result property="workTime" column="work_time" javaType="java.util.Date"/> <result property="leaveTime" column="leave_time" javaType="java.util.Date"/> <result property="bornTime" column="born_time" javaType="java.util.Date"/> <result property="info" column="info" javaType="String"/> <association property="department" column="did" javaType="Department" select="com.imooc.sm.dao.DepartmentDAO.selectById"/> </resultMap> <insert id="insert" useGeneratedKeys="true" parameterType="Staff"> insert into staff(account, password, status, did, name, sex, id_number, work_time, leave_time, born_date, info) values (#{account},#{password},#{status},#{did},#{name},#{sex},#{idNumber},#{workTime},#{leaveTime},#{bornDate},#{info}) </insert> <update id="update" parameterType="Staff"> update staff set account=#{account},password=#{password},status=#{status},did=#{did}, name=#{name},sex=#{sex},id_number=#{idNumber},work_time=#{workTime}, leave_time=#{leaveTime},born_date=#{bornDate},info=#{info} where id=#{id} </update> <delete id="delete" parameterType="Integer"> delete from staff where id=#{id} </delete> <select id="selectById" parameterType="Integer" resultMap="resultMap"> select * from staff where id=#{id} </select> <select id="selectAll" resultMap="resultMap"> select * from staff </select> </mapper>
SSM主流框架入门与综合项目实战2018版
- 参与学习 人
- 提交作业 205 份
- 解答问题 4317 个
Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星