方法一:

在实体类里面将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. day07补充-数据类型总结及拷贝

    目录 数据类型总结 按照存一个值 OR 多个值来分 按照有序 OR 无序来分 按照可变 OR 不可变来分 拷贝 && 浅拷贝 && 深拷贝&& .cop ...

  2. php省市区三级联动

    效果 步骤 前端:通过ajax请求获取数据,使用了jquery 页面一开始加载所有省份信息 ->当选择省下拉框后触发改变监听时间-change ->当选择市下拉框后触发改变监听时间-cha ...

  3. C#基础速学

    原文地址 https://www.cnblogs.com/younShieh/p/10945264.html     前几天在刷即刻的时候发现了一个GitHub上的项目,该项目名为“learn x i ...

  4. SGU100

    Read integers A and B from input file and write their sum in output file. Input Input file contains ...

  5. SSH技术介绍和Xshell公钥远程登陆

    SSH简介 传统的网络服务程序,比如FTP,POP,Telnet,本质上都是不安全的,因为它们在网络上用明文传送数据.用户账号和用户口令,很容易受到中间人攻击方式的攻击,攻击者会冒充真正的服务器接收用 ...

  6. time库

    简介 返回系统当前时间戳(正常的生活时间) 返回格林威治时间戳对应的struct_time对象 本地时间的struct_time对象 当前时间戳对应的易读格式字符串时间(周几,月份,号数,时,分,秒, ...

  7. post and get

    POST和GET是Web编程中的两个术语,他们是通过URI访问resource的两种方式.简单的说, GET 是把要访问的资源嵌入在URI中. 假设你在一个页面 http://www.myphone. ...

  8. Kotlin和Java名称的由来

    Kotlin和Java名称的由来 学习了:http://blog.jobbole.com/111249/ JetBrains由战斗民族开发: Java来源于印尼群岛中的Java岛: Kotlin来源于 ...

  9. 微信的token验证

    微信的token验证 在微信公众平台的基本配置中,需要输入token,这个token不是那个access_token springmvc验证代码: @RequestMapping(value=&quo ...

  10. Java 两个整数相除保留两位小数,将小数转化为百分数

    Java 两个整数相除保留两位小数,将小数转化为百分数 源于:http://blog.sina.com.cn/s/blog_624d755d0101cvuq.html 后来学习了:http://blo ...