日期数据类型为Date ,前台传递喂String的后台处理
方法一:
在实体类里面将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的后台处理的更多相关文章
- mybatis前台传来一个String,后后台执行sql变成了true
实际上参数传来的是一个字符串 3 ,不知道为什么会变成true 最后当然是查不到信息了.. 我在mapper映射文件里面使用了动态的where查询,我觉得跟这个关系不太大, 现在不知道怎么办,希望有思 ...
- 日期控件传到后台异常。日期数据格式是 Date 还是 String?
问题:日期控件的时间,传到Controller层直接异常. 前台日期格式:YYYY/MM/DD,后台Java定义的时间类型:Date. 解决: 方法一:原因是Controller层的参数类型定义为 D ...
- java日期类型转换总结date timestamp calendar string
用Timestamp来记录日期时间还是很方便的,但有时候显示的时候是不需要小数位后面的毫秒的,这样就需要在转换为String时重新定义格式. Timestamp转化为String: S ...
- Java 日期时间 Date类型,long类型,String类型表现形式的转换
Java 日期时间 Date类型,long类型,String类型表现形式的转换 1.java.util.Date类型转换成long类型 java.util.Date dt = new Date(); ...
- Java 日期时间 Date类型,long类型,String类型表现形式的转换 (转)
Java 日期时间 Date类型,long类型,String类型表现形式的转换 1.java.util.Date类型转换成long类型java.util.Date dt = new Date();Sy ...
- Java时间日期格式转换Date转String和String转Date
Java时间格式转换大全 import java.text.*; import java.util.Calendar; public class VeDate { /** * 获取现在时间 * * @ ...
- Js数据类型之——Date
小猪曾经分享过一篇文章,主要是讲到后台使用c#将DataTime类型序列化到前台之后进行操作:具体请看传送门 今天小猪来分享在JS中的Data类型 类型说明 ECMAScript中的Data类型是在早 ...
- sqlite3日期数据类型
一.sqlite3日期数据类型,默认用datetime解析(根据stackflow) 使用时注意三点: 1. 创建表时,字段 DT 的类型为 date 2. 插入数据时,DT字段直接为 str 类型 ...
- java:常用类(包装类,equals和==的比较,Date,java.lang.String中常用方法,枚举enum)
*包装类: 将基本类型封装成类,其中包含属性和方法以方便对象操作. *byte---->Byte *short--->Short *long--->Long *float---> ...
随机推荐
- Android Binder机制(一) Binder的设计和框架
这是关于Android中Binder机制的一系列纯技术贴.花了一个多礼拜的时间,才终于将其整理完毕.行文于此,以做记录:也是将自己所得与大家分享.和以往一样,介绍Binder时,先讲解框架,然后再从设 ...
- CStatic设置位图
CStatic 用于显示位图 如果要显示图标,则必须要设置窗口属性为 SS_BITMAP 和 SS_CENTERIMAGE,实例代码如下: //获得指向静态控件的指针 CStatic *pStatic ...
- parseInt()函数
parseInt()转化整形是从左往右,取出第一个整型,如:10a10b,则显示10: //20170719补充 如果该字符串第一个字符是0,那么该字符串会基于八进制而非十进制来求值,在八进制中,8和 ...
- 基础:Post和Get区别
1.get是从服务器上获取数据,post是向服务器传送数据.2.在客户端, get方式在通过URL提交数据,数据在URL中可以看到:post方式,数据放置在HTML HEADER内提交3.对于get方 ...
- P1638 逛画展
题目描述 博览馆正在展出由世上最佳的 M 位画家所画的图画. wangjy想到博览馆去看这几位大师的作品. 可是,那里的博览馆有一个很奇怪的规定,就是在购买门票时必须说明两个数字, a和b,代表他要看 ...
- array_map 等php回调函数使用问题(关联数组下标获取)
前言:我自己用此类回调函数,来替代 foreach 纯粹是用为代码的简洁性,让代码更好看.(我有点代码小洁癖~) 1.array_reduce 当迭代处理一个一维索引数组时,在回调函数内是无法获取到当 ...
- vue 项目的I18n国际化之路
I18n (internationalization ) ---未完善 产品国际化是产品后期维护及推广中重要的一环,通过国际化操作使得产品能更好适应不同语言和地区的需求 国际化重点:1. 语言语言本地 ...
- 第四节:DataFrame属性及方法(下)
- windows桌面远程工具连接Ubuntu
1.Ubuntu安装:sudo apt-get install xrdp sudo apt-get install vnc4server sudo apt-get install xubuntu ...
- Java基础学习总结(36)——Java注释模板
代码注释是对代码设计者.代码阅读者以及系统间调用提供了有效的帮助,最大限度的提高团队开发合作效率增强系统的可维护性.我们追求简化,不是为了写注释而写注释. (快速使用请直接看六.七.八) 一.原则: ...