标签:
studentMapper.insertStudent(student);在执行晚SQL语句之后,记得session.commit(); |
配置数据库地址时加上编码格式characterEncoding: <property name="url" value="jdbc:mysql://localhost:3306/test?characterEncoding=utf8"/> |
<?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.sjf.mapper.CourseMapper">
<resultMap id = "CourseResultMap" type="com.sjf.bean.Course" >
<id property="ID" column="ID"/>
<result property="name" column="name"/>
<result property="desc" column="description"/>
<result property = "startDate" column = "startDate"/>
<result property = "endDate" column = "endDate"/>
</resultMap>
<select id="getCourseByCondation" parameterType="hashmap" resultMap="CourseResultMap">
SELECT * FROM Course
WHERE teacherID = #{teacherID}
<if test = "courseName != null" >
AND NAME = #{courseName}
</if>
<if test = "startDate != null">
AND startDate >= #{startDate}
</if>
<if test = "endDate != null">
AND endDate <= #{endDate}
</if>
</select>
</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.sjf.mapper.CourseMapper">
<resultMap id = "CourseResultMap" type="com.sjf.bean.Course" >
<id property="ID" column="ID"/>
<result property="name" column="name"/>
<result property="desc" column="description"/>
<result property = "startDate" column = "startDate"/>
<result property = "endDate" column = "endDate"/>
</resultMap>
<select id="getCourseByCondation" parameterType="hashmap" resultMap="CourseResultMap">
SELECT * FROM Course
WHERE teacherID = #{teacherID}
<if test = "courseName != null" >
AND NAME = #{courseName}
</if>
<if test = "startDate != null">
<![CDATA[AND startDate >= #{startDate} ]]>
</if>
<if test = "endDate != null">
<![CDATA[AND endDate <= #{endDate} ]]>
</if>
</select>
</mapper>
标签:
原文地址:http://blog.csdn.net/sunnyyoona/article/details/50710310