implements SysUserRolesService {
19 | @Autowired
20 | private SysUserRolesRepository sysUserRolesRepository;
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | # 数据库配置
3 | redis:
4 | # redis数据库索引(默认为0),我们使用索引为3的数据库,避免和其他数据库冲突
5 | database: 3
6 | # redis服务器地址(默认为localhost)
7 | host: localhost
8 | # redis端口(默认为6379)
9 | port: 6379
10 | # redis访问密码(默认为空)
11 | password:
12 | # redis连接超时时间(单位为毫秒)
13 | timeout: 0
14 | # redis连接池配置
15 | pool:
16 | # 最大可用连接数(默认为8,负数表示无限)
17 | max-active: 8
18 | # 最大空闲连接数(默认为8,负数表示无限)
19 | max-idle: 8
20 | # 最小空闲连接数(默认为0,该值只有为正数才有作用)
21 | min-idle: 0
22 | # 从连接池中获取连接最大等待时间(默认为-1,单位为毫秒,负数表示无限)
23 | max-wait: -1
24 | jackson:
25 | default-property-inclusion: non_null
26 | datasource:
27 | driver-class-name: org.gjt.mm.mysql.Driver
28 | url: jdbc:mysql://localhost:3306/gwf?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=true
29 | username: root
30 | password: root
31 |
32 | # 服务器配置
33 | server:
34 | port: 9999
35 | context-path: /
36 |
37 | # mybatis配置
38 | mybatis:
39 | # 配置映射类所在包名
40 | # type-aliases-package: com.gwf.family.business.domain
41 | # 配置mapper xml文件所在路径,这里是一个数组
42 | mapper-locations:
43 | - mappers/**/*.xml
44 |
45 | mapper:
46 | mappers:
47 | - com.gwf.family.business.core.mapper.Mapper
48 | not-empty: false
49 | identity: MYSQL
50 |
51 | pagehelper:
52 | helperDialect: mysql
53 | reasonable: true
54 | supportMethodsArguments: true
55 | params: count=countSql
56 | logging:
57 | level:
58 | com.gwf.family: trace
59 |
60 | jwt:
61 | header: Authorization
62 | secret: mySecret
63 | expiration: 604800
64 | tokenHead: "Bearer "
65 | route:
66 | authentication:
67 | path: auth
68 | refresh: refresh
69 | register: "auth/register"
70 |
71 | #druid:
72 | # url: jdbc:mysql://localhost:3306/gwf?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
73 | # username: root
74 | # password: root
75 | # initial-size: 1
76 | # min-idle: 1
77 | # max-active: 20
78 | # test-on-borrow: true
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/src/main/resources/application-pro.yml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkGao11520/spring-boot-mybatis-with-redis/b5b08d407cb15f8a488c852d63278390a31d5945/src/main/resources/application-pro.yml
--------------------------------------------------------------------------------
/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | profiles:
3 | active: dev
4 | mvc:
5 | throw-exception-if-no-handler-found: true
6 | resources:
7 | add-mappings: false
--------------------------------------------------------------------------------
/src/main/resources/codeftl/controller.ftl:
--------------------------------------------------------------------------------
1 | package ${basePackage}.controller;
2 | import ${corePackage}.results.Result;
3 | import ${corePackage}.results.ResultGenerator;
4 | import ${basePackage}.entity.${table.entityName};
5 | import ${basePackage}.service.${table.entityName}Service;
6 | import com.github.pagehelper.PageHelper;
7 | import com.github.pagehelper.PageInfo;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.web.bind.annotation.*;
10 | import io.swagger.annotations.*;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | * Created by ${author} on ${.now}.
16 | */
17 | @RestController
18 | @RequestMapping("${table.mappingPath}")
19 | public class ${table.entityName}Controller {
20 | @Autowired
21 | private ${table.entityName}Service ${table.entityName?uncap_first}Service;
22 |
23 | @PostMapping
24 | @ApiOperation("添加${table.entityName}")
25 | public Result add(${table.entityName} ${table.entityName?uncap_first}) {
26 | ${table.entityName?uncap_first}Service.save(${table.entityName?uncap_first});
27 | return ResultGenerator.genSuccessResult();
28 | }
29 |
30 | @DeleteMapping("/{id:\\d+}")
31 | @ApiOperation("删除${table.entityName}")
32 | public Result delete(@ApiParam(value = "${table.remarks}id") @PathVariable Integer id) {
33 | ${table.entityName?uncap_first}Service.deleteById(id);
34 | return ResultGenerator.genSuccessResult();
35 | }
36 |
37 | @PutMapping("/{id:\\d+}")
38 | @ApiOperation("修改${table.entityName}")
39 | public Result update(${table.entityName} ${table.entityName?uncap_first}) {
40 | ${table.entityName?uncap_first}Service.update(${table.entityName?uncap_first});
41 | return ResultGenerator.genSuccessResult();
42 | }
43 |
44 | @GetMapping("/{id:\\d+}")
45 | @ApiOperation("${table.entityName}根据id查询详情")
46 | public Result detail(@ApiParam(value = "${table.remarks}id")@PathVariable Integer id) {
47 | ${table.entityName} ${table.entityName?uncap_first} = ${table.entityName?uncap_first}Service.findById(id);
48 | return ResultGenerator.genSuccessResult(${table.entityName?uncap_first});
49 | }
50 |
51 | @GetMapping
52 | @ApiOperation("${table.entityName}分页查询列表")
53 | public Result list(@ApiParam(value = "页数")@RequestParam(name = "page",defaultValue = "1") Integer page,
54 | @ApiParam(value = "每页行数")@RequestParam(name = "size",defaultValue = "10") Integer size) {
55 | PageHelper.startPage(page, size);
56 | List<${table.entityName}> list = ${table.entityName?uncap_first}Service.findAll();
57 | PageInfo pageInfo = new PageInfo(list);
58 | return ResultGenerator.genSuccessResult(pageInfo);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/resources/codeftl/entity.ftl:
--------------------------------------------------------------------------------
1 | package ${basePackage}.entity;
2 |
3 | import lombok.Data;
4 | import lombok.NoArgsConstructor;
5 | import lombok.AllArgsConstructor;
6 |
7 | import javax.persistence.*;
8 | import java.math.BigDecimal;
9 | import java.math.BigInteger;
10 | import java.io.Serializable;
11 | import java.util.Date;
12 | import java.util.List;
13 | import io.swagger.annotations.*;
14 |
15 | /**
16 | * Created with ${author} on ${.now}.
17 | */
18 | @Entity
19 | @Data
20 | @Table(name = "${table.tableName}")
21 | @NoArgsConstructor
22 | @AllArgsConstructor
23 | public class ${table.entityName} implements Serializable{
24 |
25 | <#list table.columnModels as item>
26 | /** ${item.remarks} */
27 | <#if item.isKey>
28 | @Id
29 | #if>
30 | @ApiModelProperty(value = "${item.remarks}")
31 | private ${item.javaType} ${item.columnNameLowerCamel};
32 | #list>
33 |
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/src/main/resources/codeftl/mapper.ftl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | <#list table.columnModels as item>
6 | <#if item.isKey>
7 |
8 | #if>
9 | <#if !item.isKey>
10 |
11 | #if>
12 | #list>
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/main/resources/codeftl/repository.ftl:
--------------------------------------------------------------------------------
1 | package ${basePackage}.dao;
2 |
3 | import ${corePackage}.mapper.Mapper;
4 | import ${basePackage}.entity.${table.entityName};
5 |
6 | /**
7 | * Created with ${author} on ${.now}.
8 | */
9 | @org.apache.ibatis.annotations.Mapper
10 | public interface ${table.entityName}Repository extends Mapper<${table.entityName}> {
11 |
12 | }
13 |
14 |
--------------------------------------------------------------------------------
/src/main/resources/codeftl/service.ftl:
--------------------------------------------------------------------------------
1 | package ${basePackage}.service;
2 | import ${basePackage}.entity.${table.entityName};
3 | import ${corePackage}.service.Service;
4 |
5 |
6 | /**
7 | * Created by ${author} on ${.now}.
8 | */
9 | public interface ${table.entityName}Service extends Service<${table.entityName}> {
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/resources/codeftl/serviceimpl.ftl:
--------------------------------------------------------------------------------
1 | package ${basePackage}.service.impl;
2 |
3 | import ${basePackage}.dao.${table.entityName}Repository;
4 | import ${basePackage}.entity.${table.entityName};
5 | import ${basePackage}.service.${table.entityName}Service;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import ${corePackage}.service.AbstractService;
8 | import org.springframework.stereotype.Service;
9 | import org.springframework.transaction.annotation.Transactional;
10 |
11 |
12 |
13 | /**
14 | * Created by ${author} on ${.now}.
15 | */
16 | @Service
17 | @Transactional
18 | public class ${table.entityName}ServiceImpl extends AbstractService<${table.entityName}> implements ${table.entityName}Service {
19 | @Autowired
20 | private ${table.entityName}Repository ${table.entityName?uncap_first}Repository;
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/resources/logback-spring.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | %d - %msg%n
9 |
10 |
11 |
12 |
13 |
14 |
15 | ERROR
16 | DENY
17 | ACCEPT
18 |
19 |
20 |
21 | %msg%n
22 |
23 |
24 |
25 |
26 |
27 | /Users/gaowenfeng/documents/tomcat/sell/info.%d.log
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ERROR
36 |
37 |
38 |
39 | %msg%n
40 |
41 |
42 |
43 |
44 |
45 | /Users/gaowenfeng/documents/sell/error.%d.log
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/src/main/resources/mappers/sys/role/mapper/SysRoleMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/main/resources/mappers/sys/user/mapper/SysUserMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/main/resources/mappers/sys/userroles/mapper/SysUserRolesMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/main/resources/static/connect.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by gaowenfeng on 2017/7/13.
3 | */
4 | function connect() {
5 | $.ajax({
6 | type: 'post',
7 | url: './code/connectDb',
8 | data: {
9 | ip: $('#ip').val(),
10 | db: $('#db').val(),
11 | port: $('#port').val(),
12 | dbName: $('#dbName').val(),
13 | username: $('#username').val(),
14 | password: $('#password').val()
15 | },
16 | success: function (result) {
17 | if(result.code==200){
18 | alert("连接成功");
19 | var str = '
';
20 | var list = result.data;
21 | for (var i = 0; i < list.length; i++)
22 | str += (list[i].tableName+': ');
23 | $('#tableDiv').append(str);
24 | }
25 | },
26 | error: function (error) {
27 | alert(JSON.stringify(error));
28 | }
29 | })
30 | }
31 |
32 | function generate() {
33 | var str = "";
34 | var j = 0
35 | for (var i = 0; i < document.getElementsByName('table').length; i++) {
36 | if (document.getElementsByName('table')[i].checked) {
37 | if (j == 0)
38 | str += document.getElementsByName('table')[i].value;
39 | else
40 | str += "," +document.getElementsByName('table')[i].value;
41 | j++;
42 | }
43 | }
44 | if (str == "") {
45 | alert("您没有选择任何数据");
46 | } else {
47 | window.location.href = './code/constructCode?ip=' + $('#ip').val() + '&db=' + $('#db').val() + '&port=' + $('#port').val() + '&dbName=' + $('#dbName').val() + '&username=' + $('#username').val() + '&password=' + $('#password').val() + '&tables=' + str + '&basePackage=' + $('#basepackage').val()+'&author='+$('#author').val();
48 | }
49 | }
--------------------------------------------------------------------------------
/src/main/resources/templates/connect.ftl:
--------------------------------------------------------------------------------
1 |
2 |
3 | 代码生成
4 |
5 |
6 | ip:
7 | db:
12 | port:
13 | dbName:
14 | username:
15 | password:
16 |
17 |
18 |
19 | basepackage:
20 | author:
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/test/java/com/gwf/family/SpringBootMybatisWithRedisApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.gwf.family;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.springframework.boot.test.context.SpringBootTest;
7 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
8 | import org.springframework.test.context.ActiveProfiles;
9 | import org.springframework.test.context.junit4.SpringRunner;
10 |
11 |
12 | @RunWith(SpringRunner.class)
13 | @SpringBootTest
14 | @Slf4j
15 | public class SpringBootMybatisWithRedisApplicationTests {
16 |
17 | @Test
18 | public void testEncoder(){
19 | BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
20 | log.info(encoder.encode("123"));
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/test/java/com/gwf/family/business/core/service/JwtUserDetailServiceImplTest.java:
--------------------------------------------------------------------------------
1 | package com.gwf.family.business.core.service;
2 |
3 | import com.gwf.family.SpringBootMybatisWithRedisApplication;
4 | import com.gwf.family.business.core.entity.JwtUser;
5 | import com.gwf.family.sys.user.entity.SysUser;
6 | import org.junit.Assert;
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.boot.test.context.SpringBootTest;
11 | import org.springframework.security.core.userdetails.UserDetails;
12 | import org.springframework.test.context.junit4.SpringRunner;
13 |
14 | import static org.junit.Assert.*;
15 |
16 | /**
17 | * Created by gaowenfeng on 2017/8/10.
18 | */
19 | @RunWith(SpringRunner.class)
20 | @SpringBootTest
21 | public class JwtUserDetailServiceImplTest{
22 |
23 | @Autowired
24 | private JwtUserDetailServiceImpl jwtUserDetailService;
25 |
26 | @Test
27 | public void loadUserByUsername() throws Exception {
28 | UserDetails jwtUser = jwtUserDetailService.loadUserByUsername("gwf");
29 | Assert.assertNotNull(jwtUser);
30 | }
31 |
32 | }
--------------------------------------------------------------------------------
/src/test/resources/sql/data.sql:
--------------------------------------------------------------------------------
1 | BEGIN;
2 |
3 | INSERT INTO `sys_role`
4 | VALUES
5 | ('1', 'ROLE_ADMIN'),
6 | ('2', 'ROLE_USER');
7 |
8 | INSERT INTO `sys_user`
9 | VALUES
10 | ('1', '$2a$10$NYw3YvE.XvF.hgMHfAoLo.KtMT6KpWKxNtoUhFZbM2zNuUyiJWcp2', 'gwf'),
11 | ('2', '$2a$10$NYw3YvE.XvF.hgMHfAoLo.KtMT6KpWKxNtoUhFZbM2zNuUyiJWcp2', 'jd'),
12 | ('3', '$2a$10$NYw3YvE.XvF.hgMHfAoLo.KtMT6KpWKxNtoUhFZbM2zNuUyiJWcp2', 'gzf');
13 |
14 | INSERT INTO `sys_user_roles`
15 | VALUES
16 | ('1', '1', '1');
17 |
18 | COMMIT;
--------------------------------------------------------------------------------
/src/test/resources/sql/schema.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE `sys_user` (
2 | `id` int(11) NOT NULL AUTO_INCREMENT,
3 | `password` varchar(256) COLLATE utf8_bin DEFAULT NULL,
4 | `username` varchar(256) COLLATE utf8_bin DEFAULT NULL,
5 | PRIMARY KEY (`id`)
6 | ) ENGINE=InnoDB AUTO_INCREMENT=44 DEFAULT CHARSET=utf8 COLLATE=utf8_bin
7 |
8 | CREATE TABLE `sys_role` (
9 | `id` int(11) NOT NULL AUTO_INCREMENT,
10 | `name` varchar(256) COLLATE utf8_bin DEFAULT NULL,
11 | PRIMARY KEY (`id`)
12 | ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_bin
13 |
14 | CREATE TABLE `sys_user_roles` (
15 | `user_id` int(11) NOT NULL,
16 | `role_id` int(11) NOT NULL,
17 | `id` int(11) NOT NULL AUTO_INCREMENT,
18 | PRIMARY KEY (`id`),
19 | KEY `FKdpvc6d7xqpqr43dfuk1s27cqh` (`role_id`),
20 | KEY `FKd0ut7sloes191bygyf7a3pk52` (`user_id`)
21 | ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin
--------------------------------------------------------------------------------