第一步:编辑工具
JDK1.8
MySQL8
Eclipse4.9.0
Durid
第二步:项目结构截图:
第三步:项目依赖文件:
boot-shrio.pom.xml 文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zzg</groupId>
<artifactId>boot-shrio</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<encoding>UTF-8</encoding>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<!--web 模块依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--web 热部署
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency> -->
<!--web 单元测试 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--common-lang 常用工具包 -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!--commons-codec 加密工具包 -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
</dependencies>
<modules>
<module>boot-shrio-api</module>
<module>boot-shrio-dao</module>
<module>boot-shrio-controller</module>
</modules>
</project>
boot-shrio-api的pom.xml 文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.zzg</groupId>
<artifactId>boot-shrio</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>boot-shrio-api</artifactId>
</project>
boot-shrio-dao的pom.xml 文件
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.zzg</groupId>
<artifactId>boot-shrio</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>boot-shrio-dao</artifactId>
<!--jar 依赖 -->
<dependencies>
<dependency>
<groupId>com.zzg</groupId>
<artifactId>boot-shrio-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<!--集成mybatis-generator 自动生成组件 -->
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.12</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.7</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<phase>package</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<!--允许移动生成的文件 -->
<verbose>true</verbose>
<!-- 是否覆盖 -->
<overwrite>true</overwrite>
<!-- 自动生成的配置 -->
<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
</configuration>
</plugin>
</plugins>
</build>
</project>
boot-shrio-controller的pom.xml 文件
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.zzg</groupId>
<artifactId>boot-shrio</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>boot-shrio-controller</artifactId>
<!--依赖jar 包 -->
<dependencies>
<!--依赖api层 -->
<dependency>
<groupId>com.zzg</groupId>
<artifactId>boot-shrio-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!--dao 层依赖 -->
<dependency>
<groupId>com.zzg</groupId>
<artifactId>boot-shrio-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!--springboot 与 mybatis 集成 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<!-- 数据库连接池druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
<!--mysql 驱动程序 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.12</version>
</dependency>
<!--dubbo 服务依赖 -->
<!--
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.8.4</version>
<exclusions>
<exclusion>
<artifactId>spring</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency> -->
<!--apache shrio 依赖jar -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-ehcache</artifactId>
<version>1.2.5</version>
</dependency>
<!--thymeleaf 模板依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
</dependencies>
</project>
数据库实体文件、mapper.xml文件、接口定义和接口实现。
实体对象定义:
package com.zzg.entity;
import java.io.Serializable;
public class Permission implements Serializable {
private Long id;
private String url;
private String name;
private static final long serialVersionUID = 1L;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url == null ? null : url.trim();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", url=").append(url);
sb.append(", name=").append(name);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}
package com.zzg.entity;
import java.io.Serializable;
public class Role implements Serializable {
private Long id;
private String name;
private String type;
private static final long serialVersionUID = 1L;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type == null ? null : type.trim();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", name=").append(name);
sb.append(", type=").append(type);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}
package com.zzg.entity;
import java.io.Serializable;
public class RolePermission implements Serializable {
private Long rid;
private Long pid;
private static final long serialVersionUID = 1L;
public Long getRid() {
return rid;
}
public void setRid(Long rid) {
this.rid = rid;
}
public Long getPid() {
return pid;
}
public void setPid(Long pid) {
this.pid = pid;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", rid=").append(rid);
sb.append(", pid=").append(pid);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}
package com.zzg.entity;
import java.io.Serializable;
import java.util.Date;
public class User implements Serializable {
private Long id;
private String nickname;
private String email;
private String pswd;
private Date createTime;
private Date lastLoginTime;
private Long status;
private static final long serialVersionUID = 1L;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname == null ? null : nickname.trim();
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email == null ? null : email.trim();
}
public String getPswd() {
return pswd;
}
public void setPswd(String pswd) {
this.pswd = pswd == null ? null : pswd.trim();
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getLastLoginTime() {
return lastLoginTime;
}
public void setLastLoginTime(Date lastLoginTime) {
this.lastLoginTime = lastLoginTime;
}
public Long getStatus() {
return status;
}
public void setStatus(Long status) {
this.status = status;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", nickname=").append(nickname);
sb.append(", email=").append(email);
sb.append(", pswd=").append(pswd);
sb.append(", createTime=").append(createTime);
sb.append(", lastLoginTime=").append(lastLoginTime);
sb.append(", status=").append(status);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}
package com.zzg.entity;
import java.io.Serializable;
public class UserRole implements Serializable {
private Long uid;
private Long rid;
private static final long serialVersionUID = 1L;
public Long getUid() {
return uid;
}
public void setUid(Long uid) {
this.uid = uid;
}
public Long getRid() {
return rid;
}
public void setRid(Long rid) {
this.rid = rid;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", uid=").append(uid);
sb.append(", rid=").append(rid);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}
mapper.xml 文件定义
PermissionMapper.xml
<?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.zzg.mapper.PermissionMapper">
<resultMap id="BaseResultMap" type="com.zzg.entity.Permission">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="url" jdbcType="VARCHAR" property="url" />
<result column="name" jdbcType="VARCHAR" property="name" />
</resultMap>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from u_permission
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.zzg.entity.Permission">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
SELECT LAST_INSERT_ID()
</selectKey>
insert into u_permission (url, `name`)
values (#{url,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR})
</insert>
<update id="updateByPrimaryKey" parameterType="com.zzg.entity.Permission">
update u_permission
set url = #{url,jdbcType=VARCHAR},
`name` = #{name,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select id, url, `name`
from u_permission
where id = #{id,jdbcType=BIGINT}
</select>
<select id="selectAll" resultMap="BaseResultMap">
select id, url, `name`
from u_permission
</select>
<select id="getByPermissionIds" resultMap="BaseResultMap">
select id, url, `name`
from u_permission where id in
<foreach close=")" collection="list" index="index" item="item" open="(" separator=",">
#{item}
</foreach>
</select>
</mapper>
RoleMapper.xml
<?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.zzg.mapper.RoleMapper">
<resultMap id="BaseResultMap" type="com.zzg.entity.Role">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="type" jdbcType="VARCHAR" property="type" />
</resultMap>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from u_role
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.zzg.entity.Role">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
SELECT LAST_INSERT_ID()
</selectKey>
insert into u_role (`name`, `type`)
values (#{name,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR})
</insert>
<update id="updateByPrimaryKey" parameterType="com.zzg.entity.Role">
update u_role
set `name` = #{name,jdbcType=VARCHAR},
`type` = #{type,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select id, `name`, `type`
from u_role
where id = #{id,jdbcType=BIGINT}
</select>
<select id="selectAll" resultMap="BaseResultMap">
select id, `name`, `type`
from u_role
</select>
<!--批量查询 -->
<select id="getByIds" resultMap="BaseResultMap">
select id, `name`, `type`
from u_role where id in
<foreach close=")" collection="list" index="index" item="item" open="(" separator=",">
#{item}
</foreach>
</select>
</mapper>
RolePermissionMapper.xml
<?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.zzg.mapper.RolePermissionMapper">
<resultMap id="BaseResultMap" type="com.zzg.entity.RolePermission">
<result column="rid" jdbcType="BIGINT" property="rid" />
<result column="pid" jdbcType="BIGINT" property="pid" />
</resultMap>
<insert id="insert" parameterType="com.zzg.entity.RolePermission">
insert into u_role_permission (rid, pid)
values (#{rid,jdbcType=BIGINT}, #{pid,jdbcType=BIGINT})
</insert>
<select id="selectAll" resultMap="BaseResultMap">
select rid, pid
from u_role_permission
</select>
<select id="getByRoleIds" resultMap="BaseResultMap">
select rid, pid
from u_role_permission where rid in
<foreach close=")" collection="list" index="index" item="item" open="(" separator=",">
#{item}
</foreach>
</select>
</mapper>
UserMapper.xml
<?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.zzg.mapper.UserMapper">
<resultMap id="BaseResultMap" type="com.zzg.entity.User">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="nickname" jdbcType="VARCHAR" property="nickname" />
<result column="email" jdbcType="VARCHAR" property="email" />
<result column="pswd" jdbcType="VARCHAR" property="pswd" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="last_login_time" jdbcType="TIMESTAMP" property="lastLoginTime" />
<result column="status" jdbcType="BIGINT" property="status" />
</resultMap>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from u_user
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.zzg.entity.User">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
SELECT LAST_INSERT_ID()
</selectKey>
insert into u_user (nickname, email, pswd,
create_time, last_login_time, `status`
)
values (#{nickname,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{pswd,jdbcType=VARCHAR},
#{createTime,jdbcType=TIMESTAMP}, #{lastLoginTime,jdbcType=TIMESTAMP}, #{status,jdbcType=BIGINT}
)
</insert>
<update id="updateByPrimaryKey" parameterType="com.zzg.entity.User">
update u_user
set nickname = #{nickname,jdbcType=VARCHAR},
email = #{email,jdbcType=VARCHAR},
pswd = #{pswd,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
last_login_time = #{lastLoginTime,jdbcType=TIMESTAMP},
`status` = #{status,jdbcType=BIGINT}
where id = #{id,jdbcType=BIGINT}
</update>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select id, nickname, email, pswd, create_time, last_login_time, `status`
from u_user
where id = #{id,jdbcType=BIGINT}
</select>
<select id="selectAll" resultMap="BaseResultMap">
select id, nickname, email, pswd, create_time, last_login_time, `status`
from u_user
</select>
<select id="getByUserName" parameterType="java.lang.String" resultMap="BaseResultMap">
select id, nickname, email, pswd, create_time, last_login_time, `status`
from u_user
where nickname = #{username,jdbcType=VARCHAR}
</select>
</mapper>
UserRoleMapper.xml
<?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.zzg.mapper.UserRoleMapper">
<resultMap id="BaseResultMap" type="com.zzg.entity.UserRole">
<result column="uid" jdbcType="BIGINT" property="uid" />
<result column="rid" jdbcType="BIGINT" property="rid" />
</resultMap>
<insert id="insert" parameterType="com.zzg.entity.UserRole">
insert into u_user_role (`uid`, rid)
values (#{uid,jdbcType=BIGINT}, #{rid,jdbcType=BIGINT})
</insert>
<select id="selectAll" resultMap="BaseResultMap">
select `uid`, rid
from u_user_role
</select>
<select id="getByUid" parameterType="java.lang.Long" resultMap="BaseResultMap">
select `uid`, rid
from u_user_role
where `uid` = #{userId,jdbcType=BIGINT}
</select>
<select id="getByRid" parameterType="java.lang.Long" resultMap="BaseResultMap">
select `uid`, rid
from u_user_role
where rid = #{roleId,jdbcType=BIGINT}
</select>
</mapper>
mapper接口定义:
PermissionMapper.java
package com.zzg.mapper;
import com.zzg.entity.Permission;
import java.util.List;
public interface PermissionMapper {
int deleteByPrimaryKey(Long id);
int insert(Permission record);
Permission selectByPrimaryKey(Long id);
List<Permission> selectAll();
int updateByPrimaryKey(Permission record);
List<Permission> getByPermissionIds(List<Long> ids);
}
RoleMapper.java
package com.zzg.mapper;
import com.zzg.entity.Role;
import java.util.List;
public interface RoleMapper {
int deleteByPrimaryKey(Long id);
int insert(Role record);
Role selectByPrimaryKey(Long id);
List<Role> selectAll();
int updateByPrimaryKey(Role record);
List<Role> getByIds(List<Long> list);
}
RolePermissionMapper.java
package com.zzg.mapper;
import com.zzg.entity.RolePermission;
import java.util.List;
public interface RolePermissionMapper {
int insert(RolePermission record);
List<RolePermission> selectAll();
List<RolePermission> getByRoleIds(List<Long> rids);
}
UserMapper.java
package com.zzg.mapper;
import com.zzg.entity.User;
import java.util.List;
public interface UserMapper {
int deleteByPrimaryKey(Long id);
int insert(User record);
User selectByPrimaryKey(Long id);
List<User> selectAll();
int updateByPrimaryKey(User record);
User getByUserName(String username);
}
UserRoleMapper.java
package com.zzg.mapper;
import com.zzg.entity.UserRole;
import java.util.List;
public interface UserRoleMapper {
int insert(UserRole record);
List<UserRole> selectAll();
List<UserRole> getByUid(Long userId);
List<UserRole> getByRid(Long roleId);
}
service 接口定义
PermissionService.java
package com.zzg.service;
import java.util.List;
import com.zzg.entity.Permission;
public interface PermissionService {
int deleteByPrimaryKey(Long id);
int insert(Permission record);
Permission selectByPrimaryKey(Long id);
List<Permission> selectAll();
int updateByPrimaryKey(Permission record);
List<Permission> getByPermissionIds(List<Long> ids);
}
RolePermissionService.java
package com.zzg.service;
import java.util.List;
import com.zzg.entity.RolePermission;
public interface RolePermissionService {
int insert(RolePermission record);
List<RolePermission> selectAll();
List<RolePermission> getByRoleIds(List<Long> rids);
}
RoleService.java
package com.zzg.service;
import java.util.List;
import com.zzg.entity.Role;
public interface RoleService {
int deleteByPrimaryKey(Long id);
int insert(Role record);
Role selectByPrimaryKey(Long id);
List<Role> selectAll();
int updateByPrimaryKey(Role record);
List<Role> getByIds(List<Long> list);
}
UserRoleService.java
package com.zzg.service;
import java.util.List;
import com.zzg.entity.UserRole;
public interface UserRoleService {
int insert(UserRole record);
List<UserRole> selectAll();
List<UserRole> getByUid(Long userId);
List<UserRole> getByRid(Long roleId);
}
UserService.java
package com.zzg.service;
import java.util.List;
import com.zzg.entity.User;
public interface UserService {
int deleteByPrimaryKey(Long id);
int insert(User record);
User selectByPrimaryKey(Long id);
List<User> selectAll();
int updateByPrimaryKey(User record);
User getByUserName(String username);
}
service 接口实现:
PermissionServiceImpl.java
package com.zzg.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zzg.entity.Permission;
import com.zzg.mapper.PermissionMapper;
import com.zzg.service.PermissionService;
@Service
public class PermissionServiceImpl implements PermissionService {
@Autowired
private PermissionMapper mapper;
@Override
public int deleteByPrimaryKey(Long id) {
// TODO Auto-generated method stub
return mapper.deleteByPrimaryKey(id);
}
@Override
public int insert(Permission record) {
// TODO Auto-generated method stub
return mapper.insert(record);
}
@Override
public Permission selectByPrimaryKey(Long id) {
// TODO Auto-generated method stub
return mapper.selectByPrimaryKey(id);
}
@Override
public List<Permission> selectAll() {
// TODO Auto-generated method stub
return mapper.selectAll();
}
@Override
public int updateByPrimaryKey(Permission record) {
// TODO Auto-generated method stub
return mapper.updateByPrimaryKey(record);
}
@Override
public List<Permission> getByPermissionIds(List<Long> ids) {
// TODO Auto-generated method stub
return mapper.getByPermissionIds(ids);
}
}
RolePermissionServiceImpl.java
package com.zzg.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zzg.entity.RolePermission;
import com.zzg.mapper.RolePermissionMapper;
import com.zzg.service.RolePermissionService;
@Service
public class RolePermissionServiceImpl implements RolePermissionService {
@Autowired
private RolePermissionMapper mapper;
@Override
public int insert(RolePermission record) {
// TODO Auto-generated method stub
return mapper.insert(record);
}
@Override
public List<RolePermission> selectAll() {
// TODO Auto-generated method stub
return mapper.selectAll();
}
@Override
public List<RolePermission> getByRoleIds(List<Long> rids) {
// TODO Auto-generated method stub
return mapper.getByRoleIds(rids);
}
}
RoleServiceImpl.java
package com.zzg.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zzg.entity.Role;
import com.zzg.mapper.RoleMapper;
import com.zzg.service.RoleService;
@Service
public class RoleServiceImpl implements RoleService {
@Autowired
private RoleMapper mapper;
@Override
public int deleteByPrimaryKey(Long id) {
// TODO Auto-generated method stub
return mapper.deleteByPrimaryKey(id);
}
@Override
public int insert(Role record) {
// TODO Auto-generated method stub
return mapper.insert(record);
}
@Override
public Role selectByPrimaryKey(Long id) {
// TODO Auto-generated method stub
return mapper.selectByPrimaryKey(id);
}
@Override
public List<Role> selectAll() {
// TODO Auto-generated method stub
return mapper.selectAll();
}
@Override
public int updateByPrimaryKey(Role record) {
// TODO Auto-generated method stub
return mapper.updateByPrimaryKey(record);
}
@Override
public List<Role> getByIds(List<Long> list) {
// TODO Auto-generated method stub
return mapper.getByIds(list);
}
}
UserRoleServiceImpl.java
package com.zzg.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zzg.entity.UserRole;
import com.zzg.mapper.UserRoleMapper;
import com.zzg.service.UserRoleService;
@Service
public class UserRoleServiceImpl implements UserRoleService {
@Autowired
private UserRoleMapper mapper;
@Override
public int insert(UserRole record) {
// TODO Auto-generated method stub
return mapper.insert(record);
}
@Override
public List<UserRole> selectAll() {
// TODO Auto-generated method stub
return mapper.selectAll();
}
@Override
public List<UserRole> getByUid(Long userId) {
// TODO Auto-generated method stub
return mapper.getByUid(userId);
}
@Override
public List<UserRole> getByRid(Long roleId) {
// TODO Auto-generated method stub
return mapper.getByRid(roleId);
}
}
UserServiceImpl.java
package com.zzg.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zzg.entity.User;
import com.zzg.mapper.UserMapper;
import com.zzg.service.UserService;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper mapper;
@Override
public int deleteByPrimaryKey(Long id) {
// TODO Auto-generated method stub
return mapper.deleteByPrimaryKey(id);
}
@Override
public int insert(User record) {
// TODO Auto-generated method stub
return mapper.insert(record);
}
@Override
public User selectByPrimaryKey(Long id) {
// TODO Auto-generated method stub
return mapper.selectByPrimaryKey(id);
}
@Override
public List<User> selectAll() {
// TODO Auto-generated method stub
return mapper.selectAll();
}
@Override
public int updateByPrimaryKey(User record) {
// TODO Auto-generated method stub
return mapper.updateByPrimaryKey(record);
}
@Override
public User getByUserName(String username) {
// TODO Auto-generated method stub
System.out.println("user参数:" + username);
User user= mapper.getByUserName(username);
return user;
}
}
application.properties 配置文件
# \u5B9A\u4E49logback \u914D\u7F6E\u6587\u4EF6
logging.config=classpath:logback.xml
#mybatis xml \u6587\u4EF6\u914D\u7F6E
mybatis.mapper-locations=classpath:mapper/*Mapper.xml
# Thymeleaf setting
thymeleaf.cache=false
thymeleaf.mode=LEGACYHTML5
# MyBatis mysql8 \u914D\u7F6E
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/boot_shrio?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# Druid \u914D\u7F6E
# \u521D\u59CB\u5316\u65F6\u5EFA\u7ACB\u7269\u7406\u8FDE\u63A5\u7684\u4E2A\u6570
spring.datasource.druid.initial-size=5
# \u6700\u5927\u8FDE\u63A5\u6C60\u6570\u91CF
spring.datasource.druid.max-active=30
# \u6700\u5C0F\u8FDE\u63A5\u6C60\u6570\u91CF
spring.datasource.druid.min-idle=5
# \u83B7\u53D6\u8FDE\u63A5\u65F6\u6700\u5927\u7B49\u5F85\u65F6\u95F4\uFF0C\u5355\u4F4D\u6BEB\u79D2
spring.datasource.druid.max-wait=60000
# \u914D\u7F6E\u95F4\u9694\u591A\u4E45\u624D\u8FDB\u884C\u4E00\u6B21\u68C0\u6D4B\uFF0C\u68C0\u6D4B\u9700\u8981\u5173\u95ED\u7684\u7A7A\u95F2\u8FDE\u63A5\uFF0C\u5355\u4F4D\u662F\u6BEB\u79D2
spring.datasource.druid.time-between-eviction-runs-millis=60000
# \u8FDE\u63A5\u4FDD\u6301\u7A7A\u95F2\u800C\u4E0D\u88AB\u9A71\u9010\u7684\u6700\u5C0F\u65F6\u95F4
spring.datasource.druid.min-evictable-idle-time-millis=300000
# \u7528\u6765\u68C0\u6D4B\u8FDE\u63A5\u662F\u5426\u6709\u6548\u7684sql\uFF0C\u8981\u6C42\u662F\u4E00\u4E2A\u67E5\u8BE2\u8BED\u53E5
spring.datasource.druid.validation-query=SELECT 1 FROM DUAL
# \u5EFA\u8BAE\u914D\u7F6E\u4E3Atrue\uFF0C\u4E0D\u5F71\u54CD\u6027\u80FD\uFF0C\u5E76\u4E14\u4FDD\u8BC1\u5B89\u5168\u6027\u3002\u7533\u8BF7\u8FDE\u63A5\u7684\u65F6\u5019\u68C0\u6D4B\uFF0C\u5982\u679C\u7A7A\u95F2\u65F6\u95F4\u5927\u4E8EtimeBetweenEvictionRunsMillis\uFF0C\u6267\u884CvalidationQuery\u68C0\u6D4B\u8FDE\u63A5\u662F\u5426\u6709\u6548\u3002
spring.datasource.druid.test-while-idle=true
# \u7533\u8BF7\u8FDE\u63A5\u65F6\u6267\u884CvalidationQuery\u68C0\u6D4B\u8FDE\u63A5\u662F\u5426\u6709\u6548\uFF0C\u505A\u4E86\u8FD9\u4E2A\u914D\u7F6E\u4F1A\u964D\u4F4E\u6027\u80FD\u3002
spring.datasource.druid.test-on-borrow=false
# \u5F52\u8FD8\u8FDE\u63A5\u65F6\u6267\u884CvalidationQuery\u68C0\u6D4B\u8FDE\u63A5\u662F\u5426\u6709\u6548\uFF0C\u505A\u4E86\u8FD9\u4E2A\u914D\u7F6E\u4F1A\u964D\u4F4E\u6027\u80FD\u3002
spring.datasource.druid.test-on-return=false
# \u662F\u5426\u7F13\u5B58preparedStatement\uFF0C\u4E5F\u5C31\u662FPSCache\u3002PSCache\u5BF9\u652F\u6301\u6E38\u6807\u7684\u6570\u636E\u5E93\u6027\u80FD\u63D0\u5347\u5DE8\u5927\uFF0C\u6BD4\u5982\u8BF4oracle\u3002\u5728mysql\u4E0B\u5EFA\u8BAE\u5173\u95ED\u3002
spring.datasource.druid.pool-prepared-statements=true
# \u8981\u542F\u7528PSCache\uFF0C\u5FC5\u987B\u914D\u7F6E\u5927\u4E8E0\uFF0C\u5F53\u5927\u4E8E0\u65F6\uFF0CpoolPreparedStatements\u81EA\u52A8\u89E6\u53D1\u4FEE\u6539\u4E3Atrue\u3002
spring.datasource.druid.max-pool-prepared-statement-per-connection-size=50
# \u914D\u7F6E\u76D1\u63A7\u7EDF\u8BA1\u62E6\u622A\u7684filters\uFF0C\u53BB\u6389\u540E\u76D1\u63A7\u754C\u9762sql\u65E0\u6CD5\u7EDF\u8BA1
spring.datasource.druid.filters=stat,wall
# \u901A\u8FC7connectProperties\u5C5E\u6027\u6765\u6253\u5F00mergeSql\u529F\u80FD\uFF1B\u6162SQL\u8BB0\u5F55
spring.datasource.druid.connection-properties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
# \u5408\u5E76\u591A\u4E2ADruidDataSource\u7684\u76D1\u63A7\u6570\u636E
spring.datasource.druid.use-global-data-source-stat=true
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- 从高到地低 OFF 、 FATAL 、 ERROR 、 WARN 、 INFO 、 DEBUG 、 TRACE 、 ALL -->
<!-- 日志输出规则 根据当前ROOT 级别,日志输出时,级别高于root默认的级别时 会输出 -->
<!-- 以下 每个配置的 filter 是过滤掉输出文件里面,会出现高级别文件,依然出现低级别的日志信息,通过filter 过滤只记录本级别的日志-->
<!-- 属性描述 scan:性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true scanPeriod:设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,
默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。
debug:当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。 -->
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 定义日志文件 输入位置 -->
<property name="log_dir" value="/logs/mysql-boot" />
<!-- 日志最大的历史 30天 -->
<property name="maxHistory" value="30"/>
<!-- ConsoleAppender 控制台输出日志 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- 对日志进行格式化 -->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger -%msg%n</pattern>
</encoder>
</appender>
<!-- ERROR级别日志 -->
<!-- 滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件 RollingFileAppender-->
<appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 过滤器,只记录WARN级别的日志 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<!-- 最常用的滚动策略,它根据时间来制定滚动策略.既负责滚动也负责出发滚动 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志输出位置 可相对、和绝对路径 -->
<fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/mysql-boot-error-log.log</fileNamePattern>
<!-- 可选节点,控制保留的归档文件的最大数量,超出数量就删除旧文件假设设置每个月滚动,且<maxHistory>是6,
则只保存最近6个月的文件,删除之前的旧文件。注意,删除旧文件是,那些为了归档而创建的目录也会被删除-->
<maxHistory>${maxHistory}</maxHistory>
</rollingPolicy>
<!-- 按照固定窗口模式生成日志文件,当文件大于20MB时,生成新的日志文件。窗口大小是1到3,当保存了3个归档文件后,将覆盖最早的日志。
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/.log.zip</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>3</maxIndex>
</rollingPolicy> -->
<!-- 查看当前活动文件的大小,如果超过指定大小会告知RollingFileAppender 触发当前活动文件滚动
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>5MB</maxFileSize>
</triggeringPolicy> -->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>
<!-- WARN级别日志 appender -->
<appender name="WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 过滤器,只记录WARN级别的日志 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/mysql-boot-warn-log.log
</fileNamePattern>
<maxHistory>${maxHistory}</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>
<!-- INFO级别日志 appender -->
<appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 过滤器,只记录INFO级别的日志 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/myql-boot-info-log.log
</fileNamePattern>
<maxHistory>${maxHistory}</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>
<!-- DEBUG级别日志 appender -->
<appender name="DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--过滤器,仅记录DEBUG级别的日志 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>DEBUG</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/mysql-boot-debug-log.log
</fileNamePattern>
<maxHistory>${maxHistory}</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>
<!-- 需要记录日志的包 -->
<logger name="java.sql.PreparedStatement" value="DEBUG" />
<logger name="java.sql.Connection" value="DEBUG" />
<logger name="java.sql.Statement" value="DEBUG" />
<logger name="com.ibatis" value="DEBUG" />
<logger name="com.ibatis.common.jdbc.SimpleDataSource" value="DEBUG" />
<logger name="com.ibatis.common.jdbc.ScriptRunner" level="DEBUG"/>
<logger name="com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate" value="DEBUG" />
<logger name="org.springframework.web" level="DEBUG"/>
<logger name="com.zzg" level="DEBUG"/>
<!-- root级别 DEBUG -->
<root level="INFO">
<!-- 控制台输出 -->
<appender-ref ref="STDOUT" />
<!-- 文件输出 -->
<appender-ref ref="ERROR" />
<appender-ref ref="INFO" />
<appender-ref ref="WARN" />
<appender-ref ref="DEBUG" />
</root>
</configuration>
SpringBoot 程序入口:
package com.zzg;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;
@SpringBootApplication
@MapperScan("com.zzg.mapper")
public class Application {
public static void main(String[] args) {
// TODO Auto-generated method stub
SpringApplication.run(Application.class, args);
}
}
核心业务层:自行编写