首页 技术 正文
技术 2022年11月14日
0 收藏 356 点赞 3,577 浏览 1849 个字

方法一:

在实体类里面将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>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,022
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,359
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,142
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,773
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,851