<mapper namespace="Message">
<!--type:与数据库对应的模型类, id即为名字-->
<resultMap type="main.entity.Message" id="MessageResult">
<!--cloumn:数据库的列名 jdbcType:对应的类型,注意要用大写, property:模型类对应的属性名-->
<!--主键是id 其他是result-->
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="command" jdbcType="VARCHAR" property="command"/>
<result column="description" jdbcType="VARCHAR" property="description"/>
<result column="content" jdbcType="VARCHAR" property="content"/>
</resultMap>
<!--将查出来的值放在resultMap所对应的column里面-->
<!--parameterType传入查询的类参数类型-->
<select id="queryMessageList" parameterType="main.entity.Message" resultMap="MessageResult">
select id,command,description,content from message where 1=1
<!--OGNL表达式 #{}在拼接mysql语句的时候, 会子自动转换为?, 并将command赋值-->
<if test="command!=null and !"".equals(command.trim())">and command=#{command}</if>
<if test="description!=null and !"".equals(description.trim())">and description = #{description}</if>
</select>
<!--删除语句-->
<delete id="deleteOne" parameterType="String">
delete from message where id=#{_parameter}
</delete>
<delete id="deleteBatch" parameterType="List" >
delete from message where id in(
<foreach collection="list" item="item" separator=",">
#{item}
</foreach>
)
</delete>
<!--select ID,COMMAND,DESCRIPTION,CONTENT from MESSAGE
<where>
<if test="command != null and !"".equals(command.trim())">
and COMMAND=#{command}
</if>
<if test="description != null and !"".equals(description.trim())">
and DESCRIPTION like '%' #{description} '%'
</if>
</where>-->
<!--<delete id="deleteOne" parameterType="int">-->
<!--delete from MESSAGE where ID = #{_parameter}-->
<!--</delete>-->
<!--<delete id="deleteBatch" parameterType="java.util.List">-->
<!--delete from MESSAGE where ID in(-->
<!--<foreach collection="list" item="item" separator=",">-->
<!--#{item}-->
<!--</foreach>-->
<!--)-->
<!--</delete>-->
</mapper>
<!--最后还需要将mapper在xml中配置-->
<mappers>
<mapper resource="/main/config/sql/Message.xml"></mapper>
</mappers>