From 111cdcd4922d677733f47d9c63de007ac714a5d0 Mon Sep 17 00:00:00 2001 From: bseayin Date: Wed, 4 Sep 2019 21:41:56 +0800 Subject: [PATCH] authorization --- SpringBootMybatis/SpringBootMybatis.iml | 75 +++++++++++++++ SpringBootMybatis/pom.xml | 59 ++++++++++++ .../src/main/java/com/zz/util/DateUtil.java | 38 ++++++++ .../src/main/java/com/zz/util/KeyUtil.java | 17 ++++ .../resources/mapping/PermissionMapper.xml | 71 ++++++++++++++ .../src/main/resources/mapping/RoleMapper.xml | 71 ++++++++++++++ .../mapping/RolePermissionMapper.xml | 36 +++++++ .../src/main/resources/mapping/UserMapper.xml | 93 +++++++++++++++++++ .../main/resources/mapping/UserRoleMapper.xml | 36 +++++++ 9 files changed, 496 insertions(+) create mode 100644 SpringBootMybatis/SpringBootMybatis.iml create mode 100644 SpringBootMybatis/pom.xml create mode 100644 SpringBootMybatis/src/main/java/com/zz/util/DateUtil.java create mode 100644 SpringBootMybatis/src/main/java/com/zz/util/KeyUtil.java create mode 100644 SpringBootMybatis/src/main/resources/mapping/PermissionMapper.xml create mode 100644 SpringBootMybatis/src/main/resources/mapping/RoleMapper.xml create mode 100644 SpringBootMybatis/src/main/resources/mapping/RolePermissionMapper.xml create mode 100644 SpringBootMybatis/src/main/resources/mapping/UserMapper.xml create mode 100644 SpringBootMybatis/src/main/resources/mapping/UserRoleMapper.xml diff --git a/SpringBootMybatis/SpringBootMybatis.iml b/SpringBootMybatis/SpringBootMybatis.iml new file mode 100644 index 0000000..e8bd081 --- /dev/null +++ b/SpringBootMybatis/SpringBootMybatis.iml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SpringBootMybatis/pom.xml b/SpringBootMybatis/pom.xml new file mode 100644 index 0000000..aed5c01 --- /dev/null +++ b/SpringBootMybatis/pom.xml @@ -0,0 +1,59 @@ + + + + SpringBoot2 + zz + 0.0.1-SNAPSHOT + + 4.0.0 + + SpringBootMybatis + + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-devtools + true + + + + + mysql + mysql-connector-java + 8.0.15 + + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 1.3.1 + + + + + + + alimaven + aliyun maven + http://maven.aliyun.com/nexus/content/groups/public/ + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/SpringBootMybatis/src/main/java/com/zz/util/DateUtil.java b/SpringBootMybatis/src/main/java/com/zz/util/DateUtil.java new file mode 100644 index 0000000..c9e76fe --- /dev/null +++ b/SpringBootMybatis/src/main/java/com/zz/util/DateUtil.java @@ -0,0 +1,38 @@ +package com.zz.util; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class DateUtil { + + /** + * util date 转 sql date + * @param udate + * @return + */ + public static java.sql.Date tranceToSqlDate(Date udate){ + //转成sql date + return new java.sql.Date(udate.getTime()); + } + /** + * String to uitil Date + * "yyyy-MM-dd" + * @param str + * @return + */ + + public static Date tranceToDate(String str){ + SimpleDateFormat s=new SimpleDateFormat("yyyy-MM-dd"); + Date d1=null; + try { + d1=s.parse(str); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return d1; + } + +} diff --git a/SpringBootMybatis/src/main/java/com/zz/util/KeyUtil.java b/SpringBootMybatis/src/main/java/com/zz/util/KeyUtil.java new file mode 100644 index 0000000..aeac43a --- /dev/null +++ b/SpringBootMybatis/src/main/java/com/zz/util/KeyUtil.java @@ -0,0 +1,17 @@ +package com.zz.util; +import java.util.Random; + +public class KeyUtil { + + /** + * 生成唯一的主键 + * 格式: 时间+随机数 + * @return + */ + public static String genUniqueKey() { + Random random = new Random(); + Integer number = random.nextInt(900000) + 100000; + + return System.currentTimeMillis() + String.valueOf(number); + } +} diff --git a/SpringBootMybatis/src/main/resources/mapping/PermissionMapper.xml b/SpringBootMybatis/src/main/resources/mapping/PermissionMapper.xml new file mode 100644 index 0000000..4862cba --- /dev/null +++ b/SpringBootMybatis/src/main/resources/mapping/PermissionMapper.xml @@ -0,0 +1,71 @@ + + + + + + + + + + id, name, url + + + + delete from t_permission + where id = #{id,jdbcType=VARCHAR} + + + insert into t_permission (id, name, url + ) + values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR} + ) + + + insert into t_permission + + + id, + + + name, + + + url, + + + + + #{id,jdbcType=VARCHAR}, + + + #{name,jdbcType=VARCHAR}, + + + #{url,jdbcType=VARCHAR}, + + + + + update t_permission + + + name = #{name,jdbcType=VARCHAR}, + + + url = #{url,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=VARCHAR} + + + update t_permission + set name = #{name,jdbcType=VARCHAR}, + url = #{url,jdbcType=VARCHAR} + where id = #{id,jdbcType=VARCHAR} + + \ No newline at end of file diff --git a/SpringBootMybatis/src/main/resources/mapping/RoleMapper.xml b/SpringBootMybatis/src/main/resources/mapping/RoleMapper.xml new file mode 100644 index 0000000..6e32515 --- /dev/null +++ b/SpringBootMybatis/src/main/resources/mapping/RoleMapper.xml @@ -0,0 +1,71 @@ + + + + + + + + + + id, detail, name + + + + delete from t_role + where id = #{id,jdbcType=VARCHAR} + + + insert into t_role (id, detail, name + ) + values (#{id,jdbcType=VARCHAR}, #{detail,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR} + ) + + + insert into t_role + + + id, + + + detail, + + + name, + + + + + #{id,jdbcType=VARCHAR}, + + + #{detail,jdbcType=VARCHAR}, + + + #{name,jdbcType=VARCHAR}, + + + + + update t_role + + + detail = #{detail,jdbcType=VARCHAR}, + + + name = #{name,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=VARCHAR} + + + update t_role + set detail = #{detail,jdbcType=VARCHAR}, + name = #{name,jdbcType=VARCHAR} + where id = #{id,jdbcType=VARCHAR} + + \ No newline at end of file diff --git a/SpringBootMybatis/src/main/resources/mapping/RolePermissionMapper.xml b/SpringBootMybatis/src/main/resources/mapping/RolePermissionMapper.xml new file mode 100644 index 0000000..0cd0dff --- /dev/null +++ b/SpringBootMybatis/src/main/resources/mapping/RolePermissionMapper.xml @@ -0,0 +1,36 @@ + + + + + + + + + delete from t_role_permission + where r_id = #{rId,jdbcType=VARCHAR} + and p_id = #{pId,jdbcType=VARCHAR} + + + insert into t_role_permission (r_id, p_id) + values (#{rId,jdbcType=VARCHAR}, #{pId,jdbcType=VARCHAR}) + + + insert into t_role_permission + + + r_id, + + + p_id, + + + + + #{rId,jdbcType=VARCHAR}, + + + #{pId,jdbcType=VARCHAR}, + + + + \ No newline at end of file diff --git a/SpringBootMybatis/src/main/resources/mapping/UserMapper.xml b/SpringBootMybatis/src/main/resources/mapping/UserMapper.xml new file mode 100644 index 0000000..54a2350 --- /dev/null +++ b/SpringBootMybatis/src/main/resources/mapping/UserMapper.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + id, create_time, passwd, status, username + + + + delete from t_user + where id = #{id,jdbcType=VARCHAR} + + + insert into t_user (id, create_time, passwd, + status, username) + values (#{id,jdbcType=VARCHAR}, #{createTime,jdbcType=DATE}, #{passwd,jdbcType=VARCHAR}, + #{status,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}) + + + insert into t_user + + + id, + + + create_time, + + + passwd, + + + status, + + + username, + + + + + #{id,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=DATE}, + + + #{passwd,jdbcType=VARCHAR}, + + + #{status,jdbcType=VARCHAR}, + + + #{username,jdbcType=VARCHAR}, + + + + + update t_user + + + create_time = #{createTime,jdbcType=DATE}, + + + passwd = #{passwd,jdbcType=VARCHAR}, + + + status = #{status,jdbcType=VARCHAR}, + + + username = #{username,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=VARCHAR} + + + update t_user + set create_time = #{createTime,jdbcType=DATE}, + passwd = #{passwd,jdbcType=VARCHAR}, + status = #{status,jdbcType=VARCHAR}, + username = #{username,jdbcType=VARCHAR} + where id = #{id,jdbcType=VARCHAR} + + \ No newline at end of file diff --git a/SpringBootMybatis/src/main/resources/mapping/UserRoleMapper.xml b/SpringBootMybatis/src/main/resources/mapping/UserRoleMapper.xml new file mode 100644 index 0000000..86cf468 --- /dev/null +++ b/SpringBootMybatis/src/main/resources/mapping/UserRoleMapper.xml @@ -0,0 +1,36 @@ + + + + + + + + + delete from t_user_role + where u_id = #{uId,jdbcType=VARCHAR} + and r_id = #{rId,jdbcType=VARCHAR} + + + insert into t_user_role (u_id, r_id) + values (#{uId,jdbcType=VARCHAR}, #{rId,jdbcType=VARCHAR}) + + + insert into t_user_role + + + u_id, + + + r_id, + + + + + #{uId,jdbcType=VARCHAR}, + + + #{rId,jdbcType=VARCHAR}, + + + + \ No newline at end of file