<?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.pj.project4sp.role.SpRoleMapper">


	<!-- 增 -->
	<insert id="add" >
		insert into 
		sp_role(id, name, info, is_lock, create_time) 
		values (#{id}, #{name}, #{info}, 2, now())
	</insert>


	<!-- 删 -->
	<delete id="delete" >
		delete from sp_role 
		where id = #{id}
	</delete>


	<!-- 改 -->
	<update id="update" >
		update sp_role set 
		name = #{name}, 
		info = #{info}
		where id=#{id}
	</update>


	<!-- 通用映射 -->
	<resultMap id="model" type="com.pj.project4sp.role.SpRole">
		<result property="id" column="id" />
		<result property="name" column="name" />
		<result property="info" column="info" />
		<result property="isLock" column="is_lock" />
		<result property="createTime" column="create_time" />
	</resultMap>

	<!-- 查 -->
	<select id="getById" resultMap="model" >
		select * from sp_role 
		where id = #{id}
	</select>


	<!-- 查询 -->
	<select id="getList" resultMap="model" >
		select * from sp_role where 1=1 
		<if test=' this.has("name")  '>
			and name like concat('%', #{name}, '%')
		</if>
	</select>

	<!-- 查 - 根据角色名字 -->
	<select id="getByRoleName" resultMap="model">
		select * from sp_role 
		where name = #{name}
	</select>


	
</mapper>
