当前端传过来的数据类型和数据库里的数据类型不一致时,需要在数据插入进行数据类型
使用 CAST() 函数
CAST ( expression AS type )
--- 例如
select cast(233 as numeric);
mapper文件中
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fengyun.medicallab.lab.mapper.EmployMapper">
<insert id="addEmployees" useGeneratedKeys="true" keyProperty="id">
INSERT
INTO
employees (emp_name, emp_age, emp_no, hire_date, sal, deptno, mgr,
user_name, email, phone_number, sex, emp_password, status, remark)
VALUES(#{empName},#{empAge},#{empNo},#{hireDate}, CAST(#{sal} as money),#{deptno},#{mgr},
#{userName},#{email},#{phoneNumber},#{sex},#{empPassword},#{status},#{remark})
</insert>
</mapper>
还可以使用 CREATE CAST语句自定义转换,详见:
http://postgres.cn/docs/10/sql-createcast.html