implements IUserService {
25 |
26 | @Resource
27 | private UserMapper userMapper;
28 |
29 | @Override
30 | public void test() {
31 | log.info("我是[{}]", this.getClass().getName());
32 | }
33 |
34 | @Override
35 | public void testDoubleIf(Integer code) {
36 | log.info("结果为[{}]",userMapper.testDoubleIf(code));
37 | }
38 |
39 | @Override
40 | public void testDoubleIf(Integer code, Integer code2) {
41 | log.info("结果为[{}]",userMapper.testDoubleIf1(code, code2));
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/lsb-crub/src/main/java/com/example/crud/util/Component.java:
--------------------------------------------------------------------------------
1 | package com.example.crud.util;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Getter;
5 |
6 | @Getter
7 | @AllArgsConstructor
8 | public enum Component {
9 | RED("红色", "1"), GREEN("绿色", "2"), BLANK("白色", "3"), YELLO("黄色", "4");
10 | private String msg;
11 |
12 | private String code;
13 |
14 |
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/lsb-crub/src/main/java/com/example/crud/util/Config.java:
--------------------------------------------------------------------------------
1 | package com.example.crud.util;
2 |
3 | import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.transaction.annotation.EnableTransactionManagement;
7 |
8 | /**
9 | * @Description: 配置 mybatisplus 的分页
10 | * @Author: boolean
11 | * @Date: 2020/1/6 0:07
12 | */
13 | @EnableTransactionManagement
14 | @Configuration
15 | public class Config {
16 | @Bean
17 | public PaginationInterceptor paginationInterceptor() {
18 | PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
19 | // 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求 默认false
20 | // paginationInterceptor.setOverflow(false);
21 | // 设置最大单页限制数量,默认 500 条,-1 不受限制
22 | // paginationInterceptor.setLimit(500);
23 | return paginationInterceptor;
24 | }
25 | }
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/lsb-crub/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | datasource:
3 | url: jdbc:mysql://127.0.0.1/test?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&autoReconnect=true&serverTimezone=Asia/Shanghai&useSSL=false
4 | username: root
5 | password: 123456
6 | driver-class-name: com.mysql.jdbc.Driver
7 | thymeleaf:
8 | cache: false
9 | prefix: classpath:/templates/
10 | check-template-location: true
11 | suffix: .html
12 | encoding: utf-8
13 | servlet:
14 | content-type: text/html
15 | mode: HTML5
16 | logging:
17 | level:
18 | com.example.crud.mapper: debug # 改成你的mapper文件所在包路径
--------------------------------------------------------------------------------
/lsb-crub/src/main/resources/banner.txt:
--------------------------------------------------------------------------------
1 | ${AnsiColor.BRIGHT_YELLOW}
2 | ////////////////////////////////////////////////////////////////////
3 | // _ooOoo_ //
4 | // o8888888o //
5 | // 88" . "88 //
6 | // (| ^_^ |) //
7 | // O\ = /O //
8 | // ____/`---'\____ //
9 | // .' \\| |// `. //
10 | // / \\||| : |||// \ //
11 | // / _||||| -:- |||||- \ //
12 | // | | \\\ - /// | | //
13 | // | \_| ''\---/'' | | //
14 | // \ .-\__ `-` ___/-. / //
15 | // ___`. .' /--.--\ `. . ___ //
16 | // ."" '< `.___\_<|>_/___.' >'"". //
17 | // | | : `- \`.;`\ _ /`;.`/ - ` : | | //
18 | // \ \ `-. \_ __\ /__ _/ .-` / / //
19 | // ========`-.____`-.___\_____/___.-`____.-'======== //
20 | // `=---=' //
21 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
22 | // 佛祖保佑 永不宕机 永无BUG //
23 | ////////////////////////////////////////////////////////////////////
--------------------------------------------------------------------------------
/lsb-crub/src/main/resources/templates/edit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | hello
5 |
6 |
7 |
8 |
9 |
10 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/lsb-crub/src/main/resources/templates/list.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | hello
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | id |
13 | 姓名 |
14 | 年龄 |
15 | 邮箱 |
16 | 编辑 |
17 | 删除 |
18 |
19 |
20 | |
21 | |
22 | |
23 | |
24 | 编辑 |
25 | 删除 |
26 |
27 |
28 |
29 |
34 |
35 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/lsb-crub/src/test/java/com/example/crud/AsyncTest.java:
--------------------------------------------------------------------------------
1 | package com.example.crud;
2 |
3 | import com.example.crud.entity.Name;
4 | import com.example.crud.entity.User;
5 | import com.example.crud.service.AsyncService;
6 | import com.example.crud.service.INameService;
7 | import com.example.crud.service.impl.CompentServiceImplTotal;
8 | import com.example.crud.service.impl.TestService;
9 | import com.example.crud.service.impl.UserJDBCServiceImpl;
10 | import lombok.extern.slf4j.Slf4j;
11 | import org.junit.Test;
12 | import org.junit.runner.RunWith;
13 | import org.springframework.beans.factory.annotation.Autowired;
14 | import org.springframework.boot.test.context.SpringBootTest;
15 | import org.springframework.test.context.junit4.SpringRunner;
16 | import org.springframework.transaction.annotation.Transactional;
17 |
18 | /**
19 | * @Author buerbl
20 | * @create 2020/9/10 13:02
21 | */
22 | @Slf4j
23 | @RunWith(SpringRunner.class)
24 | @SpringBootTest
25 | //@Transactional
26 |
27 | public class AsyncTest {
28 | @Autowired
29 | private TestService test;
30 |
31 | @Autowired
32 | private INameService nameService;
33 |
34 | @Test
35 | public void test() {
36 | try {
37 | test.test();
38 | } catch (Exception e) {
39 | log.error("错误为[{}] ", e);
40 | }
41 | }
42 |
43 | @Test
44 | public void test1(){
45 | Name name = new Name();
46 | name.setId(1);
47 | nameService.getById(name);
48 | }
49 |
50 | @Test
51 | public void test2(){
52 | Name name = new Name();
53 | name.setId(19);
54 | name.setName("wen61123");
55 | // nameService.localUpdate(name);
56 | test.test1(name);
57 | }
58 |
59 | @Autowired
60 | private CompentServiceImplTotal compentServiceImplTotal;
61 | @Test
62 | public void testStrategy(){
63 | compentServiceImplTotal.strategySelect("compentServiceImplTwo").test("123");
64 | }
65 |
66 | @Autowired
67 | private UserJDBCServiceImpl userJDBCService;
68 | @Test
69 | public void testJdbc(){
70 |
71 | // add
72 | userJDBCService.addUser();
73 |
74 | // get
75 |
76 | // String user = userJDBCService.getUser();
77 | // System.out.println(user);
78 |
79 |
80 | }
81 |
82 | @Test
83 | public void testshiwu(){
84 | int a= 0;
85 | System.out.println(2 / a);
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/lsb-crub/src/test/java/com/example/crud/Clothes.java:
--------------------------------------------------------------------------------
1 | package com.example.crud;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class Clothes {
7 | private String color;
8 | }
9 |
--------------------------------------------------------------------------------
/lsb-crub/src/test/java/com/example/crud/Clothes1.java:
--------------------------------------------------------------------------------
1 | package com.example.crud;
2 |
3 | public class Clothes1 {
4 | private String color;
5 | }
6 |
--------------------------------------------------------------------------------
/lsb-crub/src/test/java/com/example/crud/CrudApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.example.crud;
2 |
3 | import com.example.crud.mapper.UserMapper;
4 | import com.example.crud.service.INameService;
5 | import com.example.crud.service.IUserService;
6 | import com.example.crud.service.impl.NameServiceImpl;
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.test.context.junit4.SpringRunner;
12 | import org.springframework.util.StopWatch;
13 |
14 | import javax.annotation.Resource;
15 |
16 | @RunWith(SpringRunner.class)
17 | @SpringBootTest
18 | public class CrudApplicationTest {
19 |
20 | @Autowired
21 | private IUserService userService;
22 |
23 |
24 | @Resource
25 | private UserMapper userMapper;
26 |
27 | @Resource
28 | private INameService nameService;
29 |
30 | @Test
31 | public void testDoubleIf() {
32 | userService.testDoubleIf(2);
33 | }
34 |
35 | @Test
36 | public void test() {
37 | userService.test();
38 | }
39 |
40 | @Test
41 | public void test3() {
42 | StopWatch sw = new StopWatch();
43 |
44 | sw.start("校验耗时");
45 | try {
46 | Thread.sleep(1000);
47 | } catch (InterruptedException e) {
48 | e.printStackTrace();
49 | }
50 | sw.stop();
51 |
52 | sw.start("组装报文耗时");
53 |
54 | sw.start("请求耗时");
55 | try {
56 | Thread.sleep(1000);
57 | } catch (InterruptedException e) {
58 | e.printStackTrace();
59 | }
60 | sw.stop();
61 |
62 | System.out.println(sw.getTotalTimeMillis());
63 | }
64 |
65 |
66 | @Test
67 | public void testStringForLong(){
68 | userMapper.testStringForLong(2L);
69 | }
70 |
71 |
72 | @Test
73 | public void testTransaction(){
74 | userMapper.testDoubleIf1(2, 3);
75 | }
76 |
77 | @Test
78 | public void testInsert(){
79 | nameService.AddName();
80 | }
81 | }
--------------------------------------------------------------------------------
/lsb-crub/src/test/java/com/example/crud/Test.java:
--------------------------------------------------------------------------------
1 | package com.example.crud;
2 |
3 | import org.springframework.util.StopWatch;
4 |
5 | import java.util.LinkedList;
6 |
7 | /**
8 | * @Author buerbl
9 | * @create 2020/8/20 15:03
10 | */
11 | public class Test {
12 | public static void main(String[] args) throws InterruptedException {
13 | LinkedList linkedList = null;
14 | for (Integer a : linkedList){
15 |
16 | }
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/lsb-crub/src/test/java/com/example/crud/User.java:
--------------------------------------------------------------------------------
1 | package com.example.crud;
2 |
3 | import com.alibaba.fastjson.JSON;
4 | import lombok.Data;
5 | import lombok.extern.slf4j.Slf4j;
6 | import org.junit.Test;
7 | import org.springframework.beans.BeanUtils;
8 |
9 | import java.util.List;
10 | @Slf4j
11 | @Data
12 | public class User {
13 | private Integer sex;
14 | private String name;
15 | private List clothesList;
16 |
17 |
18 | @Test
19 | public void test() {
20 | User user = JSON.parseObject(" {\n" +
21 | " \"sex\": 0,\n" +
22 | " \"name\": \"chen\",\n" +
23 | " \"clothesList\": [\n" +
24 | " {\n" +
25 | " \"color\": \"red\"\n" +
26 | " }\n" +
27 | " ]\n" +
28 | " }", User.class);
29 | log.info(user.toString());
30 | log.info("==========================================");
31 | User1 target = new User1();
32 | BeanUtils.copyProperties(user, target);
33 | log.info(target.toString());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/lsb-crub/src/test/java/com/example/crud/User1.java:
--------------------------------------------------------------------------------
1 | package com.example.crud;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.List;
6 |
7 | @Data
8 | public class User1 {
9 | private Integer sex;
10 | private List clothesList;
11 | }
12 |
--------------------------------------------------------------------------------
/lsb-digui/src/main/java/com/example/lsbdigui/LsbDiguiApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbdigui;
2 |
3 | import org.mybatis.spring.annotation.MapperScan;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | @SpringBootApplication
8 | @MapperScan("com.example.lsbdigui.mapper")
9 | public class LsbDiguiApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(LsbDiguiApplication.class, args);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/lsb-digui/src/main/java/com/example/lsbdigui/ServletInitializer.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbdigui;
2 |
3 | import org.springframework.boot.builder.SpringApplicationBuilder;
4 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
5 |
6 | public class ServletInitializer extends SpringBootServletInitializer {
7 |
8 | @Override
9 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
10 | return application.sources(LsbDiguiApplication.class);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/lsb-digui/src/main/java/com/example/lsbdigui/controller/DiguiController.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbdigui.controller;
2 |
3 |
4 | import com.example.lsbdigui.service.IDiguiService;
5 | import com.example.lsbdigui.util.Result;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 |
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 | /**
12 | *
13 | * 前端控制器
14 | *
15 | *
16 | * @author jobob
17 | * @since 2019-12-15
18 | */
19 | @RestController
20 | @RequestMapping("/digui")
21 | public class DiguiController {
22 | @Autowired
23 | private IDiguiService diguiService;
24 |
25 | @RequestMapping("/getAll")
26 | public Result getAll(){
27 | return Result.getResult(diguiService.getAll(0));
28 | }
29 |
30 | @RequestMapping("/getAllBySQL")
31 | public Result getAllBySQL(){
32 | return Result.getResult(diguiService.getAllBySQL(null));
33 | }
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/lsb-digui/src/main/java/com/example/lsbdigui/emum/ResultEnum.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbdigui.emum;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Getter;
5 |
6 | /**
7 | * @Description:
8 | * @Author: boolean
9 | * @Date: 2019/12/9 23:37
10 | */
11 | @Getter
12 | @AllArgsConstructor
13 | public enum ResultEnum {
14 | RIGHT(200, "正确返回"),
15 | ERROR(404,"错误返回");
16 |
17 | private Integer code;
18 |
19 | private String msg;
20 | }
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/lsb-digui/src/main/java/com/example/lsbdigui/entity/Digui.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbdigui.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableField;
5 | import com.baomidou.mybatisplus.annotation.TableId;
6 | import java.io.Serializable;
7 | import java.util.List;
8 |
9 | import lombok.Data;
10 | import lombok.EqualsAndHashCode;
11 | import lombok.experimental.Accessors;
12 |
13 | /**
14 | *
15 | *
16 | *
17 | *
18 | * @author jobob
19 | * @since 2019-12-15
20 | */
21 | @Data
22 | @EqualsAndHashCode(callSuper = false)
23 | @Accessors(chain = true)
24 | public class Digui implements Serializable {
25 |
26 | private static final long serialVersionUID=1L;
27 |
28 | @TableId(value = "id", type = IdType.AUTO)
29 | private Integer id;
30 |
31 | /**
32 | * 评论的内容
33 | */
34 | private String msg;
35 |
36 | /**
37 | * 上一条
38 | */
39 | private Integer parentid;
40 |
41 | @TableField(exist = false)
42 | private List diguiList;
43 |
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/lsb-digui/src/main/java/com/example/lsbdigui/mapper/DiguiMapper.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbdigui.mapper;
2 |
3 | import com.example.lsbdigui.entity.Digui;
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 | import org.apache.ibatis.annotations.Mapper;
6 | import org.apache.ibatis.annotations.Param;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | *
12 | * Mapper 接口
13 | *
14 | *
15 | * @author jobob
16 | * @since 2019-12-15
17 | */
18 | public interface DiguiMapper extends BaseMapper {
19 |
20 | List getAllBySQL(@Param("parent")Integer parent);
21 | }
22 |
--------------------------------------------------------------------------------
/lsb-digui/src/main/java/com/example/lsbdigui/service/IDiguiService.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbdigui.service;
2 |
3 | import com.example.lsbdigui.entity.Digui;
4 | import com.baomidou.mybatisplus.extension.service.IService;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | *
10 | * 服务类
11 | *
12 | *
13 | * @author jobob
14 | * @since 2019-12-15
15 | */
16 | public interface IDiguiService extends IService {
17 |
18 | /**
19 | * 应用层按照顺序返回所有的内容
20 | * @return
21 | */
22 | List getAll(int parent);
23 |
24 |
25 | /**
26 | * SQL层按照顺序返回所有的内容
27 | * @return
28 | * @param parent
29 | */
30 | List getAllBySQL(Integer parent);
31 |
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/lsb-digui/src/main/java/com/example/lsbdigui/service/impl/DiguiServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbdigui.service.impl;
2 |
3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 | import com.example.lsbdigui.entity.Digui;
5 | import com.example.lsbdigui.mapper.DiguiMapper;
6 | import com.example.lsbdigui.service.IDiguiService;
7 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
8 | import org.springframework.stereotype.Service;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | /**
14 | *
15 | * 服务实现类
16 | *
17 | *
18 | * @author jobob
19 | * @since 2019-12-15
20 | */
21 | @Service
22 | public class DiguiServiceImpl extends ServiceImpl implements IDiguiService {
23 |
24 |
25 | //应用层递归查询
26 | @Override
27 | public List getAll(int parent) {
28 | List deptVosList=new ArrayList<>();
29 | QueryWrapper queryWrapper = new QueryWrapper();
30 | queryWrapper.eq("parentid", parent);
31 | List list1 = list(queryWrapper);
32 | for (Digui digui: list1) {
33 | Digui digui1 = new Digui();
34 | digui1.setId(digui.getId());
35 | digui1.setMsg(digui.getMsg());
36 | digui1.setParentid(digui.getParentid());
37 | digui1.setDiguiList(getAll(digui.getId()));
38 | deptVosList.add(digui1);
39 | }
40 | return deptVosList;
41 |
42 | }
43 |
44 | //SQL层递归查询
45 | @Override
46 | public List getAllBySQL(Integer parent) {
47 | return baseMapper.getAllBySQL(parent);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/lsb-digui/src/main/java/com/example/lsbdigui/util/DiguiException.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbdigui.util;
2 |
3 | /**
4 | * @Description:
5 | * @Author: boolean
6 | * @Date: 2019/12/10 0:41
7 | */
8 |
9 | public class DiguiException extends RuntimeException{
10 | public DiguiException(String msg){
11 | super(msg);
12 | }
13 | }
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/lsb-digui/src/main/java/com/example/lsbdigui/util/GlobalException.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbdigui.util;
2 |
3 | //import com.example.lsbdigui.emum.ResultEnum;
4 | import lombok.extern.slf4j.Slf4j;
5 |
6 | /**
7 | * @Description: 全局的异常返回
8 | * @Author: boolean
9 | * @Date: 2019/12/10 0:14
10 | */
11 | //@RestControllerAdvice
12 | @Slf4j
13 | public class GlobalException {
14 |
15 | // // 拦截器
16 | // @ExceptionHandler({Exception.class})
17 | // public Result exception(Exception e){
18 | // Result result = new Result();
19 | // result.setCode(ResultEnum.ERROR.getCode());
20 | // result.setMsg(ResultEnum.ERROR.getMsg());
21 | // result.setDate(e.toString());
22 | // log.error(e.toString());
23 | // return result;
24 | // }
25 |
26 |
27 | }
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/lsb-digui/src/main/java/com/example/lsbdigui/util/Result.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbdigui.util;
2 |
3 | import com.example.lsbcrudplus.emum.ResultEnum;
4 | import com.google.gson.Gson;
5 | import lombok.AllArgsConstructor;
6 | import lombok.Data;
7 |
8 | import java.util.LinkedList;
9 | import java.util.List;
10 |
11 | /**
12 | * @Description:
13 | * @Author: boolean
14 | * @Date: 2019/12/9 16:59
15 | */
16 | @Data
17 | public class Result {
18 |
19 | /**
20 | * 返回码
21 | */
22 | private Integer code;
23 |
24 | /**
25 | * 返回码状态
26 | */
27 | private String msg;
28 |
29 | /**
30 | * 返回数据
31 | */
32 | private Object date;
33 |
34 | public static Result getResult(Object date){
35 | Result result = new Result();
36 | // result.setCode(200);
37 | // result.setMsg("正确返回");
38 | result.setCode(ResultEnum.RIGHT.getCode());
39 | result.setMsg(ResultEnum.RIGHT.getMsg());
40 | result.setDate(date);
41 | return result;
42 | }
43 |
44 | public static void main(String[] args) {
45 | List person = new LinkedList<>();
46 | person.add("chen");
47 | person.add("wen");
48 | person.add("guan");
49 | Gson gson = new Gson();
50 | System.out.println(gson.toJson(getResult(person)));
51 | }
52 |
53 | @Data
54 | @AllArgsConstructor
55 | static class Person{
56 | private String name;
57 | private Integer code;
58 | }
59 |
60 | }
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/lsb-digui/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 |
2 | logging:
3 | level:
4 | com:
5 | example:
6 | lsbdigui:
7 | mapper: debug
8 | spring:
9 | datasource:
10 | url: jdbc:mysql://127.0.0.1:3306/dev?serverTimezone=GMT%2B8
11 | username: root
12 | password: 123456
13 | server:
14 | port: 8081
15 |
16 | mybatis:
17 | configuration:
18 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
--------------------------------------------------------------------------------
/lsb-digui/src/main/resources/mapper/DiguiMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
24 |
25 |
--------------------------------------------------------------------------------
/lsb-druid/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.11.RELEASE
9 |
10 |
11 | com.example
12 | lsb-druid
13 | 0.0.1-SNAPSHOT
14 | lsb-druid
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 |
26 |
27 |
28 | mysql
29 | mysql-connector-java
30 | runtime
31 |
32 |
33 | org.projectlombok
34 | lombok
35 | true
36 |
37 |
38 | org.springframework.boot
39 | spring-boot-starter-test
40 | test
41 |
42 |
43 | com.baomidou
44 | mybatis-plus-boot-starter
45 | 3.3.0
46 |
47 |
48 | com.alibaba
49 | druid-spring-boot-starter
50 | 1.1.17
51 |
52 |
53 |
54 |
55 |
56 |
57 | org.springframework.boot
58 | spring-boot-maven-plugin
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/lsb-druid/src/main/java/com/example/lsbdruid/LsbDruidApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbdruid;
2 |
3 | import org.mybatis.spring.annotation.MapperScan;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | @SpringBootApplication
8 | @MapperScan("com.example.lsbdruid.mapper")
9 | public class LsbDruidApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(LsbDruidApplication.class, args);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/lsb-druid/src/main/java/com/example/lsbdruid/controller/MyUserController.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbdruid.controller;
2 |
3 |
4 | import com.example.lsbdruid.entity.MyUser;
5 | import com.example.lsbdruid.service.IMyUserService;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 |
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | *
15 | * 前端控制器
16 | *
17 | *
18 | * @author jobob
19 | * @since 2020-01-15
20 | */
21 | @RestController
22 | @RequestMapping("/my-user")
23 | public class MyUserController {
24 | @Autowired
25 | private IMyUserService myUserService;
26 | @RequestMapping("/add")
27 | public String add(){
28 | MyUser myUser = new MyUser();
29 | myUser.setAge(18);
30 | myUser.setEmail("83");
31 | myUser.setName("布尔bl");
32 | return myUserService.save(myUser) ? "1": "0";
33 | }
34 |
35 | @RequestMapping("/get")
36 | public List get(){
37 | try {
38 | Thread.sleep(1000);
39 | } catch (InterruptedException e) {
40 | e.printStackTrace();
41 | }
42 | return myUserService.list();
43 | }
44 |
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/lsb-druid/src/main/java/com/example/lsbdruid/entity/MyUser.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbdruid.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import java.io.Serializable;
6 | import lombok.Data;
7 | import lombok.EqualsAndHashCode;
8 | import lombok.experimental.Accessors;
9 |
10 | /**
11 | *
12 | *
13 | *
14 | *
15 | * @author jobob
16 | * @since 2020-01-15
17 | */
18 | @Data
19 | @EqualsAndHashCode(callSuper = false)
20 | @Accessors(chain = true)
21 | public class MyUser implements Serializable {
22 |
23 | private static final long serialVersionUID=1L;
24 |
25 | /**
26 | * 主键ID
27 | */
28 | @TableId(value = "id", type = IdType.AUTO)
29 | private Long id;
30 |
31 | /**
32 | * 姓名
33 | */
34 | private String name;
35 |
36 | /**
37 | * 年龄
38 | */
39 | private Integer age;
40 |
41 | /**
42 | * 邮箱
43 | */
44 | private String email;
45 |
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/lsb-druid/src/main/java/com/example/lsbdruid/mapper/MyUserMapper.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbdruid.mapper;
2 |
3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 | import com.example.lsbdruid.entity.MyUser;
5 |
6 | /**
7 | *
8 | * Mapper 接口
9 | *
10 | *
11 | * @author jobob
12 | * @since 2020-01-15
13 | */
14 | public interface MyUserMapper extends BaseMapper {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/lsb-druid/src/main/java/com/example/lsbdruid/mapper/UserMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/lsb-druid/src/main/java/com/example/lsbdruid/service/IMyUserService.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbdruid.service;
2 |
3 | import com.baomidou.mybatisplus.extension.service.IService;
4 | import com.example.lsbdruid.entity.MyUser;
5 |
6 | public interface IMyUserService extends IService {
7 | }
8 |
--------------------------------------------------------------------------------
/lsb-druid/src/main/java/com/example/lsbdruid/service/impl/MyUserServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbdruid.service.impl;
2 |
3 | import com.example.lsbdruid.entity.MyUser;
4 | import com.example.lsbdruid.mapper.MyUserMapper;
5 | import com.example.lsbdruid.service.IMyUserService;
6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7 | import org.springframework.stereotype.Service;
8 |
9 | /**
10 | *
11 | * 服务实现类
12 | *
13 | *
14 | * @author jobob
15 | * @since 2020-01-15
16 | */
17 | @Service
18 | public class MyUserServiceImpl extends ServiceImpl implements IMyUserService {
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/lsb-druid/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | # 连接配置
2 | spring.datasource.druid.url= jdbc:mysql://ip/数据库
3 | spring.datasource.druid.username= *
4 | spring.datasource.druid.password= *
5 | spring.datasource.druid.driver-class-name= com.mysql.jdbc.Driver
6 |
7 | ## 连接池配置
8 | spring.datasource.druid.initial-size=5
9 | spring.datasource.druid.max-active=20
10 | spring.datasource.druid.min-idle=5
11 | spring.datasource.druid.max-wait=3000
12 | spring.datasource.druid.pool-prepared-statements=true
13 | spring.datasource.druid.max-pool-prepared-statement-per-connection-size=5
14 | # spring.datasource.druid.max-open-prepared-statements= #等价于上面的max-pool-prepared-statement-per-connection-size
15 | spring.datasource.druid.validation-query=select 1
16 | spring.datasource.druid.validation-query-timeout=1
17 | spring.datasource.druid.test-on-borrow=true
18 | spring.datasource.druid.test-on-return=true
19 | spring.datasource.druid.test-while-idle=true
20 | spring.datasource.druid.time-between-eviction-runs-millis=10000
21 | spring.datasource.druid.min-evictable-idle-time-millis=30001
22 | spring.datasource.druid.async-close-connection-enable=true
23 |
24 | # WebStatFilter配置,说明请参考Druid Wiki,配置_配置WebStatFilter
25 | spring.datasource.druid.web-stat-filter.enabled= true
26 | spring.datasource.druid.web-stat-filter.url-pattern=/*
27 | spring.datasource.druid.web-stat-filter.exclusions=*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*
28 |
29 |
30 | # StatViewServlet配置,说明请参考Druid Wiki,配置_StatViewServlet配置
31 | spring.datasource.druid.stat-view-servlet.enabled= true
32 | spring.datasource.druid.stat-view-servlet.url-pattern=/druid/*
33 | spring.datasource.druid.stat-view-servlet.reset-enable= false
34 | # 自定义
35 | spring.datasource.druid.stat-view-servlet.login-username=root
36 | spring.datasource.druid.stat-view-servlet.login-password=123
37 | # 显示sql统计
38 | spring.datasource.druid.filter.stat.enabled=true
39 | # Spring监控配置,说明请参考Druid Github Wiki,配置_Druid和Spring关联监控配置
40 | spring.datasource.druid.aop-patterns= com.example.lsbdruid.service.*
--------------------------------------------------------------------------------
/lsb-druid/src/main/resources/banner.txt:
--------------------------------------------------------------------------------
1 | ${AnsiColor.BRIGHT_YELLOW}
2 | ////////////////////////////////////////////////////////////////////
3 | // _ooOoo_ //
4 | // o8888888o //
5 | // 88" . "88 //
6 | // (| ^_^ |) //
7 | // O\ = /O //
8 | // ____/`---'\____ //
9 | // .' \\| |// `. //
10 | // / \\||| : |||// \ //
11 | // / _||||| -:- |||||- \ //
12 | // | | \\\ - /// | | //
13 | // | \_| ''\---/'' | | //
14 | // \ .-\__ `-` ___/-. / //
15 | // ___`. .' /--.--\ `. . ___ //
16 | // ."" '< `.___\_<|>_/___.' >'"". //
17 | // | | : `- \`.;`\ _ /`;.`/ - ` : | | //
18 | // \ \ `-. \_ __\ /__ _/ .-` / / //
19 | // ========`-.____`-.___\_____/___.-`____.-'======== //
20 | // `=---=' //
21 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
22 | // 佛祖保佑 永不宕机 永无BUG //
23 | ////////////////////////////////////////////////////////////////////
--------------------------------------------------------------------------------
/lsb-email/README.md:
--------------------------------------------------------------------------------
1 | >show me the code and talk to me,做的出来更要说的明白
2 | >我是布尔bl,你的支持是我分享的动力!
3 |
4 |
5 | ## 1 引入
6 |
7 | 简单送送邮件
8 |
9 | # 2 结构
10 | ```java
11 | ├─java
12 | │ └─com
13 | │ └─example
14 | │ └─lsbemail
15 | └─resources
16 | ├─static
17 | └─templates
18 | ```
19 | ## 3 maven
20 | ```java
21 |
22 | org.springframework.boot
23 | spring-boot-starter-mail
24 |
25 | ```
26 | ## 4 配置
27 |
28 | ```java
29 | ## 邮箱服务器地址
30 | spring.mail.host=smtp.163.com
31 | ## 用户名
32 | spring.mail.username=18319748706@163.com
33 | ##163的授权密码(需要额外获取)
34 | spring.mail.password=*
35 | spring.mail.default-encoding=utf-8
36 | ## 发送地址
37 | mail.sender=18319748706@163.com
38 | ## 接收地址
39 | mail.receiver=18319748706@163.com
40 | ```
41 |
42 | ## 5 发送
43 |
44 | ```java
45 | package com.example.lsbemail;
46 |
47 | import lombok.Data;
48 | import lombok.extern.slf4j.Slf4j;
49 | import org.springframework.beans.factory.annotation.Autowired;
50 | import org.springframework.beans.factory.annotation.Value;
51 | import org.springframework.boot.SpringApplication;
52 | import org.springframework.boot.autoconfigure.SpringBootApplication;
53 | import org.springframework.mail.SimpleMailMessage;
54 | import org.springframework.mail.javamail.JavaMailSender;
55 | import org.springframework.web.bind.annotation.RequestMapping;
56 | import org.springframework.web.bind.annotation.RestController;
57 |
58 | @SpringBootApplication
59 | @RestController
60 | @Slf4j
61 | @Data
62 | public class LsbEmailApplication {
63 |
64 | public static void main(String[] args) {
65 | SpringApplication.run(LsbEmailApplication.class, args);
66 | }
67 |
68 | @Value("${mail.sender}")
69 | private String sender;
70 |
71 | @Value("${mail.receiver}")
72 | private String receiver;
73 |
74 | @Autowired
75 | private JavaMailSender javaMailSender;
76 | @RequestMapping("/send")
77 | public void send(){
78 | String title = "文本邮件";
79 | String text = "文本内容";
80 | SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
81 | simpleMailMessage.setFrom(sender);
82 | simpleMailMessage.setTo(receiver);
83 | simpleMailMessage.setSubject(title);
84 | simpleMailMessage.setText(text);
85 | try {
86 | javaMailSender.send(simpleMailMessage);
87 | }catch (Exception e){
88 | log.error("邮件发送失败",e);
89 | }
90 | }
91 | }
92 |
93 | ```
94 |
95 | ### 6 启动
96 |
97 | jar方式启动,直接点击启动类 mian() 方法启动
98 |
99 | ### 7 关注微信公众号,随时移动端阅读
100 |
101 | 
102 |
--------------------------------------------------------------------------------
/lsb-email/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.11.RELEASE
9 |
10 |
11 | com.example
12 | lsb-email
13 | 0.0.1-SNAPSHOT
14 | lsb-email
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 |
26 |
27 |
28 | org.projectlombok
29 | lombok
30 | true
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-mail
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-test
39 | test
40 |
41 |
42 |
43 |
44 |
45 |
46 | org.springframework.boot
47 | spring-boot-maven-plugin
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/lsb-email/src/main/java/com/example/lsbemail/LsbEmailApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbemail;
2 |
3 | import lombok.Data;
4 | import lombok.extern.slf4j.Slf4j;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.beans.factory.annotation.Value;
7 | import org.springframework.boot.SpringApplication;
8 | import org.springframework.boot.autoconfigure.SpringBootApplication;
9 | import org.springframework.mail.SimpleMailMessage;
10 | import org.springframework.mail.javamail.JavaMailSender;
11 | import org.springframework.web.bind.annotation.RequestMapping;
12 | import org.springframework.web.bind.annotation.RestController;
13 |
14 | @SpringBootApplication
15 | @RestController
16 | @Slf4j
17 | @Data
18 | public class LsbEmailApplication {
19 |
20 | public static void main(String[] args) {
21 | SpringApplication.run(LsbEmailApplication.class, args);
22 | }
23 |
24 | @Value("${mail.sender}")
25 | private String sender;
26 |
27 | @Value("${mail.receiver}")
28 | private String receiver;
29 |
30 | @Autowired
31 | private JavaMailSender javaMailSender;
32 | @RequestMapping("/send")
33 | public void send(){
34 | String title = "文本邮件";
35 | String text = "文本内容";
36 | SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
37 | simpleMailMessage.setFrom(sender);
38 | simpleMailMessage.setTo(receiver);
39 | simpleMailMessage.setSubject(title);
40 | simpleMailMessage.setText(text);
41 | try {
42 | javaMailSender.send(simpleMailMessage);
43 | }catch (Exception e){
44 | log.error("邮件发送失败",e);
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/lsb-email/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | ## 邮箱服务器地址
2 | spring.mail.host=smtp.163.com
3 | ## 用户名
4 | spring.mail.username=18319748706@163.com
5 | ##163的授权密码(需要额外获取)
6 | spring.mail.password=*
7 | spring.mail.default-encoding=utf-8
8 | ## 发送地址
9 | mail.sender=18319748706@163.com
10 | ## 接收地址
11 | mail.receiver=18319748706@163.com
12 |
--------------------------------------------------------------------------------
/lsb-email/src/main/resources/banner.txt:
--------------------------------------------------------------------------------
1 | ${AnsiColor.BRIGHT_YELLOW}
2 | ////////////////////////////////////////////////////////////////////
3 | // _ooOoo_ //
4 | // o8888888o //
5 | // 88" . "88 //
6 | // (| ^_^ |) //
7 | // O\ = /O //
8 | // ____/`---'\____ //
9 | // .' \\| |// `. //
10 | // / \\||| : |||// \ //
11 | // / _||||| -:- |||||- \ //
12 | // | | \\\ - /// | | //
13 | // | \_| ''\---/'' | | //
14 | // \ .-\__ `-` ___/-. / //
15 | // ___`. .' /--.--\ `. . ___ //
16 | // ."" '< `.___\_<|>_/___.' >'"". //
17 | // | | : `- \`.;`\ _ /`;.`/ - ` : | | //
18 | // \ \ `-. \_ __\ /__ _/ .-` / / //
19 | // ========`-.____`-.___\_____/___.-`____.-'======== //
20 | // `=---=' //
21 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
22 | // 佛祖保佑 永不宕机 永无BUG //
23 | ////////////////////////////////////////////////////////////////////
--------------------------------------------------------------------------------
/lsb-es/README.md:
--------------------------------------------------------------------------------
1 | # SpringBoot基础架构篇5
--------------------------------------------------------------------------------
/lsb-es/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.11.RELEASE
9 |
10 |
11 | com.example
12 | lsb-es
13 | 0.0.1-SNAPSHOT
14 | war
15 | lsb-es
16 | Demo project for Spring Boot
17 |
18 |
19 | 1.8
20 |
21 |
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-starter-web
26 |
27 |
28 |
29 | org.projectlombok
30 | lombok
31 | true
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-tomcat
36 | provided
37 |
38 |
39 | org.springframework.boot
40 | spring-boot-starter-test
41 | test
42 |
43 |
44 |
45 |
46 |
47 |
48 | org.springframework.boot
49 | spring-boot-maven-plugin
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/lsb-es/src/main/java/com/example/lsbes/LsbEsApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbes;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class LsbEsApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(LsbEsApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/lsb-es/src/main/java/com/example/lsbes/ServletInitializer.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbes;
2 |
3 | import org.springframework.boot.builder.SpringApplicationBuilder;
4 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
5 |
6 | public class ServletInitializer extends SpringBootServletInitializer {
7 |
8 | @Override
9 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
10 | return application.sources(LsbEsApplication.class);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/lsb-es/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/lsb-helloworld/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM docker.io/adoptopenjdk/openjdk8
2 | COPY lsb-helloworld.jar app.jar
3 | ENTRYPOINT ["java","-jar","/app.jar"]
4 |
--------------------------------------------------------------------------------
/lsb-helloworld/README.md:
--------------------------------------------------------------------------------
1 | ## 引入
2 |
3 | 用 SpringBoot (2.1.10.RELEASE) 写出第一行代码
4 |
5 | ## 核心代码
6 |
7 | ```java
8 | @SpringBootApplication
9 | @RestController
10 | public class Demo2Application {
11 |
12 | public static void main(String[] args) {
13 | SpringApplication.run(Demo2Application.class, args);
14 | }
15 |
16 | @RequestMapping
17 | public String test(){
18 | return "hello,springboot2!";
19 | }
20 | }
21 | ```
22 |
23 | ## 输出
24 | 输出 hello, springboot2!
25 |
--------------------------------------------------------------------------------
/lsb-helloworld/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.11.RELEASE
9 |
10 | com.example
11 | lsb-helloworld
12 | 0.0.1-SNAPSHOT
13 | lsb-helloworld
14 | Demo project for Spring Boot
15 |
16 |
17 | 1.8
18 | true
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-starter-test
29 | test
30 |
31 |
32 |
33 |
34 |
35 |
36 | org.springframework.boot
37 | spring-boot-maven-plugin
38 |
39 |
40 |
41 | repackage
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/lsb-helloworld/src/main/java/com/example/demo2/Demo2Application.java:
--------------------------------------------------------------------------------
1 | package com.example.demo2;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.stereotype.Service;
6 |
7 | @SpringBootApplication
8 | public class Demo2Application {
9 |
10 | public static void main(String[] args) {
11 | E e = (E) SpringApplication.run(Demo2Application.class, args).getBean("ss");
12 | e.test();
13 | }
14 |
15 | @Service(value = "ss")
16 | class E {
17 | public void test() {
18 | System.out.println("service1111111");
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/lsb-helloworld/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/lsb-helloworld/src/main/resources/banner.txt:
--------------------------------------------------------------------------------
1 | ${AnsiColor.BRIGHT_YELLOW}
2 | ////////////////////////////////////////////////////////////////////
3 | // _ooOoo_ //
4 | // o8888888o //
5 | // 88" . "88 //
6 | // (| ^_^ |) //
7 | // O\ = /O //
8 | // ____/`---'\____ //
9 | // .' \\| |// `. //
10 | // / \\||| : |||// \ //
11 | // / _||||| -:- |||||- \ //
12 | // | | \\\ - /// | | //
13 | // | \_| ''\---/'' | | //
14 | // \ .-\__ `-` ___/-. / //
15 | // ___`. .' /--.--\ `. . ___ //
16 | // ."" '< `.___\_<|>_/___.' >'"". //
17 | // | | : `- \`.;`\ _ /`;.`/ - ` : | | //
18 | // \ \ `-. \_ __\ /__ _/ .-` / / //
19 | // ========`-.____`-.___\_____/___.-`____.-'======== //
20 | // `=---=' //
21 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
22 | // 佛祖保佑 永不宕机 永无BUG //
23 | ////////////////////////////////////////////////////////////////////
--------------------------------------------------------------------------------
/lsb-interceptor/README.md:
--------------------------------------------------------------------------------
1 | >show me the code and talk to me,做的出来更要说的明白
2 | >我是布尔bl,你的支持是我分享的动力!
3 |
4 |
5 |
6 | ## 拦截器引入
7 |
8 | 拦截器可以在请求控制层之前做一些特定操作
9 |
10 | ## 操作
11 |
12 | 1. 继承 HandlerInterceptor,
13 | 2. 继承 WebMvcConfigurer 放到Springboot 容器
14 |
15 | ## 注解引入
16 | 基于aop注解的使用
17 |
18 |
19 |
20 | 
21 |
--------------------------------------------------------------------------------
/lsb-interceptor/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.12.RELEASE
9 |
10 |
11 | com.example
12 | lsb-interceptor
13 | 0.0.1-SNAPSHOT
14 | lsb-interceptor
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-aop
30 |
31 |
32 |
33 | org.projectlombok
34 | lombok
35 | true
36 |
37 |
38 | org.springframework.boot
39 | spring-boot-starter-test
40 | test
41 |
42 |
43 |
44 |
45 |
46 |
47 | org.springframework.boot
48 | spring-boot-maven-plugin
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/lsb-interceptor/src/main/java/com/example/lsbinterceptor/LsbInterceptorApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbinterceptor;
2 |
3 | import com.example.lsbinterceptor.config.MyInterceptor;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
8 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
9 |
10 | @SpringBootApplication
11 | public class LsbInterceptorApplication implements WebMvcConfigurer {
12 |
13 | public static void main(String[] args) {
14 | SpringApplication.run(LsbInterceptorApplication.class, args);
15 | }
16 |
17 |
18 | @Autowired
19 | private MyInterceptor myInterceptor;
20 | @Override
21 | public void addInterceptors(InterceptorRegistry registry) {
22 | registry.addInterceptor(myInterceptor);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/lsb-interceptor/src/main/java/com/example/lsbinterceptor/config/Log.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbinterceptor.config;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Target(ElementType.METHOD) // 注解作用在方法上
9 | @Retention(RetentionPolicy.RUNTIME)
10 | public @interface Log {
11 | String value() default "";
12 | }
13 |
--------------------------------------------------------------------------------
/lsb-interceptor/src/main/java/com/example/lsbinterceptor/config/LogAspect.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbinterceptor.config;
2 |
3 | import org.aspectj.lang.ProceedingJoinPoint;
4 | import org.aspectj.lang.annotation.Around;
5 | import org.aspectj.lang.annotation.Aspect;
6 | import org.springframework.stereotype.Component;
7 |
8 | @Aspect
9 | @Component// 声明这是一个切面类
10 | public class LogAspect {
11 |
12 | @Around("@annotation(log)")
13 | public Object logMethodExecution(ProceedingJoinPoint joinPoint, Log log) throws Throwable {
14 |
15 | String methodName = joinPoint.getSignature().getName();
16 | String logMessage = log.value().isEmpty() ?
17 | "Executing method: " + methodName : log.value();
18 |
19 | // 打印日志(前置通知)
20 | System.out.println("[LOG] START: " + logMessage);
21 |
22 | try {
23 | Object result = joinPoint.proceed(); // 执行目标方法
24 | // 打印日志(返回通知)
25 | System.out.println("[LOG] SUCCESS: " + methodName);
26 | return result;
27 | } catch (Exception e) {
28 | // 打印日志(异常通知)
29 | System.out.println("[LOG] ERROR: " + methodName + " - " + e.getMessage());
30 | throw e;
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/lsb-interceptor/src/main/java/com/example/lsbinterceptor/config/MyInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbinterceptor.config;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.springframework.stereotype.Component;
5 | import org.springframework.web.servlet.HandlerInterceptor;
6 | import org.springframework.web.servlet.ModelAndView;
7 |
8 | import javax.servlet.http.HttpServletRequest;
9 | import javax.servlet.http.HttpServletResponse;
10 |
11 | /**
12 | * @Description:
13 | * @Author: boolean
14 | * @Date: 2020/1/17 16:43
15 | */
16 | @Slf4j
17 | @Component
18 | public class MyInterceptor implements HandlerInterceptor {
19 | @Override
20 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
21 | log.info("我是第一preHandle");
22 | // flase 不向后执行
23 | return true;
24 | }
25 |
26 | @Override
27 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
28 | log.info("我是第二 postHandle");
29 | }
30 |
31 | @Override
32 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
33 | log.info("我是第三 afterCompletion");
34 | }
35 | }
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/lsb-interceptor/src/main/java/com/example/lsbinterceptor/controller/DemoController.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbinterceptor.controller;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | /**
8 | * @Description:
9 | * @Author: boolean
10 | * @Date: 2020/1/17 16:50
11 | */
12 | @Slf4j
13 | @RestController
14 | public class DemoController {
15 | @RequestMapping("/test")
16 | public String test(){
17 | log.info("我是控制层");
18 | return "well";
19 | }
20 | }
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/lsb-interceptor/src/main/java/com/example/lsbinterceptor/service/DemoServie.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbinterceptor.service;
2 |
3 | public interface DemoServie {
4 |
5 | void test();
6 | }
7 |
--------------------------------------------------------------------------------
/lsb-interceptor/src/main/java/com/example/lsbinterceptor/service/impl/DemoServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbinterceptor.service.impl;
2 |
3 | import com.example.lsbinterceptor.config.Log;
4 | import com.example.lsbinterceptor.service.DemoServie;
5 | import org.springframework.stereotype.Service;
6 |
7 | @Service
8 | public class DemoServiceImpl implements DemoServie {
9 | @Log("我是注解")
10 | @Override
11 | public void test() {
12 | System.out.println("执行service方法");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/lsb-interceptor/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/lsb-login/README.md:
--------------------------------------------------------------------------------
1 | # 认证方式
2 |
3 | ## 用户名密码认证
4 |
5 | ## Session-Cookie认证
6 |
7 | ## token认证
8 |
9 | ## jwt 认证
10 |
11 | ## auth 认证
12 |
13 | 微信 qq 淘宝
--------------------------------------------------------------------------------
/lsb-login/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.12.RELEASE
9 |
10 |
11 | com.example
12 | lsb-login
13 | 0.0.1-SNAPSHOT
14 | lsb-login
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 |
26 |
27 |
28 | org.projectlombok
29 | lombok
30 | true
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-test
35 | test
36 |
37 |
38 |
39 |
40 |
41 |
42 | org.springframework.boot
43 | spring-boot-maven-plugin
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/lsb-login/src/main/java/com/example/demo/DemoApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.demo;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.ui.Model;
7 | import org.springframework.web.bind.annotation.GetMapping;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | import javax.servlet.http.HttpSession;
11 |
12 | @SpringBootApplication
13 | @RestController
14 | @Slf4j
15 | public class DemoApplication {
16 |
17 | public static void main(String[] args) {
18 | SpringApplication.run(DemoApplication.class, args);
19 | }
20 |
21 | @GetMapping("/login")
22 | public String login(HttpSession session){
23 | // session.setAttribute("USER", "1234");
24 | return "sss";
25 | }
26 |
27 | @GetMapping("/hello")
28 | public String hello(HttpSession session){
29 | Object user = session.getAttribute("USER");
30 | if (user != null){
31 | log.info("session为:{}", user);
32 | }
33 | return "hello";
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/lsb-login/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/lsb-mq/README.md:
--------------------------------------------------------------------------------
1 | # SpringBoot基础架构篇4(SpringBoot与 RabbitMQ)
2 |
3 | ## 应用场景
4 |
5 | - 异步(下单后返回排队,减少数据库压力)
6 |
7 | - 延迟消费(订单过期)
8 | RabbitMQ 不支持定时消费
9 |
10 | ## rockertmq(docker)
11 |
12 | ### 状态检查
13 |
14 | ```java
15 | docker ps -a
16 | ```
17 | ### 启动Namestr
18 |
19 | ```java
20 | docker run -d -p 9876:9876 -v /tmp/data/rocketmq/namesrv/logs:/root/rocketmq-all-4.6.0-bin-release/log -v /tmp/data/rocketmq/namesrv/store:/root/rocketmq-all-4.6.0-bin-release/data --name rmqnamesrv -e "MAX_POSSIBLE_HEAP=100000000" rocketmqinc/rocketmq sh mqnamesrv
21 | ```
22 | ### 启动Broker
23 |
24 | ```java
25 | docker run -d -p 10911:10911 -p 10909:10909 -v /tmp/data/rocketmq/broker/logs:/root/rocketmq-all-4.6.0-bin-release/log -v /tmp/data/rocketmq/broker/store:/root/rocketmq-all-4.6.0-bin-release/data -v /tmp/etc/rocketmq/broker/broker.conf:/root/rocketmq-all-4.6.0-bin-release/conf/broker.conf --name rmqbroker --link rmqnamesrv:namesrv -e "NAMESRV_ADDR=namesrv:9876" -e "MAX_POSSIBLE_HEAP=200000000" rocketmqinc/rocketmq sh mqbroker -c /opt/rocketmq/conf/broker.conf
26 | ```
27 |
28 | ### 杀死进程
29 |
30 | ```java
31 | lsof -i:10909
32 | kill -9 10909
33 | ```
34 | ### 启动项目
35 |
36 | 
--------------------------------------------------------------------------------
/lsb-mq/img.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/buerbl/learnSpringboot/24b970f923ac6cf942ab47d5ec5e19694e35b6ec/lsb-mq/img.png
--------------------------------------------------------------------------------
/lsb-mq/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | com.example
13 | learnSpringboot
14 | 1.0-SNAPSHOT
15 |
16 | com.example
17 | lsb-mq
18 | 0.0.1-SNAPSHOT
19 | war
20 | lsb-mq
21 | Demo project for Spring Boot
22 |
23 |
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 |
34 | org.projectlombok
35 | lombok
36 | true
37 |
38 |
39 | org.springframework.boot
40 | spring-boot-starter-test
41 | test
42 |
43 |
44 | org.springframework.boot
45 | spring-boot-starter-amqp
46 |
47 |
48 | org.apache.rocketmq
49 | rocketmq-client
50 | 4.7.0
51 |
52 |
53 |
54 | org.slf4j
55 | slf4j-api
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | org.springframework.boot
64 | spring-boot-maven-plugin
65 |
66 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/lsb-mq/src/main/java/com/example/lsbmq/LsbMqApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbmq;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class LsbMqApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(LsbMqApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/lsb-mq/src/main/java/com/example/lsbmq/rabbit/RabbitConfig.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbmq.rabbit;
2 |
3 | import org.springframework.amqp.core.Queue;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 |
7 |
8 | /**
9 | * @Description:
10 | * @Author: boolean
11 | * @Date: 2020/1/6 21:42
12 | *
13 | */
14 |
15 | @Configuration
16 | public class RabbitConfig {
17 |
18 | // 队列
19 | @Bean
20 | public Queue helloQueue() {
21 | return new Queue("hello");
22 | }
23 |
24 |
25 | }
26 |
27 |
28 |
--------------------------------------------------------------------------------
/lsb-mq/src/main/java/com/example/lsbmq/rabbit/Receiver.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbmq.rabbit;
2 |
3 | import org.springframework.amqp.rabbit.annotation.RabbitHandler;
4 | import org.springframework.amqp.rabbit.annotation.RabbitListener;
5 | import org.springframework.stereotype.Component;
6 |
7 | /**
8 | * @Description:
9 | * @Author: boolean
10 | * @Date: 2020/1/6 21:41
11 | */
12 | //@Component
13 | //@RabbitListener(queues = "hello")
14 | //public class Receiver {
15 | //
16 | // @RabbitHandler
17 | // public void process(String hello) {
18 | // System.out.println("Receiver : " + hello);
19 | // }
20 | //
21 | //}
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/lsb-mq/src/main/java/com/example/lsbmq/rabbit/Sender.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbmq.rabbit;
2 |
3 | import org.apache.rocketmq.client.producer.DefaultMQProducer;
4 | import org.apache.rocketmq.client.producer.SendResult;
5 | import org.apache.rocketmq.common.message.Message;
6 | import org.apache.rocketmq.remoting.common.RemotingHelper;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 | import org.springframework.amqp.core.AmqpTemplate;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.stereotype.Component;
12 |
13 | import java.util.Date;
14 |
15 | /**
16 | * @Description:
17 | * @Author: boolean
18 | * @Date: 2020/1/6 21:38
19 | */
20 | @Component
21 | public class Sender {
22 | public static final Logger LOGGER = LoggerFactory.getLogger(Sender.class);
23 | @Autowired
24 | private AmqpTemplate rabbitTemplate;
25 |
26 | public void send() {
27 | String context = "hello " + new Date();
28 | System.out.println("Sender : " + context);
29 | rabbitTemplate.convertAndSend("hello", context);
30 | }
31 |
32 | private static String TOPIC = "DemoTopic";
33 | private static String TAGS = "glmapperTags";
34 | @Autowired
35 | private DefaultMQProducer defaultMQProducer;
36 | public String testRocketMQ() throws Throwable {
37 | Message msg = new Message(TOPIC, TAGS, ("Say Hello RocketMQ to Glmapper").getBytes(RemotingHelper.DEFAULT_CHARSET));
38 | // 调用客户端发送消息
39 | SendResult sendResult = defaultMQProducer.send(msg);
40 | LOGGER.info("sendResult: {}.",sendResult);
41 | return "SUCCESS";
42 | }
43 |
44 | }
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/lsb-mq/src/main/java/com/example/lsbmq/rockertmq/MQProducerConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbmq.rockertmq;
2 |
3 | import org.apache.rocketmq.client.exception.MQClientException;
4 | import org.apache.rocketmq.client.producer.DefaultMQProducer;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 | import org.springframework.beans.factory.annotation.Value;
8 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
9 | import org.springframework.context.annotation.Bean;
10 | import org.springframework.context.annotation.Configuration;
11 |
12 |
13 | /**
14 | * @author: guolei.sgl (glmapper_2018@163.com) 2020/4/5 5:17 PM
15 | * @since:
16 | **/
17 | @Configuration
18 | public class MQProducerConfiguration {
19 |
20 | public static final Logger LOGGER = LoggerFactory.getLogger(MQProducerConfiguration.class);
21 |
22 | @Value("${rocketmq.producer.groupName}")
23 | private String groupName;
24 |
25 | @Value("${rocketmq.producer.namesrvAddr}")
26 | private String namesrvAddr;
27 |
28 | @Value("${rocketmq.producer.maxMessageSize}")
29 | private Integer maxMessageSize;
30 |
31 | @Value("${rocketmq.producer.sendMsgTimeout}")
32 | private Integer sendMsgTimeout;
33 |
34 | @Value("${rocketmq.producer.retryTimesWhenSendFailed}")
35 | private Integer retryTimesWhenSendFailed;
36 |
37 | @Bean
38 | @ConditionalOnMissingBean
39 | public DefaultMQProducer defaultMQProducer() throws RuntimeException {
40 | DefaultMQProducer producer = new DefaultMQProducer(this.groupName);
41 | producer.setNamesrvAddr(this.namesrvAddr);
42 | producer.setCreateTopicKey("AUTO_CREATE_TOPIC_KEY");
43 | //如果需要同一个 jvm 中不同的 producer 往不同的 mq 集群发送消息,需要设置不同的 instanceName
44 | //producer.setInstanceName(instanceName);
45 | //如果发送消息的最大限制
46 | producer.setMaxMessageSize(this.maxMessageSize);
47 | //如果发送消息超时时间
48 | producer.setSendMsgTimeout(this.sendMsgTimeout);
49 | //如果发送消息失败,设置重试次数,默认为 2 次
50 | producer.setRetryTimesWhenSendFailed(this.retryTimesWhenSendFailed);
51 | try {
52 | producer.start();
53 | LOGGER.info("producer is started. groupName:{}, namesrvAddr: {}", groupName, namesrvAddr);
54 | } catch (MQClientException e) {
55 | LOGGER.error("failed to start producer.", e);
56 | throw new RuntimeException(e);
57 | }
58 | return producer;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/lsb-mq/src/main/java/com/example/lsbmq/rockertmq/MessageListenerHandler.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbmq.rockertmq;
2 |
3 | import org.apache.commons.collections.CollectionUtils;
4 | import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
5 | import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
6 | import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
7 | import org.apache.rocketmq.common.message.MessageExt;
8 | import org.slf4j.Logger;
9 | import org.slf4j.LoggerFactory;
10 | import org.springframework.stereotype.Component;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | * @Author 布尔bl
16 | * @create 2021/11/7 17:19
17 | */
18 | @Component
19 | public class MessageListenerHandler implements MessageListenerConcurrently {
20 | private static final Logger LOGGER = LoggerFactory.getLogger(MessageListenerHandler.class);
21 | private static String TOPIC = "DemoTopic";
22 |
23 | @Override
24 | public ConsumeConcurrentlyStatus consumeMessage(List msgs,
25 | ConsumeConcurrentlyContext context) {
26 | if (CollectionUtils.isEmpty(msgs)) {
27 | LOGGER.info("receive blank msgs...");
28 | return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
29 | }
30 | MessageExt messageExt = msgs.get(0);
31 | String msg = new String(messageExt.getBody());
32 | if (messageExt.getTopic().equals(TOPIC)) {
33 | // mock 消费逻辑
34 | mockConsume(msg);
35 | }
36 | return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
37 | }
38 |
39 | private void mockConsume(String msg){
40 | LOGGER.info("receive msg: {}.", msg);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/lsb-mq/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | rabbitmq:
3 | host: ip
4 | port: 5672
5 | username: admin
6 | password: 123456
7 | server:
8 | port:8008
9 | rocketmq:
10 | producer:
11 | isOnOff: on
12 | groupName: test-rocket
13 | namesrvAddr: ip:9876
14 | maxMessageSize: 4096
15 | sendMsgTimeout: 3000
16 | retryTimesWhenSendFailed: 2
17 | consumer:
18 | isOnOff: on
19 | groupName: test-rocket
20 | namesrvAddr: ip:9876
21 | topics: DemoTopic
22 | consumeThreadMin: 20
23 | consumeThreadMax: 64
24 | consumeMessageBatchMaxSize: 1
25 |
--------------------------------------------------------------------------------
/lsb-mybatis_generator/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | learnSpringboot
7 | com.example
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | lsb-mybatis_generator
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-web
17 |
18 |
19 | org.projectlombok
20 | lombok
21 | true
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-starter-test
26 | test
27 |
28 |
29 |
30 |
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-maven-plugin
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/lsb-mybatis_generator/src/main/java/com/example/gen/GenApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.gen;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.web.bind.annotation.GetMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | @SpringBootApplication
9 | @RestController
10 | public class GenApplication {
11 |
12 | public static void main(String[] args) {
13 | SpringApplication.run(GenApplication.class, args);
14 | }
15 | @GetMapping("/gen")
16 | public String gen(){
17 | return "gen";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/lsb-profiles/README.md:
--------------------------------------------------------------------------------
1 | ## 配置1
2 | 
3 |
4 | ## 配置2
5 | 
6 |
7 | ## 配置3
8 | 
--------------------------------------------------------------------------------
/lsb-profiles/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.2.5.RELEASE
9 |
10 |
11 | com.example
12 | lsb-profiles
13 | 0.0.1-SNAPSHOT
14 | lsb-profiles
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-test
30 | test
31 |
32 |
33 | org.junit.vintage
34 | junit-vintage-engine
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | org.springframework.boot
44 | spring-boot-maven-plugin
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/lsb-profiles/src/main/java/com/example/lsbprofiles/LsbProfilesApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbprofiles;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | @SpringBootApplication
9 | @RestController
10 | public class LsbProfilesApplication {
11 |
12 | public static void main(String[] args) {
13 | SpringApplication.run(LsbProfilesApplication.class, args);
14 | }
15 | @RequestMapping
16 | public String test(){
17 | return "hello,profile";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/lsb-profiles/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | profiles:
3 | active: p3
4 |
5 | ---
6 |
7 | spring:
8 | profiles: p1
9 | server:
10 | port: 8081
11 |
12 |
13 | ---
14 |
15 | spring:
16 | profiles: p2
17 | server:
18 | port: 8082
19 |
20 | ---
21 |
22 | spring:
23 | profiles: p3
24 | server:
25 | port: 8083
--------------------------------------------------------------------------------
/lsb-redistest/src/main/java/com/example/lsbredistest/LsbRedistestApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbredistest;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class LsbRedistestApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(LsbRedistestApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/lsb-redistest/src/main/java/com/example/lsbredistest/ServletInitializer.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbredistest;
2 |
3 | import org.springframework.boot.builder.SpringApplicationBuilder;
4 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
5 |
6 | public class ServletInitializer extends SpringBootServletInitializer {
7 |
8 | @Override
9 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
10 | return application.sources(LsbRedistestApplication.class);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/lsb-redistest/src/main/java/com/example/lsbredistest/controller/RedisController.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbredistest.controller;
2 |
3 | import com.example.lsbredistest.controller.entity.User;
4 | import com.google.gson.Gson;
5 | import org.springframework.data.redis.core.RedisTemplate;
6 | import org.springframework.data.redis.core.StringRedisTemplate;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | import javax.annotation.Resource;
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | /**
15 | * @Description:
16 | * @Author: boolean
17 | * @Date: 2020/1/6 15:47
18 | */
19 | @RestController
20 | @RequestMapping("/lsbredis")
21 | public class RedisController {
22 |
23 | @Resource
24 | private StringRedisTemplate stringRedisTemplate;
25 |
26 | @RequestMapping("/test")
27 | public void test(){
28 |
29 | // key : a value: a
30 | // 增
31 | stringRedisTemplate.opsForValue().set("a","a");
32 | // 查
33 | String a = stringRedisTemplate.opsForValue().get("a");
34 | System.out.println("a的值:"+a);
35 | // 改
36 | stringRedisTemplate.opsForValue().set("a","b");
37 |
38 | // 缓存一个对象
39 | List list = new ArrayList<>();
40 | list.add(new User(1l, "c1",1, "s1"));
41 | list.add(new User(2l, "c2",2, "s2"));
42 | list.add(new User(3l, "c3",3, "s3"));
43 | Gson gson = new Gson();
44 | String toJson = gson.toJson(list);
45 | stringRedisTemplate.opsForValue().set("user",toJson);
46 | stringRedisTemplate.opsForZSet().add("chen", "12", 1D);
47 | stringRedisTemplate.opsForZSet().add("chen", "15", 6D);
48 |
49 | }
50 |
51 | }
52 |
53 |
54 |
--------------------------------------------------------------------------------
/lsb-redistest/src/main/java/com/example/lsbredistest/controller/entity/User.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbredistest.controller.entity;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 |
6 | import java.io.Serializable;
7 |
8 | /**
9 | * @Description:
10 | * @Author: boolean
11 | * @Date: 2020/1/6 15:53
12 | */
13 | @Data
14 | @AllArgsConstructor
15 | public class User implements Serializable {
16 |
17 | private static final long serialVersionUID=1L;
18 |
19 | /**
20 | * 主键ID
21 | */
22 | private Long id;
23 |
24 | /**
25 | * 姓名
26 | */
27 | private String name;
28 |
29 | /**
30 | * 年龄
31 | */
32 | private Integer age;
33 |
34 | /**
35 | * 邮箱
36 | */
37 | private String email;
38 |
39 |
40 |
41 | }
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/lsb-redistest/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | ### redis 缓存配置
2 | spring:
3 | redis:
4 | database: 0
5 | host: 127.0.0.1
6 | port: 6379
7 | password:
--------------------------------------------------------------------------------
/lsb-restful/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/buerbl/learnSpringboot/24b970f923ac6cf942ab47d5ec5e19694e35b6ec/lsb-restful/README.md
--------------------------------------------------------------------------------
/lsb-restful/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.12.RELEASE
9 |
10 |
11 | com.example
12 | lsb-restful
13 | 0.0.1-SNAPSHOT
14 | lsb-restful
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 |
26 |
27 |
28 | org.projectlombok
29 | lombok
30 | true
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-test
35 | test
36 |
37 |
38 |
39 |
40 |
41 |
42 | org.springframework.boot
43 | spring-boot-maven-plugin
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/lsb-restful/src/main/java/com/example/lsbrestful/LsbRestfulApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbrestful;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.web.bind.annotation.PathVariable;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RequestMethod;
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 | @SpringBootApplication
12 | @RestController
13 | @Slf4j
14 | public class LsbRestfulApplication {
15 |
16 | public static void main(String[] args) {
17 | SpringApplication.run(LsbRestfulApplication.class, args);
18 | }
19 |
20 | /**
21 | * 得到所有列表
22 | * @return
23 | */
24 | @RequestMapping(value = "/v1/list",method = RequestMethod.GET)
25 | public String getList(){
26 | log.info("得到列表");
27 | return "得到列表";
28 | }
29 |
30 | /**
31 | * 得到列表中的一条
32 | * @param name
33 | * @return
34 | */
35 | @RequestMapping(value = "/v1/list/{name}",method = RequestMethod.GET)
36 | public String getListone(@PathVariable("name") String name){
37 | log.info("得到列表"+name);
38 | return "得到列表"+name;
39 | }
40 |
41 | /**
42 | * 往列表中的增加一条数据
43 | * @return
44 | */
45 | @RequestMapping(value = "/v1/list",method = RequestMethod.POST)
46 | public String addList(){
47 | log.info("增加一个列表1");
48 | return "增加一个列表1";
49 | }
50 |
51 | /**
52 | * 更新列表中的一条数据
53 | * @return
54 | */
55 | @RequestMapping(value = "/v1/list/{name}",method = RequestMethod.PUT)
56 | public String updateListOne(@PathVariable("name") String name){
57 | log.info("更新列表"+name);
58 | return "更新列表"+name;
59 | }
60 |
61 | /**
62 | * 删除所有列表
63 | * @return
64 | */
65 | @RequestMapping(value = "/v1/list",method = RequestMethod.DELETE)
66 | public String delList(){
67 | log.info("删除一个列表");
68 | return "删除一个列表";
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/lsb-restful/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/lsb-scheduledtask/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | learnSpringboot
7 | com.example
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 | lsb-scheduledtask
12 |
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-web
17 |
18 |
19 | org.springframework.boot
20 | spring-boot-starter-test
21 | test
22 |
23 |
24 |
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-maven-plugin
30 |
31 |
32 |
33 |
34 | src/main/java
35 |
36 | **/*.xml
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/lsb-scheduledtask/src/main/java/com/example/LsbSchduledTaskApplication.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.context.ConfigurableApplicationContext;
6 | import org.springframework.stereotype.Service;
7 |
8 | @SpringBootApplication
9 | public class LsbSchduledTaskApplication {
10 |
11 | public static void main(String[] args) {
12 | ConfigurableApplicationContext run = SpringApplication.run(LsbSchduledTaskApplication.class, args);
13 | Test bean = (Test) run.getBean("scheduled");
14 | bean.test();
15 | }
16 |
17 | @Service(value = "scheduled")
18 | class Test {
19 | public void test() {
20 | System.out.println("scheduled");
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/lsb-security/README.md:
--------------------------------------------------------------------------------
1 | ## 登录
2 |
3 | 
4 |
5 | ## 注销
6 |
7 | 
8 |
9 |
--------------------------------------------------------------------------------
/lsb-security/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.12.RELEASE
9 |
10 |
11 | com.example
12 | lsb-security
13 | 0.0.1-SNAPSHOT
14 | lsb-security
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 |
26 |
27 |
28 | org.projectlombok
29 | lombok
30 | true
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-test
35 | test
36 |
37 |
38 | org.springframework.boot
39 | spring-boot-starter-security
40 |
41 |
42 | org.springframework.boot
43 | spring-boot-starter-thymeleaf
44 |
45 |
46 |
47 |
48 |
49 |
50 | org.springframework.boot
51 | spring-boot-maven-plugin
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/lsb-security/src/main/java/com/example/lsbsecurity/LsbSecurityApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbsecurity;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class LsbSecurityApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(LsbSecurityApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/lsb-security/src/main/java/com/example/lsbsecurity/config/MvcConfig.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbsecurity.config;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
6 |
7 | /**
8 | * @Description:
9 | * @Author: boolean
10 | * @Date: 2020/1/17 18:27
11 | */
12 | @Configuration
13 | public class MvcConfig implements WebMvcConfigurer {
14 |
15 | public void addViewControllers(ViewControllerRegistry registry) {
16 | registry.addViewController("/hello").setViewName("hello");
17 | registry.addViewController("/logout").setViewName("logout");
18 | }
19 |
20 | }
21 |
22 |
23 |
--------------------------------------------------------------------------------
/lsb-security/src/main/java/com/example/lsbsecurity/config/WebSecurityConfig.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbsecurity.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
7 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
8 | import org.springframework.security.core.userdetails.User;
9 | import org.springframework.security.core.userdetails.UserDetails;
10 | import org.springframework.security.core.userdetails.UserDetailsService;
11 | import org.springframework.security.provisioning.InMemoryUserDetailsManager;
12 |
13 | /**
14 | * @Description:
15 | * @Author: boolean
16 | * @Date: 2020/1/17 18:12
17 | */
18 | @Configuration
19 | @EnableWebSecurity
20 | public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
21 | @Override
22 | protected void configure(HttpSecurity http) throws Exception {
23 | http
24 | .authorizeRequests()
25 | .antMatchers("/").permitAll()
26 | .anyRequest().authenticated()
27 | .and()
28 | .formLogin()
29 | .failureForwardUrl("/login?error")
30 | .defaultSuccessUrl("/hello")
31 | .permitAll();
32 | super.configure(http);
33 | }
34 |
35 | @Bean
36 | @Override
37 | public UserDetailsService userDetailsService() {
38 | UserDetails user =
39 | User.withDefaultPasswordEncoder()
40 | .username("user")
41 | .password("password")
42 | .roles("USER")
43 | .build();
44 |
45 | return new InMemoryUserDetailsManager(user);
46 | }
47 |
48 |
49 | }
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/lsb-security/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/lsb-security/src/main/resources/templates/hello.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | Hello World!
6 |
7 |
8 | Hello world!
9 |
10 |
--------------------------------------------------------------------------------
/lsb-security/src/main/resources/templates/logout.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
7 |
8 | Document
9 |
10 |
11 | 注销了
12 |
13 |
--------------------------------------------------------------------------------
/lsb-shiro/README.md:
--------------------------------------------------------------------------------
1 | # easy-authority-system
2 |
3 | ## 效果
4 |
5 | 
6 |
7 | ## 分析 Shrio 的核心 API
8 |
9 | Subject : 用户主体(把操作交给 SecurityManager)
10 | SecurityManager : 安全管理器(关联 Realm)
11 | Realm :Shiro 连接数据的桥梁
12 |
13 | ## shiro 引入
14 |
15 | ```java
16 |
17 | org.apache.shiro
18 | shiro-spring
19 | 1.4.0
20 |
21 | ```
22 |
23 |
24 | ## 简单拦截
25 |
26 | ```java
27 | public ShiroFilterFactoryBean getShiroFilterFactoryBean(@Qualifier("securityManager") DefaultWebSecurityManager securityManager){
28 | ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
29 |
30 |
31 | // 设置安全管理器
32 | shiroFilterFactoryBean.setSecurityManager(securityManager);
33 |
34 | // 添加 shiro 内置过滤器
35 | /**
36 | * Shiro 内置过滤器,可以实现权限相关的拦截器
37 | * 常用的过滤器
38 | * anon: 无需认证(登录)可以访问
39 | * authc: 必须认证才可以访问
40 | * user:如果使用 remenmberMe 的功能可以直接访问
41 | * perms: 该资源必须得到资源权限才可以访问
42 | * role: 该资源必须得到角色权限才可以访问
43 | */
44 | Map filterMap = new LinkedHashMap<>();
45 | filterMap.put("/test", "anon");
46 | // 拦截所有
47 | filterMap.put("/*", "authc");
48 |
49 |
50 | shiroFilterFactoryBean.setLoginUrl("/tologin");
51 | shiroFilterFactoryBean.setFilterChainDefinitionMap(filterMap);
52 |
53 | return shiroFilterFactoryBean;
54 | }
55 | ```
56 |
57 | ## 认证
58 |
59 | ```java
60 | public String login(String name, String password, Model model){
61 | log.info("登录");
62 | log.info(name+"+"+password);
63 | // 1. 获取 Subject
64 | Subject subject = SecurityUtils.getSubject();
65 |
66 | // 2. 封装用户数据
67 | UsernamePasswordToken token = new UsernamePasswordToken(name, password);
68 | try {
69 | subject.login(token);
70 |
71 | } catch (UnknownAccountException e){
72 | model.addAttribute("msg", "用户名不存在");
73 | return "login";
74 | }catch (IncorrectCredentialsException e){
75 | model.addAttribute("msg", "密码错误");
76 | return "login";
77 | }
78 | return "login";
79 | }
80 | ```
--------------------------------------------------------------------------------
/lsb-shiro/src/main/java/com/example/demo/DemoApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.demo;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | @SpringBootApplication
9 | public class DemoApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(DemoApplication.class, args);
13 | }
14 |
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/lsb-shiro/src/main/java/com/example/demo/Dto/Dto.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.Dto;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | /**
8 | * @Description:
9 | * @Author: boolean
10 | * @Date: 2020/2/2 13:29
11 | */
12 | @Data
13 | @NoArgsConstructor
14 | @AllArgsConstructor
15 | public class Dto {
16 | private String name;
17 | private String password;
18 |
19 | }
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/lsb-shiro/src/main/java/com/example/demo/config/FilterConfig.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.config;
2 |
3 | import org.springframework.boot.web.servlet.FilterRegistrationBean;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 |
7 | /**
8 | * @Description:
9 | * @Author: boolean
10 | * @Date: 2020/2/2 21:04
11 | */
12 | @Configuration
13 | public class FilterConfig {
14 |
15 | @Bean
16 | public FilterRegistrationBean registFilter() {
17 | FilterRegistrationBean registration = new FilterRegistrationBean();
18 | registration.setFilter(new GlobalCorsConfig());
19 | registration.addUrlPatterns("/*");
20 | registration.setName("GlobalCorsConfig");
21 | registration.setOrder(1);
22 | return registration;
23 | }
24 |
25 | }
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/lsb-shiro/src/main/java/com/example/demo/config/GlobalCorsConfig.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.config;
2 |
3 | import org.apache.catalina.filters.CorsFilter;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.web.cors.CorsConfiguration;
7 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
8 | import org.springframework.web.servlet.config.annotation.CorsRegistry;
9 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
10 |
11 | import javax.servlet.*;
12 | import javax.servlet.http.HttpServletRequest;
13 | import javax.servlet.http.HttpServletResponse;
14 | import java.io.IOException;
15 |
16 |
17 | /**
18 | * @Description:
19 | * @Author: boolean
20 | * @Date: 2020/2/2 19:52
21 | */
22 | //@Configuration
23 | public class GlobalCorsConfig implements Filter {
24 |
25 | @Override
26 | public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
27 | HttpServletResponse response = (HttpServletResponse) res;
28 | response.setHeader("Access-Control-Allow-Origin", "*");
29 | response.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD"); // or *
30 | response.setHeader("Access-Control-Max-Age", "3600");
31 | response.setHeader("Access-Control-Allow-Headers", "*"); // or *
32 | HttpServletRequest request = (HttpServletRequest) req;
33 | if (request.getMethod().equals("OPTIONS")) {
34 | response.setStatus(HttpServletResponse.SC_OK);
35 | }else {
36 | chain.doFilter(req, res);
37 | }
38 |
39 | }
40 | }
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/lsb-shiro/src/main/java/com/example/demo/config/ShiroSessionManager.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.config;
2 |
3 | import org.apache.shiro.web.servlet.ShiroHttpServletRequest;
4 | import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
5 | import org.apache.shiro.web.util.WebUtils;
6 | import org.springframework.util.StringUtils;
7 |
8 | import javax.servlet.ServletRequest;
9 | import javax.servlet.ServletResponse;
10 | import java.io.Serializable;
11 |
12 | /**
13 | * @Description:
14 | * @Author: boolean
15 | * @Date: 2020/2/2 18:30
16 | */
17 | public class ShiroSessionManager extends DefaultWebSessionManager {
18 |
19 | private static final String AUTHORIZATION = "authorization";
20 |
21 | private static final String REFERENCED_SESSION_ID_SOURCE = "Stateless request";
22 |
23 | public ShiroSessionManager(){
24 | super();
25 | }
26 |
27 | @Override
28 | protected Serializable getSessionId(ServletRequest request, ServletResponse response){
29 | String id = WebUtils.toHttp(request).getHeader(AUTHORIZATION);
30 | // Object attribute = request.getHe(AUTHORIZATION);
31 | System.out.println("id:"+id);
32 | if(StringUtils.isEmpty(id)){
33 | //如果没有携带id参数则按照父类的方式在cookie进行获取
34 | System.out.println("super:"+super.getSessionId(request, response));
35 | return super.getSessionId(request, response);
36 | }else{
37 | //如果请求头中有 authToken 则其值为sessionId
38 | request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_SOURCE,REFERENCED_SESSION_ID_SOURCE);
39 | request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID,id);
40 | request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_IS_VALID,Boolean.TRUE);
41 | return id;
42 | }
43 | }
44 | }
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/lsb-shiro/src/main/java/com/example/demo/config/UserRealm.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.config;
2 |
3 | import com.example.demo.entity.ShiroUser;
4 | import com.example.demo.service.IShiroUserService;
5 | import lombok.extern.slf4j.Slf4j;
6 | import org.apache.shiro.SecurityUtils;
7 | import org.apache.shiro.authc.*;
8 | import org.apache.shiro.authz.AuthorizationInfo;
9 | import org.apache.shiro.authz.SimpleAuthorizationInfo;
10 | import org.apache.shiro.realm.AuthorizingRealm;
11 | import org.apache.shiro.subject.PrincipalCollection;
12 | import org.apache.shiro.subject.Subject;
13 | import org.springframework.beans.factory.annotation.Autowired;
14 |
15 | /**
16 | * @Description:
17 | * @Author: boolean
18 | * @Date: 2020/1/31 22:09
19 | * 自定义的Realm
20 | */
21 | @Slf4j
22 | public class UserRealm extends AuthorizingRealm {
23 |
24 | /**
25 | * 执行授权逻辑
26 | * @param principals
27 | * @return
28 | */
29 | @Override
30 | protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
31 | log.info("执行授权逻辑");
32 | SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
33 | // info.addStringPermission("add");
34 | Subject subject = SecurityUtils.getSubject();
35 | ShiroUser user = (ShiroUser) subject.getPrincipal();
36 | info.addStringPermission(user.getRole());
37 | return info;
38 | }
39 |
40 |
41 | @Autowired
42 | private IShiroUserService shiroUserService;
43 | /**
44 | * 执行认证逻辑
45 | * @param token
46 | * @return
47 | * @throws AuthenticationException
48 | */
49 | @Override
50 | protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
51 | log.info("执行认证逻辑");
52 |
53 | UsernamePasswordToken token1 = (UsernamePasswordToken) token;
54 | ShiroUser user = shiroUserService.getUser(token1.getUsername(), String.copyValueOf(token1.getPassword()));
55 | // 判断用户名
56 | if (user==null){
57 | return null; //shiro 抛出 UnaKnowAccountException
58 | }
59 |
60 | // 判断密码
61 | return new SimpleAuthenticationInfo(user, user.getPassword(), "");
62 | }
63 | }
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/lsb-shiro/src/main/java/com/example/demo/entity/ShiroUser.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.entity;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | /**
8 | * @Description:
9 | * @Author: boolean
10 | * @Date: 2020/2/1 14:32
11 | */
12 | @Data
13 | @NoArgsConstructor
14 | @AllArgsConstructor
15 | public class ShiroUser {
16 | private Integer id;
17 | private String name;
18 | private String password;
19 | private String role;
20 |
21 | }
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/lsb-shiro/src/main/java/com/example/demo/mapper/ShiroUserMapper.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.mapper;
2 |
3 | import com.example.demo.entity.ShiroUser;
4 | import org.apache.ibatis.annotations.Mapper;
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | /**
8 | * @Description:
9 | * @Author: boolean
10 | * @Date: 2020/2/1 14:30
11 | */
12 | @Mapper
13 | public interface ShiroUserMapper {
14 | ShiroUser getUser(@Param("name") String name, @Param("password") String password);
15 | }
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/lsb-shiro/src/main/java/com/example/demo/mapper/ShiroUserMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
18 |
--------------------------------------------------------------------------------
/lsb-shiro/src/main/java/com/example/demo/service/IShiroUserService.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service;
2 |
3 | import com.example.demo.entity.ShiroUser;
4 |
5 | public interface IShiroUserService {
6 | /**
7 | * 登录方法
8 | * @param name
9 | * @param password
10 | * @return
11 | */
12 | ShiroUser getUser(String name, String password);
13 | }
14 |
--------------------------------------------------------------------------------
/lsb-shiro/src/main/java/com/example/demo/service/Impl/ShiroUserServieImpl.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service.Impl;
2 |
3 | import com.example.demo.entity.ShiroUser;
4 | import com.example.demo.mapper.ShiroUserMapper;
5 | import com.example.demo.service.IShiroUserService;
6 | import lombok.extern.slf4j.Slf4j;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Service;
9 |
10 | /**
11 | * @Description:
12 | * @Author: boolean
13 | * @Date: 2020/2/1 14:34
14 | */
15 | @Service
16 | @Slf4j
17 | public class ShiroUserServieImpl implements IShiroUserService {
18 | @Autowired
19 | private ShiroUserMapper shiroUserMapper;
20 | @Override
21 | public ShiroUser getUser(String name, String password) {
22 | log.info("name为{}, password为{}", name, password);
23 | return shiroUserMapper.getUser(name, password);
24 | }
25 | }
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/lsb-shiro/src/main/java/rebel.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/lsb-shiro/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | datasource:
3 | url: jdbc:mysql://localhost:3306/dev
4 | username: root
5 | password: 123456
--------------------------------------------------------------------------------
/lsb-shiro/src/main/resources/shiro_user.sql:
--------------------------------------------------------------------------------
1 | /*
2 | Navicat MySQL Data Transfer
3 |
4 | Source Server : buer
5 | Source Server Version : 50728
6 | Source Host : 47.105.202.146:3306
7 | Source Database : dev
8 |
9 | Target Server Type : MYSQL
10 | Target Server Version : 50728
11 | File Encoding : 65001
12 |
13 | Date: 2020-02-01 15:45:51
14 | */
15 |
16 | SET FOREIGN_KEY_CHECKS=0;
17 |
18 | -- ----------------------------
19 | -- Table structure for shiro_user
20 | -- ----------------------------
21 | DROP TABLE IF EXISTS `shiro_user`;
22 | CREATE TABLE `shiro_user` (
23 | `id` int(11) NOT NULL AUTO_INCREMENT,
24 | `name` varchar(255) NOT NULL,
25 | `password` varchar(255) NOT NULL,
26 | `role` varchar(255) NOT NULL,
27 | PRIMARY KEY (`id`)
28 | ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
29 |
30 | -- ----------------------------
31 | -- Records of shiro_user
32 | -- ----------------------------
33 | INSERT INTO `shiro_user` VALUES ('1', 'root', '123456', 'add');
34 | INSERT INTO `shiro_user` VALUES ('2', 'normal', 'normal', 'update');
35 |
--------------------------------------------------------------------------------
/lsb-shiro/src/main/resources/templates/hello.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 测试thymeleaf
6 |
7 |
8 |
17 |
18 |
--------------------------------------------------------------------------------
/lsb-shiro/src/main/resources/templates/login.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 登录
6 |
7 |
8 |
9 |
10 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/lsb-shiro/src/main/resources/templates/logout.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 | 退出登陆
9 |
10 |
--------------------------------------------------------------------------------
/lsb-shiro/src/main/resources/templates/noauto.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 | 亲,您没有授权呢!
9 |
10 |
--------------------------------------------------------------------------------
/lsb-shiro/src/main/resources/templates/user/add.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 |
9 | 增加用户
10 |
11 |
12 |
--------------------------------------------------------------------------------
/lsb-shiro/src/main/resources/templates/user/update.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 |
9 | 更新用户
10 |
11 |
12 |
--------------------------------------------------------------------------------
/lsb-springboot-learn/common/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.example
8 | learnSpringboot
9 | 1.0-SNAPSHOT
10 | ../../pom.xml
11 |
12 |
13 | common
14 |
15 |
16 | 17
17 | 17
18 | UTF-8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 | 2.7.5
26 |
27 |
28 | org.projectlombok
29 | lombok
30 | true
31 |
32 |
33 | org.redisson
34 | redisson-spring-boot-starter
35 | 2.14.1
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/lsb-springboot-learn/common/src/main/java/com/example/ComponentTwo.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | @Configuration
7 | public class ComponentTwo {
8 |
9 | @Bean
10 | public void test() {
11 | System.out.println("ComponentTwo test");
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/lsb-springboot-learn/main/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.example
8 | learnSpringboot
9 | 1.0-SNAPSHOT
10 | ../../pom.xml
11 |
12 |
13 | main
14 |
15 |
16 | 17
17 | 17
18 | UTF-8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 | 2.7.5
26 |
27 |
28 | org.projectlombok
29 | lombok
30 | true
31 |
32 |
33 | com.example
34 | common
35 | 1.0-SNAPSHOT
36 | compile
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/lsb-springboot-learn/main/src/main/java/com/example/Application.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 | import org.springframework.context.ApplicationContext;
8 |
9 | @Slf4j
10 | @SpringBootApplication
11 | public class Application {
12 |
13 |
14 | @Autowired
15 | private static ComponentTwo componentTwo;
16 | public static void main(String[] args) {
17 | ApplicationContext context = SpringApplication.run(Application.class, args);
18 | log.info("启动成功!");
19 | // 从 Spring 容器中获取 comOne 实例
20 | ComOne comOne = context.getBean(ComOne.class);
21 | comOne.test();
22 |
23 | ComponentTwo componentTwo = context.getBean(ComponentTwo.class);
24 | componentTwo.test();
25 | // componentTwo.test();
26 |
27 | }
28 |
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/lsb-springboot-learn/main/src/main/java/com/example/ComOne.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.springframework.stereotype.Component;
4 |
5 | @Component
6 | public class ComOne {
7 | public void test(){
8 | System.out.println("comOne test");
9 | }
10 |
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/lsb-swagger/README.md:
--------------------------------------------------------------------------------
1 | ## 地址
2 |
3 | 原始的:http://localhost:8080/swagger-ui.html
4 | 美化的:http://localhost:8080/doc.html
5 |
6 | ## 效果图
7 |
8 | 
--------------------------------------------------------------------------------
/lsb-swagger/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.12.RELEASE
9 |
10 |
11 | com.example
12 | lsb-swagger
13 | 0.0.1-SNAPSHOT
14 | lsb-swagger
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 |
26 |
27 |
28 | org.projectlombok
29 | lombok
30 | true
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-test
35 | test
36 |
37 |
38 | io.springfox
39 | springfox-swagger2
40 | 2.9.2
41 |
42 |
43 | io.springfox
44 | springfox-swagger-ui
45 | 2.9.2
46 |
47 |
48 | com.github.xiaoymin
49 | knife4j-spring-boot-starter
50 | 2.0.1
51 |
52 |
53 |
54 |
55 |
56 |
57 | org.springframework.boot
58 | spring-boot-maven-plugin
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/lsb-swagger/src/main/java/com/example/lsbswagger/LsbSwaggerApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbswagger;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
6 |
7 | @SpringBootApplication
8 | @EnableSwagger2
9 | public class LsbSwaggerApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(LsbSwaggerApplication.class, args);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/lsb-swagger/src/main/java/com/example/lsbswagger/config/Swagger2Config.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbswagger.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import springfox.documentation.builders.ApiInfoBuilder;
6 | import springfox.documentation.builders.PathSelectors;
7 | import springfox.documentation.builders.RequestHandlerSelectors;
8 | import springfox.documentation.service.ApiInfo;
9 | import springfox.documentation.spi.DocumentationType;
10 | import springfox.documentation.spring.web.plugins.Docket;
11 |
12 | /**
13 | * @Description:
14 | * @Author: boolean
15 | * @Date: 2020/1/22 9:49
16 | */
17 | @Configuration
18 | public class Swagger2Config {
19 | @Bean
20 | public Docket create(){
21 | return new Docket(DocumentationType.SWAGGER_2)
22 | .apiInfo(apiInfo())
23 | .select()
24 | .apis(RequestHandlerSelectors.basePackage("com.example.lsbswagger.controller"))
25 | .paths(PathSelectors.any())
26 | .build();
27 | }
28 |
29 | private ApiInfo apiInfo() {
30 | return new ApiInfoBuilder()
31 | .title("接口")
32 | .description("文档")
33 | .termsOfServiceUrl("https://swagger.io/")
34 | .version("v1.0.0")
35 | .build();
36 |
37 | }
38 |
39 |
40 | }
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/lsb-swagger/src/main/java/com/example/lsbswagger/controller/controller.java:
--------------------------------------------------------------------------------
1 | package com.example.lsbswagger.controller;
2 |
3 | import io.swagger.annotations.Api;
4 | import io.swagger.annotations.ApiModel;
5 | import io.swagger.annotations.ApiModelProperty;
6 | import io.swagger.annotations.ApiOperation;
7 | import lombok.Data;
8 | import org.springframework.web.bind.annotation.GetMapping;
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 | /**
12 | * @Description:
13 | * @Author: boolean
14 | * @Date: 2020/1/22 10:03
15 | */
16 | @RestController
17 | @Api(value = "用户", tags = {"用户"})
18 | public class controller {
19 |
20 | @ApiOperation(value = "获取用户信息信息", notes = "根据用户的id来获取用户详细信息")
21 | @GetMapping("/heelo")
22 | public U test(){
23 | return new U();
24 | }
25 | @ApiOperation(value = "获取用户信息信息1", notes = "根据用户的id来获取用户详细信息")
26 | @GetMapping("/heelo1")
27 | public U1 test1(){
28 | return new U1();
29 | }
30 | @ApiOperation(value = "获取用户信息信息2", notes = "根据用户的id来获取用户详细信息")
31 | @GetMapping("/heelo2")
32 | public U test2(){
33 | return new U();
34 | }
35 | @ApiOperation(value = "获取用户信息信息3", notes = "根据用户的id来获取用户详细信息")
36 | @GetMapping("/heelo3")
37 | public U test3(){
38 | return new U();
39 | }
40 |
41 | @Data
42 | @ApiModel("用户实体")
43 | private class U {
44 | @ApiModelProperty("用户 id")
45 | private int id;
46 | @ApiModelProperty("用户 name")
47 | private String name;
48 |
49 | }
50 |
51 | @Data
52 | @ApiModel("用户实体2")
53 | private class U1 {
54 | @ApiModelProperty("用户 id")
55 | private int id;
56 | @ApiModelProperty("用户 name")
57 | private String name;
58 |
59 | }
60 | }
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/lsb-swagger/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/lsb-validation/README.md:
--------------------------------------------------------------------------------
1 | # 入参校验
--------------------------------------------------------------------------------
/lsb-validation/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.springframework.boot
8 | spring-boot-starter-parent
9 | 2.1.11.RELEASE
10 |
11 |
12 | com.example
13 | lsb-validation
14 | 1.0-SNAPSHOT
15 |
16 | 1.8
17 |
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-web
23 |
24 |
25 | org.projectlombok
26 | lombok
27 | true
28 |
29 |
30 | org.springframework.boot
31 | spring-boot-starter-test
32 | test
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | org.springframework.boot
43 | spring-boot-maven-plugin
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/lsb-validation/src/main/java/com/example/gen/ValidationApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.gen;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | @SpringBootApplication
9 | @RestController
10 | public class ValidationApplication {
11 |
12 | public static void main(String[] args) {
13 | SpringApplication.run(ValidationApplication.class, args);
14 | }
15 | @RequestMapping("/validation")
16 | public String test(){
17 | return "gen";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/lsb-validation/src/main/java/com/example/gen/controller/ValidationController.java:
--------------------------------------------------------------------------------
1 | package com.example.gen.controller;
2 |
3 | import com.example.gen.dto.NotBlankDto;
4 | import com.example.gen.dto.NotEmptyDto;
5 | import com.example.gen.dto.NotNullDto;
6 | import org.springframework.validation.annotation.Validated;
7 | import org.springframework.web.bind.annotation.RequestBody;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 |
12 | /**
13 | * @Author 布尔bl
14 | * @create 2020/3/31 11:07
15 | */
16 | @RestController
17 | public class ValidationController {
18 |
19 | @RequestMapping("/NotBlankDto")
20 | public String test(@RequestBody @Validated NotBlankDto dto){
21 | System.out.println("进检验..");
22 | return "NotBlankDto";
23 | }
24 |
25 | @RequestMapping("/NotNullDto")
26 | public String test(@RequestBody @Validated NotNullDto dto){
27 | System.out.println("进检验..");
28 | return "NotNullDto";
29 | }
30 |
31 | @RequestMapping("/NotEmptyDto")
32 | public String test(@RequestBody @Validated NotEmptyDto dto){
33 | System.out.println("进检验..");
34 | return "NotEmptyDto";
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/lsb-validation/src/main/java/com/example/gen/dto/NotBlankDto.java:
--------------------------------------------------------------------------------
1 | package com.example.gen.dto;
2 |
3 | import lombok.Data;
4 |
5 | import javax.validation.constraints.NotBlank;
6 |
7 | /**
8 | * @Author 布尔bl
9 | * @create 2020/3/31 11:09
10 | */
11 | @Data
12 | public class NotBlankDto {
13 | @NotBlank(message = "字段不能为null或者空字符") // 需要是字符
14 | private String name;
15 | }
16 |
--------------------------------------------------------------------------------
/lsb-validation/src/main/java/com/example/gen/dto/NotEmptyDto.java:
--------------------------------------------------------------------------------
1 | package com.example.gen.dto;
2 |
3 | import lombok.Data;
4 |
5 | import javax.validation.constraints.NotEmpty;
6 |
7 | /**
8 | * @Author 布尔bl
9 | * @create 2020/3/31 15:26
10 | */
11 | @Data
12 | public class NotEmptyDto {
13 | @NotEmpty(message = "字段不能为null或者空字符")
14 | private String name;
15 | }
16 |
--------------------------------------------------------------------------------
/lsb-validation/src/main/java/com/example/gen/dto/NotNullDto.java:
--------------------------------------------------------------------------------
1 | package com.example.gen.dto;
2 |
3 | import lombok.Data;
4 |
5 | import javax.validation.constraints.NotNull;
6 |
7 | /**
8 | * @Author 布尔bl
9 | * @create 2020/3/31 15:21
10 | */
11 | @Data
12 | public class NotNullDto {
13 | @NotNull(message ="字段不能为null") // 使用所有类型
14 | private Integer name;
15 | }
16 |
--------------------------------------------------------------------------------
/lsb-validation/src/main/java/com/example/gen/util/GlobalException.java:
--------------------------------------------------------------------------------
1 | package com.example.gen.util;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.springframework.web.bind.annotation.ExceptionHandler;
5 | import org.springframework.web.bind.annotation.RestControllerAdvice;
6 |
7 |
8 | /**
9 | * @Description: 全局的异常返回
10 | * @Author: boolean
11 | * @Date: 2019/12/10 0:14
12 | */
13 | @Slf4j
14 | @RestControllerAdvice
15 | public class GlobalException {
16 |
17 | // 拦截器
18 | @ExceptionHandler({Exception.class})
19 | public Result exception(Exception e){
20 | Result result = new Result();
21 | result.setCode(500);
22 | result.setMsg(e.getMessage());
23 | log.error("报错了",e);
24 | return result;
25 | }
26 |
27 |
28 | }
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/lsb-validation/src/main/java/com/example/gen/util/Result.java:
--------------------------------------------------------------------------------
1 | package com.example.gen.util;
2 |
3 | import lombok.Data;
4 |
5 |
6 | /**
7 | * @Description:
8 | * @Author: boolean
9 | * @Date: 2019/12/9 16:59
10 | */
11 | @Data
12 | public class Result {
13 |
14 | /**
15 | * 返回码
16 | */
17 | private Integer code;
18 |
19 | /**
20 | * 返回码状态
21 | */
22 | private String msg;
23 |
24 |
25 |
26 | }
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/lsb-webScocketOne/README.md:
--------------------------------------------------------------------------------
1 | ### 客户端
2 | http://coolaf.com/tool/chattest
3 |
--------------------------------------------------------------------------------
/lsb-webScocketOne/pom.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 | learnSpringboot
5 | com.example
6 | 1.0-SNAPSHOT
7 |
8 | 4.0.0
9 |
10 | lsb-webScocketOne
11 | jar
12 |
13 | lsb-webScocketOne
14 | http://maven.apache.org
15 |
16 |
17 | UTF-8
18 |
19 |
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter-websocket
24 |
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-starter-web
29 |
30 |
31 |
32 | org.projectlombok
33 | lombok
34 | true
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-test
39 | test
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | org.springframework.boot
48 | spring-boot-maven-plugin
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/lsb-webScocketOne/src/main/java/com/example/DemoApplication.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class DemoApplication {
8 | public static void main(String[] args) {
9 | SpringApplication.run(DemoApplication.class, args);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/lsb-webScocketOne/src/main/java/com/example/WebSocketConfig.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.web.socket.server.standard.ServerEndpointExporter;
6 |
7 | @Configuration
8 | public class WebSocketConfig {
9 |
10 | @Bean
11 | public ServerEndpointExporter serverEndpointExporter() {
12 | return new ServerEndpointExporter();
13 | }
14 |
15 | }
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 | pom
7 |
8 | org.springframework.boot
9 | spring-boot-starter-parent
10 | 2.1.11.RELEASE
11 |
12 |
13 | com.example
14 | learnSpringboot
15 | 1.0-SNAPSHOT
16 |
17 | lsb-mq
18 | lsb-aop
19 | lsb-crub
20 | lsb-crub-plus
21 | lsb-druid
22 | lsb-es
23 | lsb-email
24 | lsb-helloworld
25 | lsb-interceptor
26 | lsb-profiles
27 | lsb-validation
28 | lsb-swagger
29 | lsb-shiro
30 | lsb-security
31 | lsb-digui
32 | lsb-login
33 | lsb-redistest
34 | lsb-restful
35 | lsb-scheduledtask
36 | lsb-mybatis_generator
37 | lsb-crub-jpa
38 | lsb-webScocketOne
39 | lsb-springboot-learn/main
40 | lsb-springboot-learn/common
41 |
42 |
--------------------------------------------------------------------------------