xml的配置:
<mapper namespace="com.dao.StudyDao" >
<resultMap id="BaseResultMap" type="com.model.Study" >
<id column="id" property="sId" jdbcType="INTEGER" /> <result column="course_name" property="courseName" jdbcType="VARCHAR" /> <result column="level" property="level" jdbcType="VARCHAR" /> <result column="createtime" property="createTime" jdbcType="DATE" /> </resultMap>
<sql id="where_course">
<trim prefix="where" prefixOverrides="and|or"> <if test="results != null and results != ''"> <if test="results.courseName!= null and results.courseName!='' "> and course_name like CONCAT('%',#{results.courseName},'%') </if> </if> </trim> </sql>
<sql id="Base_Column_List" >
course_name ,createtime,level,id </sql>
<select id="getCourseList" resultMap="BaseResultMap" parameterType="com.model.Study">
select <include refid="Base_Column_List"/> from s_course <include refid="where_course"/> order by id desc </select><select id="countCourse" resultType="int" parameterType="com.model.Study">
select count(1) from s_course <include refid="where_course"/> </select>
<select id="getCourse" resultMap="BaseResultMap" parameterType="java.lang.String" >
select <include refid="Base_Column_List" /> from s_course a where id = #{sId,jdbcType=INTEGER} </select><delete id="delCourse" parameterType="int" >
delete from s_course where id = #{sId,jdbcType=INTEGER} </delete> <insert id="addCourse" parameterType="com.model.Study" > insert into s_course (course_name, createtime, level) values (#{courseName,jdbcType=VARCHAR}, #{createTime,jdbcType=DATE}, #{level,jdbcType=VARCHAR}) </insert> <update id="updateCourse" parameterType="com.model.Study" > update s_course <set > <if test="courseName != null" > course_name = #{courseName,jdbcType=VARCHAR}, </if> <if test="level != null" > level = #{level,jdbcType=VARCHAR}, </if> <if test="createTime != null" > createtime = #{createTime,jdbcType=DATE}, </if> </set> where id = #{sId,jdbcType=INTEGER} </update></mapper>