方法一:

在实体类里面将set方法里面将数据类型转为Date

 public void setBirth(String birth) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
this.birth = sdf.parse(birth);
} catch (ParseException e) {
e.printStackTrace();
}
}

这样就可以了

注意在修改是判断是否为空的时候不能写birth!=“”,否则报java.util.Date and java.lang.String 的错

<if test="birth!= null">
birth = #{birth},
</if>

方法二:

实体类改为String类型,在xml里面改数据类型

<insert id="insert" parameterType="实体类">
INSERT INTO
table(id,idtype,idno,name,sex,phone,birth,nation,degree,native_type,native_place,address,first_job_year,emp_type,emp_form,start_date)
VALUES(#{id},#{idtype},#{idno},#{name},#{sex},#{phone},DATE_FORMAT(#{birth},'%Y-%m-%d'),#{nation},#{degree},#{nativeType},#{nativePlace},#{address},#{firstJobYear},#{empType},#{empForm},DATE_FORMAT(#{startDate},'%Y-%m-%d'))
</insert>-->
<update id="update" parameterType="实体类">
update table
<trim prefix="SET" suffixOverrides="," suffix="WHERE id = #{id}" >
<if test="idtype!= null and idtype != ''">
idtype = #{idtype},
</if>
<if test="idno!= null and idno != ''">
idno = #{idno},
</if>
<if test="name!= null and name != ''">
name = #{name},
</if>
<if test="sex!= null and sex != ''">
sex = #{sex},
</if>
<if test="phone!= null and phone != ''">
phone = #{phone},
</if>
<if test="birth!= null and birth != ''">
birth = DATE_FORMAT(#{birth},'%Y-%m-%d'),
</if>
<if test="nation != null and nation != ''">
nation = #{nation},
</if>
<if test="degree!= null and degree != ''">
degree = #{degree},
</if>
<if test="nativeType!= null and nativeType != ''">
native_type = #{nativeType},
</if>
<if test="nativePlace!= null and nativePlace != ''">
native_place = #{nativePlace},
</if>
<if test="address!= null and address != ''">
address = #{address},
</if>
<if test="firstJobYear!= null and firstJobYear != ''">
first_job_year = #{firstJobYear},
</if>
<if test="empType!= null and empType != ''">
emp_type = #{empType},
</if>
<if test="empForm!= null and empForm != ''">
emp_form = #{empForm},
</if>
<if test="startDate!= null and startDate != ''">
start_date = DATE_FORMAT(#{startDate},'%Y-%m-%d'),
</if>
</trim>
</update>

日期数据类型为Date ,前台传递喂String的后台处理的更多相关文章

  1. mybatis前台传来一个String,后后台执行sql变成了true

    实际上参数传来的是一个字符串 3 ,不知道为什么会变成true 最后当然是查不到信息了.. 我在mapper映射文件里面使用了动态的where查询,我觉得跟这个关系不太大, 现在不知道怎么办,希望有思 ...

  2. 日期控件传到后台异常。日期数据格式是 Date 还是 String?

    问题:日期控件的时间,传到Controller层直接异常. 前台日期格式:YYYY/MM/DD,后台Java定义的时间类型:Date. 解决: 方法一:原因是Controller层的参数类型定义为 D ...

  3. java日期类型转换总结date timestamp calendar string

    用Timestamp来记录日期时间还是很方便的,但有时候显示的时候是不需要小数位后面的毫秒的,这样就需要在转换为String时重新定义格式.         Timestamp转化为String: S ...

  4. Java 日期时间 Date类型,long类型,String类型表现形式的转换

    Java 日期时间 Date类型,long类型,String类型表现形式的转换 1.java.util.Date类型转换成long类型 java.util.Date dt = new Date(); ...

  5. Java 日期时间 Date类型,long类型,String类型表现形式的转换 (转)

    Java 日期时间 Date类型,long类型,String类型表现形式的转换 1.java.util.Date类型转换成long类型java.util.Date dt = new Date();Sy ...

  6. Java时间日期格式转换Date转String和String转Date

    Java时间格式转换大全 import java.text.*; import java.util.Calendar; public class VeDate { /** * 获取现在时间 * * @ ...

  7. Js数据类型之——Date

    小猪曾经分享过一篇文章,主要是讲到后台使用c#将DataTime类型序列化到前台之后进行操作:具体请看传送门 今天小猪来分享在JS中的Data类型 类型说明 ECMAScript中的Data类型是在早 ...

  8. sqlite3日期数据类型

    一.sqlite3日期数据类型,默认用datetime解析(根据stackflow) 使用时注意三点: 1. 创建表时,字段 DT 的类型为 date 2. 插入数据时,DT字段直接为 str 类型 ...

  9. java:常用类(包装类,equals和==的比较,Date,java.lang.String中常用方法,枚举enum)

    *包装类: 将基本类型封装成类,其中包含属性和方法以方便对象操作. *byte---->Byte *short--->Short *long--->Long *float---> ...

随机推荐

  1. Render2

    https://blog.csdn.net/wf19930209/article/details/81109388

  2. JSON,对象..的数据格式

    [此案例为自动产生的随机数] 对象: {a1:180,a2:721, a3:574} 序列化传值:将对象转化为Json字符串 public ActionResult Val2() { Random r ...

  3. CVPR 2017 Paper list

    CVPR2017 paper list Machine Learning 1 Spotlight 1-1A Exclusivity-Consistency Regularized Multi-View ...

  4. stress工具使用指南和结果分析

    stress介绍 #stress `stress' imposes certain types of compute stress on your system Usage: stress [OPTI ...

  5. 数据结构与算法(4) -- list、queue以及stack

    今天主要给大家介绍几种数据结构,这几种数据结构在实现原理上较为类似,我习惯称之为类list的容器.具体有list.stack以及queue. list的节点Node 首先介绍下node,也就是组成li ...

  6. MySQL中是索引

    MySQL中是索引: --.唯一索引: 一行中的内容不能一样, create t2( id int , num int, unique weiyisuiyin (id,num) ) --唯一; --约 ...

  7. Django cookie、session使用

    一.cookie Cookie是key-value结构,类似于一个python中的字典.随着服务器端的响应发送给客户端浏览器.然后客户端浏览器会把Cookie保存起来,当下一次再访问服务器时把Cook ...

  8. 【Codeforces 522A】Reposts

    [链接] 我是链接,点我呀:) [题意] 有人转载官方号的动态. 又有其他人转载其他人转载的动态. 问你最长的一条转载动态的链有多长. [题解] 用map把每个人的英文都转成小写的 然后从map中获取 ...

  9. Linux学习总结(3)——Linux实用工具

    1. Windows下同步Linux文件(Linux安装Samba和配置) 场景需求: 安装了Ubuntu在虚拟机上,但是代码编辑或者其它更多的操作的时候,还是习惯在windows下进行.如果wind ...

  10. 关于在JSP页面中为什么一定要用${pageContext.request.contextPath}来获取项目路径,而不能用${request.contextPath}?

    这里的疑问在于pageContext和request都是JSP中的内置对象之一,为什么不直接用${request.contextPath}来获取项目路径? 出现这种疑问,其实是将JSP的内置对象和EL ...