写查询语句的时候出现的错,记录一下:
<?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.mybatis.demo.domain.dao.cfDAO">
<resultMap id="techermap" type="实体类的地址(和数据库表中字段一致的定义的类)">
<id property="id" column="字段名1" javaType ="java.lang.String"/>
<result property="amt" column="字段名2" javaType ="java.math.BigDecimal"/>
</resultMap>
<!--insert 是要和这个xml同名的xxxDAO.java中的定义名字一致-->
<insert id="insert">
insert into demo (id ,amt) values (#{id ,jdbcType=VARCHAR},#{amt,jdbcType=VARCHAR})
</insert>
<update id ="XXS">
update demo
<set>
<if test="id != null and id !=''">
id =#{id ,jdbcType=VARCHAR},
</if>
</set>
</update>
<delete id ="deleteByKey">
delete from demo where id = #{id}
</delete>
<select id ="findByWhere">
select id from demo
<where>
amt ='10' and ((Date3!= '2020630' AND Date4!= '2020730') OR (Date3== '2020430' AND Date4== '2020530'))
<if test="accDate!=null and accDate!= ''">
and accDate = #{accDate}
</if>
<!--Date在数据库中没有该字段,定义类中有这个字段-->
<if test="Date1!=null and Date1!= '' and Date2!=null and Date2!= ''">
and Date between #{Date1} and #{Date2}
</if>
<if test="Date1!=null and Date1!= ''">
<if test='Date2==null and Date2== "" '>
and Date = #{Date1}
</if>
</if>
</where>
</select>
</mapper>
注: 在判断时候,<if> 不等于的时候可用 “ ”,字段的值可以用‘’;
相等的时候用‘’,字段的值可以用“”。