日期数据类型为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---> ...
随机推荐
- [ECharts]"echarts/config" is not exists
今天在给Echarts折线图中的数据点增加点击事件的时候总是出现一个 Uncaught Error: [MODULE_MISS]"echarts/config" is not ex ...
- codeforces_725C_字符串
C. Hidden Word time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- 如何在Android Studio中查看一个类的继承关系呢?
在面板顶部的工具栏中,找到Navigate,然后在下拉列表中,找到“Type Hierarchy”(快捷键 Ctrl+H),点击.即可在面板右侧出现该类的Hierarchy层级图.
- 抓包工具Fiddler及Charles
一.抓包工具介绍 1.charles抓包如何抓取手机端数据包(安卓手机) (1)获取pc的IP地址 (2)打开charles里的[Proxy]-[Proxy setting],设置端口号,默认为888 ...
- DDX DDV 用法
DDX:Dialog Data Exchange 如果使用DDX机制,一般会在OnInitDialog消息处理函数或Dialog构造函数中,为对话框对象的成员变量设置了初始值.在对话框显示前,框架的D ...
- 构建秘钥对验证的SSH体系
构建秘钥对验证的SSH 体系 首先先要在ssh 客户端以root用户身份创建秘钥对 客户端将创建的公钥文件上传至ssh服务器 服务器将公钥信息导入用户root的公钥数据库文件 客户端以root用户身份 ...
- numpy.tile()
numpy.tile()是个什么函数呢,说白了,就是把数组沿各个方向复制 比如 a = np.array([0,1,2]), np.tile(a,(2,1))就是把a先沿x轴(就这样称呼吧)复制 ...
- 跟着alex学习了格式化输出,最大的感受就是编程这个事,一定要自己动手去做,才能学会。看会和自己会做完全是两码事
学习了三天,现在学到格式化输出.看视频教程,alex和那个美女学员打情骂俏,真是羡慕啊. 教程看懂很容易,完全会了. 可是上手编程马上歇菜. 就这么几行的代码,我遇到了n多错误 首先是中文输入的错误, ...
- 50.percentiles百分比算法以及网站延时统计
主要知识点 percentiles的用法 现有一个需求:比如有一个网站,记录下了每次请求的访问的耗时,需要统计tp50,tp90,tp99 tp50:50%的请求的耗时最长在多长时间 tp90 ...
- 彻底搞定Android开发中软键盘的常见问题
软键盘显示的原理 软件盘的本质是什么?软键盘其实是一个Dialog. InputMethodService为我们的输入法创建了一个Dialog,并且将该Dialog的Window的某些参 ...