1. 程式人生 > >Spring Boot + Mybatis 實現動態資料來源

Spring Boot + Mybatis 實現動態資料來源

<?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.louis.springboot.dynamic.datasource.dao.SysUserMapper">
  <resultMap id="BaseResultMap" type="com.louis.springboot.dynamic.datasource.model.SysUser">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="password" jdbcType="VARCHAR" property="password" />
    <result column="salt" jdbcType="VARCHAR" property="salt" />
    <result column="email" jdbcType="VARCHAR" property="email" />
    <result column="mobile" jdbcType="VARCHAR" property="mobile" />
    <result column="status" jdbcType="TINYINT" property="status" />
    <result column="dept_id" jdbcType="BIGINT" property="deptId" />
    <result column="create_by" jdbcType="BIGINT" property="createBy" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="last_update_by" jdbcType="BIGINT" property="lastUpdateBy" />
    <result column="last_update_time" jdbcType="TIMESTAMP" property="lastUpdateTime" />
    <result column="del_flag" jdbcType="TINYINT" property="delFlag" />
  </resultMap>
  <sql id="Base_Column_List">
    id, name, password, salt, email, mobile, status, dept_id, create_by, create_time, 
    last_update_by, last_update_time, del_flag
  
</sql> <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from sys_user where id = #{id,jdbcType=BIGINT} </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> delete from sys_user where id
= #{id,jdbcType=BIGINT} </delete> <insert id="insert" parameterType="com.louis.springboot.dynamic.datasource.model.SysUser"> insert into sys_user (id, name, password, salt, email, mobile, status, dept_id, create_by, create_time, last_update_by, last_update_time, del_flag) values (#{id,jdbcType
=BIGINT}, #{name,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{salt,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT}, #{deptId,jdbcType=BIGINT}, #{createBy,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, #{lastUpdateBy,jdbcType=BIGINT}, #{lastUpdateTime,jdbcType=TIMESTAMP}, #{delFlag,jdbcType=TINYINT}) </insert> <insert id="insertSelective" parameterType="com.louis.springboot.dynamic.datasource.model.SysUser"> insert into sys_user <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null"> id, </if> <if test="name != null"> name, </if> <if test="password != null"> password, </if> <if test="salt != null"> salt, </if> <if test="email != null"> email, </if> <if test="mobile != null"> mobile, </if> <if test="status != null"> status, </if> <if test="deptId != null"> dept_id, </if> <if test="createBy != null"> create_by, </if> <if test="createTime != null"> create_time, </if> <if test="lastUpdateBy != null"> last_update_by, </if> <if test="lastUpdateTime != null"> last_update_time, </if> <if test="delFlag != null"> del_flag, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="id != null"> #{id,jdbcType=BIGINT}, </if> <if test="name != null"> #{name,jdbcType=VARCHAR}, </if> <if test="password != null"> #{password,jdbcType=VARCHAR}, </if> <if test="salt != null"> #{salt,jdbcType=VARCHAR}, </if> <if test="email != null"> #{email,jdbcType=VARCHAR}, </if> <if test="mobile != null"> #{mobile,jdbcType=VARCHAR}, </if> <if test="status != null"> #{status,jdbcType=TINYINT}, </if> <if test="deptId != null"> #{deptId,jdbcType=BIGINT}, </if> <if test="createBy != null"> #{createBy,jdbcType=BIGINT}, </if> <if test="createTime != null"> #{createTime,jdbcType=TIMESTAMP}, </if> <if test="lastUpdateBy != null"> #{lastUpdateBy,jdbcType=BIGINT}, </if> <if test="lastUpdateTime != null"> #{lastUpdateTime,jdbcType=TIMESTAMP}, </if> <if test="delFlag != null"> #{delFlag,jdbcType=TINYINT}, </if> </trim> </insert> <update id="updateByPrimaryKeySelective" parameterType="com.louis.springboot.dynamic.datasource.model.SysUser"> update sys_user <set> <if test="name != null"> name = #{name,jdbcType=VARCHAR}, </if> <if test="password != null"> password = #{password,jdbcType=VARCHAR}, </if> <if test="salt != null"> salt = #{salt,jdbcType=VARCHAR}, </if> <if test="email != null"> email = #{email,jdbcType=VARCHAR}, </if> <if test="mobile != null"> mobile = #{mobile,jdbcType=VARCHAR}, </if> <if test="status != null"> status = #{status,jdbcType=TINYINT}, </if> <if test="deptId != null"> dept_id = #{deptId,jdbcType=BIGINT}, </if> <if test="createBy != null"> create_by = #{createBy,jdbcType=BIGINT}, </if> <if test="createTime != null"> create_time = #{createTime,jdbcType=TIMESTAMP}, </if> <if test="lastUpdateBy != null"> last_update_by = #{lastUpdateBy,jdbcType=BIGINT}, </if> <if test="lastUpdateTime != null"> last_update_time = #{lastUpdateTime,jdbcType=TIMESTAMP}, </if> <if test="delFlag != null"> del_flag = #{delFlag,jdbcType=TINYINT}, </if> </set> where id = #{id,jdbcType=BIGINT} </update> <update id="updateByPrimaryKey" parameterType="com.louis.springboot.dynamic.datasource.model.SysUser"> update sys_user set name = #{name,jdbcType=VARCHAR}, password = #{password,jdbcType=VARCHAR}, salt = #{salt,jdbcType=VARCHAR}, email = #{email,jdbcType=VARCHAR}, mobile = #{mobile,jdbcType=VARCHAR}, status = #{status,jdbcType=TINYINT}, dept_id = #{deptId,jdbcType=BIGINT}, create_by = #{createBy,jdbcType=BIGINT}, create_time = #{createTime,jdbcType=TIMESTAMP}, last_update_by = #{lastUpdateBy,jdbcType=BIGINT}, last_update_time = #{lastUpdateTime,jdbcType=TIMESTAMP}, del_flag = #{delFlag,jdbcType=TINYINT} where id = #{id,jdbcType=BIGINT} </update> <select id="findAll" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from sys_user </select> </mapper>