<?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">
<!-- 映射文件：存放CRUD的sql语句 -->
<mapper namespace="com.ssm.mapper.DemoMapper">
	<select id="getDemoById" resultMap="DemoResult" parameterType="Integer">
		SELECT did,dname,comment
		FROM Demo d
		WHERE d.did=#{did}
	</select>

	<resultMap type="com.ssm.entity.Demo" id="DemoResult">
		<id property="did" column="did"/>
		<result property="dname" column="dname"/>
		<result property="comment" column="comment"/>
	</resultMap>

	<select id="getDemoAll" resultMap="DemoResult" parameterType="int">
		SELECT did,dname,comment
		FROM Demo d
		WHERE 1=1
		limit #{param1},#{param2}
	</select>
	<insert id="addDemo" parameterType="com.ssm.entity.Demo">
		insert into Demo(dname,comment)
		values(#{dname},#{comment})
	</insert>

	<update id="updateDemo" parameterType="com.ssm.entity.Demo">
		update Demo set dname=#{dname},comment=#{comment} where did=#{did}
	</update>

	<delete id="deleteDemoById" parameterType="Integer">
		<!-- delete from 表名 where 列名称=某值 -->
		delete from Demo where did=#{did}
	</delete>

	<delete id="deleteDemoAll">
		<!-- delete from 表名 -->
		delete from Demo
	</delete>

	<select id="countTotlePage" resultType="Integer">
		SELECT count(*)
		FROM Demo d

	</select>

	<select id="findDemoByDid" resultMap="DemoResult" parameterType="Integer">
		SELECT did,dname,comment
		FROM Demo d
		WHERE d.did=#{did}
	</select>

	<!-- 模糊查询 -->
	<select id="searchDemoByCondition" parameterType="String"
			resultMap="DemoResult">
		SELECT did,dname,comment
		FROM Demo d
		WHERE d.dname like '%${value}%' or d.comment like '%${value}%'
	</select>
</mapper>