<?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.fjs.scenic.mapper.system.RolePermissionMapper" >
  <resultMap id="BaseResultMap" type="com.fjs.scenic.entity.system.RolePermission" >
    <constructor >
      <arg column="role_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
      <arg column="permission_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
    </constructor>
  </resultMap>
  <insert id="insert" parameterType="com.fjs.scenic.entity.system.RolePermission" >
    insert into role_permission (role_id, permission_id)
    values (#{roleId,jdbcType=INTEGER}, #{permissionId,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.fjs.scenic.entity.system.RolePermission" >
    insert into role_permission
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="roleId != null" >
        role_id,
      </if>
      <if test="permissionId != null" >
        permission_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="roleId != null" >
        #{roleId,jdbcType=INTEGER},
      </if>
      <if test="permissionId != null" >
        #{permissionId,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>

  <!--手动-->
  <select id="selectByPermissionId" resultMap="BaseResultMap">
    select * from role_permission WHERE permission_id=#{permissionId,jdbcType=INTEGER}
  </select>

  <select id="selectByRoleId" resultMap="BaseResultMap">
    select * from role_permission WHERE role_id=#{id,jdbcType=INTEGER}
  </select>

  <insert id="adds" parameterType="java.util.List" >
    insert into role_permission (role_id, permission_id)
    values
    <foreach collection="list" item="r" index="index" separator=",">
      (#{r.roleId,jdbcType=INTEGER}, #{r.permissionId,jdbcType=VARCHAR})
    </foreach>
  </insert>

  <delete id="delByRoleId" parameterType="java.lang.Integer" >
    delete from role_permission
    where role_id = #{id,jdbcType=INTEGER}
  </delete>
</mapper>