├── .gitignore ├── README.md ├── lsb-aop ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ └── gen │ │ ├── Entity.java │ │ ├── LsbAopApplication.java │ │ └── service │ │ ├── AsyncService.java │ │ ├── Buer.java │ │ ├── C.java │ │ ├── ClassA.java │ │ ├── ClassB.java │ │ ├── Idemo.java │ │ └── impl │ │ ├── AsyncServiceImpl.java │ │ ├── BuerAop.java │ │ └── DemoImpl.java │ └── resources │ └── application.properties ├── lsb-crub-jpa ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ └── lsbcrudjpa │ │ ├── LsbCrubJpaApplication.java │ │ ├── dao │ │ └── UserRepository.java │ │ ├── entity │ │ └── User.java │ │ ├── enums │ │ └── ResultEnum.java │ │ ├── service │ │ ├── IUserService.java │ │ └── impl │ │ │ └── UserServiceImpl.java │ │ └── util │ │ ├── GlobalException.java │ │ └── Result.java │ └── resources │ └── application.yml ├── lsb-crub-plus ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── lsbcrudplus │ │ │ ├── LsbCrubPlusApplication.java │ │ │ ├── controller │ │ │ └── UserController.java │ │ │ ├── emum │ │ │ └── ResultEnum.java │ │ │ ├── entity │ │ │ └── User.java │ │ │ ├── mapper │ │ │ ├── UserMapper.java │ │ │ └── UserMapper.xml │ │ │ ├── service │ │ │ ├── Compent.java │ │ │ ├── IUserService.java │ │ │ └── impl │ │ │ │ └── UserServiceImpl.java │ │ │ └── util │ │ │ ├── CustomIdGenerator.java │ │ │ ├── GlobalException.java │ │ │ ├── IdGenerator.java │ │ │ ├── LsbcrudplusException.java │ │ │ ├── MybatisPlusConfig.java │ │ │ └── Result.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── example │ └── lsbcrubplus │ └── LsbCrubPlusApplicationTests.java ├── lsb-crub ├── README.md ├── clean.sh ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── crud │ │ │ ├── CrudApplication.java │ │ │ ├── ServletInitializer.java │ │ │ ├── controller │ │ │ ├── NameController.java │ │ │ ├── PeopleController.java │ │ │ └── UserController.java │ │ │ ├── entity │ │ │ ├── Name.java │ │ │ ├── People.java │ │ │ └── User.java │ │ │ ├── mapper │ │ │ ├── NameMapper.java │ │ │ ├── NameMapper.xml │ │ │ ├── PeopleMapper.java │ │ │ ├── PeopleMapper.xml │ │ │ ├── UserMapper.java │ │ │ └── UserMapper.xml │ │ │ ├── service │ │ │ ├── AsyncConfig.java │ │ │ ├── AsyncService.java │ │ │ ├── CompentService.java │ │ │ ├── INameService.java │ │ │ ├── IPeopleService.java │ │ │ ├── IUserService.java │ │ │ └── impl │ │ │ │ ├── Compant.java │ │ │ │ ├── CompentServiceImplOne.java │ │ │ │ ├── CompentServiceImplThird.java │ │ │ │ ├── CompentServiceImplTotal.java │ │ │ │ ├── CompentServiceImplTwo.java │ │ │ │ ├── NameServiceImpl.java │ │ │ │ ├── TestService.java │ │ │ │ ├── UserJDBCServiceImpl.java │ │ │ │ ├── UserJDBCServiceImplA.java │ │ │ │ ├── UserJDBCServiceImplB.java │ │ │ │ └── UserServiceImpl.java │ │ │ └── util │ │ │ ├── Component.java │ │ │ └── Config.java │ └── resources │ │ ├── application.yml │ │ ├── banner.txt │ │ ├── generatorConfig.xml │ │ └── templates │ │ ├── edit.html │ │ └── list.html │ └── test │ └── java │ └── com │ └── example │ └── crud │ ├── AsyncTest.java │ ├── Clothes.java │ ├── Clothes1.java │ ├── CodeGenerator.java │ ├── CrudApplicationTest.java │ ├── Test.java │ ├── TestPdf.java │ ├── User.java │ └── User1.java ├── lsb-digui ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ └── lsbdigui │ │ ├── LsbDiguiApplication.java │ │ ├── ServletInitializer.java │ │ ├── controller │ │ └── DiguiController.java │ │ ├── emum │ │ └── ResultEnum.java │ │ ├── entity │ │ └── Digui.java │ │ ├── mapper │ │ └── DiguiMapper.java │ │ ├── service │ │ ├── IDiguiService.java │ │ └── impl │ │ │ └── DiguiServiceImpl.java │ │ └── util │ │ ├── DiguiException.java │ │ ├── GlobalException.java │ │ └── Result.java │ └── resources │ ├── application.yml │ └── mapper │ └── DiguiMapper.xml ├── lsb-druid ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ └── lsbdruid │ │ ├── LsbDruidApplication.java │ │ ├── controller │ │ └── MyUserController.java │ │ ├── entity │ │ └── MyUser.java │ │ ├── mapper │ │ ├── MyUserMapper.java │ │ └── UserMapper.xml │ │ └── service │ │ ├── IMyUserService.java │ │ └── impl │ │ └── MyUserServiceImpl.java │ └── resources │ ├── application.properties │ └── banner.txt ├── lsb-email ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ └── lsbemail │ │ └── LsbEmailApplication.java │ └── resources │ ├── application.properties │ └── banner.txt ├── lsb-es ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ └── lsbes │ │ ├── LsbEsApplication.java │ │ └── ServletInitializer.java │ └── resources │ └── application.properties ├── lsb-helloworld ├── Dockerfile ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ └── demo2 │ │ └── Demo2Application.java │ └── resources │ ├── application.properties │ └── banner.txt ├── lsb-interceptor ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ └── lsbinterceptor │ │ ├── LsbInterceptorApplication.java │ │ ├── config │ │ ├── Log.java │ │ ├── LogAspect.java │ │ └── MyInterceptor.java │ │ ├── controller │ │ └── DemoController.java │ │ └── service │ │ ├── DemoServie.java │ │ └── impl │ │ └── DemoServiceImpl.java │ └── resources │ └── application.properties ├── lsb-login ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ └── demo │ │ └── DemoApplication.java │ └── resources │ └── application.properties ├── lsb-mq ├── README.md ├── img.png ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ └── lsbmq │ │ ├── LsbMqApplication.java │ │ ├── rabbit │ │ ├── RabbitConfig.java │ │ ├── Receiver.java │ │ └── Sender.java │ │ └── rockertmq │ │ ├── MQConsumerConfiguration.java │ │ ├── MQProducerConfiguration.java │ │ └── MessageListenerHandler.java │ └── resources │ └── application.yml ├── lsb-mybatis_generator ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── example │ └── gen │ └── GenApplication.java ├── lsb-profiles ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ └── lsbprofiles │ │ └── LsbProfilesApplication.java │ └── resources │ └── application.yml ├── lsb-redistest ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ └── lsbredistest │ │ ├── LsbRedistestApplication.java │ │ ├── ServletInitializer.java │ │ └── controller │ │ ├── RedisController.java │ │ └── entity │ │ └── User.java │ └── resources │ └── application.yml ├── lsb-restful ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ └── lsbrestful │ │ └── LsbRestfulApplication.java │ └── resources │ └── application.properties ├── lsb-scheduledtask ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── example │ └── LsbSchduledTaskApplication.java ├── lsb-security ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ └── lsbsecurity │ │ ├── LsbSecurityApplication.java │ │ └── config │ │ ├── MvcConfig.java │ │ └── WebSecurityConfig.java │ └── resources │ ├── application.properties │ └── templates │ ├── hello.html │ └── logout.html ├── lsb-shiro ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ ├── com │ │ └── example │ │ │ └── demo │ │ │ ├── DemoApplication.java │ │ │ ├── Dto │ │ │ └── Dto.java │ │ │ ├── config │ │ │ ├── FilterConfig.java │ │ │ ├── GlobalCorsConfig.java │ │ │ ├── ShiroSessionManager.java │ │ │ ├── ShrioConfig.java │ │ │ └── UserRealm.java │ │ │ ├── controller │ │ │ └── TestController.java │ │ │ ├── entity │ │ │ └── ShiroUser.java │ │ │ ├── mapper │ │ │ ├── ShiroUserMapper.java │ │ │ └── ShiroUserMapper.xml │ │ │ └── service │ │ │ ├── IShiroUserService.java │ │ │ └── Impl │ │ │ └── ShiroUserServieImpl.java │ └── rebel.xml │ └── resources │ ├── application.yml │ ├── shiro_user.sql │ └── templates │ ├── hello.html │ ├── login.html │ ├── logout.html │ ├── noauto.html │ └── user │ ├── add.html │ └── update.html ├── lsb-springboot-learn ├── common │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── example │ │ └── ComponentTwo.java └── main │ ├── pom.xml │ └── src │ └── main │ └── java │ └── com │ └── example │ ├── Application.java │ └── ComOne.java ├── lsb-swagger ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ └── lsbswagger │ │ ├── LsbSwaggerApplication.java │ │ ├── config │ │ └── Swagger2Config.java │ │ └── controller │ │ └── controller.java │ └── resources │ └── application.properties ├── lsb-validation ├── README.md ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── example │ └── gen │ ├── ValidationApplication.java │ ├── controller │ └── ValidationController.java │ ├── dto │ ├── NotBlankDto.java │ ├── NotEmptyDto.java │ └── NotNullDto.java │ └── util │ ├── GlobalException.java │ └── Result.java ├── lsb-webScocketOne ├── README.md ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── example │ ├── DemoApplication.java │ ├── WebSocket.java │ └── WebSocketConfig.java └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | /*/target/ 2 | .idea 3 | *.iws 4 | *.iml 5 | /*/mvnw 6 | /*/mvnw.cmd 7 | /*/.mvn/ 8 | */src/main/resources/rebel.xml 9 | */src/test/ 10 | 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # learnSpringboot 2 | > 愿天下没有难学的技术 3 | 4 | ## 部署 5 | 6 | ![](http://javahouse.xyz/20200320122034.png) 7 | 8 | ## 基础架构篇 9 | 10 | - [lsb-第一行代码(SpringBoot)](/lsb-helloworld) 11 | 12 | - [lsb-SpringBoot基础架构篇1(SpringBoot、MyBatis-Plus与Thymeleaf)](/lsb-crub) 13 | 14 | - [lsb-SpringBoot基础架构篇2(SpringBoot与MyBatis-Plus)](/lsb-crub-plus) 15 | 16 | - [lsb-SpringBoot基础架构篇3(Redis)](/lsb-redistest) 17 | 18 | - [lsb-SpringBoot基础架构篇4(SpringBoot与 RabbitMQ)](/lsb-mq) 19 | 20 | - [lsb-SpringBoot基础架构篇5(SpringBoot与)]() 21 | 22 | - [lsb-SpringBoot基础架构篇6(Druid的监控)](/lsb-druid) 23 | 24 | - [lsb-SpringBoot基础架构篇7(security鉴权)](/lsb-security) 25 | 26 | - [lsb-SpringBoot基础架构篇8(shiro)](/lsb-shiro) 27 | 28 | - [lsb-SpringBoot之多环境配置](/lsb-profiles) 29 | 30 | 31 | ## 应用实战篇 32 | 33 | 34 | - [lsb-MySQL 递归查询](/lsb-digui) 35 | 36 | - [lsb-邮件发送](/lsb-email) 37 | 38 | - [lsb-入参校验](/lsb-validation) 39 | 40 | - [lsb-切面结合注解](/lsb-aop) 41 | 42 | - [lsb-拦截器使用](/lsb-interceptor) 43 | 44 | - [lsb-如何设计一个优雅的RESTFUL的接口](/lsb-restful) 45 | 46 | - [lsb-用swagger管理接口](/lsb-swagger) 47 | 48 | - [lsb-登录的几种常见方法](/lsb-login) 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /lsb-aop/README.md: -------------------------------------------------------------------------------- 1 | >show me the code and talk to me,做的出来更要说的明白 2 | >我是布尔bl,你的支持是我分享的动力! 3 | 4 | 5 | 6 | 7 | ## maven 8 | ```java 9 | 10 | org.springframework.boot 11 | spring-boot-starter-aop 12 | 13 | ``` 14 | 15 | 16 | ### 启动 17 | 18 | 运行 learnSpringboot\lsb-aop\src\test\java\com\example\lsbaop\LsbAopApplicationTests.java 19 | 20 | ### 关注微信公众号,随时移动端阅读 21 | 22 | ![](http://javahouse.xyz/20200106104817.png) 23 | -------------------------------------------------------------------------------- /lsb-aop/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | pom 6 | 7 | 8 | org.springframework.boot 9 | spring-boot-starter-parent 10 | 2.1.12.RELEASE 11 | 12 | 13 | com.example 14 | lsb-aop 15 | 0.0.1-SNAPSHOT 16 | lsb-aop 17 | Demo project for Spring Boot 18 | 19 | 20 | 1.8 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter 27 | 28 | 29 | 30 | org.projectlombok 31 | lombok 32 | true 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter-aop 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-web 46 | 47 | 48 | org.springframework 49 | spring-tx 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-maven-plugin 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /lsb-aop/src/main/java/com/example/gen/Entity.java: -------------------------------------------------------------------------------- 1 | package com.example.gen; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | /** 7 | * @Author 布尔bl 8 | * @create 2020/4/24 18:51 9 | */ 10 | @Data 11 | @AllArgsConstructor 12 | public class Entity { 13 | Integer num; 14 | String name; 15 | } 16 | -------------------------------------------------------------------------------- /lsb-aop/src/main/java/com/example/gen/LsbAopApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.gen; 2 | 3 | import com.example.gen.service.Idemo; 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.scheduling.annotation.EnableAsync; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | 12 | @SpringBootApplication 13 | @RestController 14 | @EnableAsync 15 | public class LsbAopApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(LsbAopApplication.class, args); 19 | } 20 | @Autowired 21 | private Idemo idemoImpl; 22 | @RequestMapping 23 | public void test(){ 24 | idemoImpl.demo(new Entity(1,"sa")); 25 | System.out.println("执行controller方法"); 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /lsb-aop/src/main/java/com/example/gen/service/AsyncService.java: -------------------------------------------------------------------------------- 1 | package com.example.gen.service; 2 | 3 | /** 4 | * @Author 布尔bl 5 | * @create 2020/8/31 23:50 6 | */ 7 | public interface AsyncService { 8 | 9 | void testAsync(String name); 10 | } 11 | -------------------------------------------------------------------------------- /lsb-aop/src/main/java/com/example/gen/service/Buer.java: -------------------------------------------------------------------------------- 1 | package com.example.gen.service; 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 | 9 | @Retention(RetentionPolicy.RUNTIME) 10 | @Target(ElementType.METHOD) 11 | public @interface Buer { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /lsb-aop/src/main/java/com/example/gen/service/C.java: -------------------------------------------------------------------------------- 1 | package com.example.gen.service; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service 6 | public class C { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /lsb-aop/src/main/java/com/example/gen/service/ClassA.java: -------------------------------------------------------------------------------- 1 | package com.example.gen.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | 6 | @Service 7 | public class ClassA { 8 | 9 | private final ClassB classB; 10 | 11 | public ClassA(ClassB classB) { 12 | this.classB = classB; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /lsb-aop/src/main/java/com/example/gen/service/ClassB.java: -------------------------------------------------------------------------------- 1 | package com.example.gen.service; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service 6 | public class ClassB { 7 | 8 | private final ClassA classA; 9 | 10 | public ClassB(ClassA classA) { 11 | this.classA = classA; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /lsb-aop/src/main/java/com/example/gen/service/Idemo.java: -------------------------------------------------------------------------------- 1 | package com.example.gen.service; 2 | 3 | import com.example.gen.Entity; 4 | 5 | /** 6 | * @Description: 7 | * @Author: boolean 8 | * @Date: 2020/1/17 14:24 9 | */ 10 | 11 | 12 | public interface Idemo { 13 | 14 | void demo(Entity entity); 15 | } 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /lsb-aop/src/main/java/com/example/gen/service/impl/AsyncServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.gen.service.impl; 2 | 3 | import com.example.gen.service.AsyncService; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.scheduling.annotation.Async; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * @Author 布尔bl 10 | * @create 2020/8/31 23:52 11 | */ 12 | @Slf4j 13 | @Component 14 | public class AsyncServiceImpl { 15 | 16 | @Async 17 | public void testAsync(String name) { 18 | log.info("异步开始"); 19 | System.out.println(11); 20 | try { 21 | Thread.sleep(1000); 22 | System.out.println(name); 23 | log.info(name); 24 | int i = 1 / 0; 25 | } catch (InterruptedException e) { 26 | e.printStackTrace(); 27 | } 28 | log.info("结束"); 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /lsb-aop/src/main/java/com/example/gen/service/impl/BuerAop.java: -------------------------------------------------------------------------------- 1 | package com.example.gen.service.impl; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.aspectj.lang.ProceedingJoinPoint; 5 | import org.aspectj.lang.annotation.Around; 6 | import org.aspectj.lang.annotation.Aspect; 7 | import org.aspectj.lang.annotation.Pointcut; 8 | import org.springframework.stereotype.Component; 9 | 10 | import java.util.Arrays; 11 | 12 | /** 13 | * @Description: 14 | * @Author: boolean 15 | * @Date: 2020/1/17 14:27 16 | */ 17 | @Component 18 | @Aspect 19 | @Slf4j 20 | public class BuerAop { 21 | // 1 直接扫描注解 22 | @Pointcut("@annotation(com.example.gen.service.Buer))") 23 | // 2 直接扫描注解方法 24 | // @Pointcut("execution(* com.example.gen.service..*.*(..))") 25 | public void test(){ 26 | 27 | } 28 | // @Before("test()") 29 | // public void before(){ 30 | // log.info("我是切面"); 31 | // } 32 | 33 | 34 | @Around("test()") 35 | public void test(ProceedingJoinPoint point){ 36 | try { 37 | Object[] args = point.getArgs(); // 获取参数 38 | System.out.println(Arrays.toString(args)); 39 | System.out.println("我是环绕通知前"); 40 | point.proceed(); 41 | System.out.println("我是环绕通止后"); 42 | } catch (Throwable throwable) { 43 | throwable.printStackTrace(); 44 | } 45 | } 46 | } 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /lsb-aop/src/main/java/com/example/gen/service/impl/DemoImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.gen.service.impl; 2 | 3 | import com.example.gen.Entity; 4 | import com.example.gen.service.Buer; 5 | import com.example.gen.service.Idemo; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * @Description: 11 | * @Author: boolean 12 | * @Date: 2020/1/17 14:25 13 | */ 14 | @Slf4j 15 | @Service 16 | public class DemoImpl implements Idemo { 17 | @Override 18 | @Buer 19 | public void demo(Entity entity) { 20 | log.info("我是Service"); 21 | } 22 | } 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /lsb-aop/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lsb-crub-jpa/README.md: -------------------------------------------------------------------------------- 1 | 规范大于约定,不需要写sql,借助hibernate -------------------------------------------------------------------------------- /lsb-crub-jpa/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | learnSpringboot 7 | com.example 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | lsb-crub-jpa 13 | 14 | 15 | 8 16 | 8 17 | 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-web 23 | 24 | 25 | 26 | mysql 27 | mysql-connector-java 28 | runtime 29 | 30 | 31 | org.projectlombok 32 | lombok 33 | true 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-tomcat 38 | provided 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-test 43 | test 44 | 45 | 46 | com.google.code.gson 47 | gson 48 | 2.8.5 49 | 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-starter-data-jpa 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | org.springframework.boot 62 | spring-boot-maven-plugin 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /lsb-crub-jpa/src/main/java/com/example/lsbcrudjpa/LsbCrubJpaApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudjpa; 2 | 3 | import com.example.lsbcrudjpa.service.IUserService; 4 | import com.example.lsbcrudjpa.service.impl.UserServiceImpl; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.SpringApplication; 8 | import org.springframework.boot.autoconfigure.SpringBootApplication; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | @SpringBootApplication 13 | @RestController 14 | @Slf4j 15 | public class LsbCrubJpaApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(LsbCrubJpaApplication.class, args); 19 | // ApplicationContext applicationContext = new AnnotationConfigApplicationContext(UserServiceImpl.class); 20 | // //打印所有在容器中的实例(Bean) 21 | // String[] beanNames = applicationContext.getBeanDefinitionNames(); 22 | // for (String beanName : beanNames) { 23 | // System.out.println("sss:“" + beanName); 24 | // 25 | // } 26 | } 27 | 28 | @Autowired 29 | private IUserService userService; 30 | 31 | @GetMapping("/demo") 32 | public String hello() { 33 | return "LsbCrubJpa"; 34 | } 35 | 36 | @GetMapping("/user") 37 | public void user() { 38 | userService.test1(); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /lsb-crub-jpa/src/main/java/com/example/lsbcrudjpa/dao/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudjpa.dao; 2 | 3 | import com.example.lsbcrudjpa.entity.User; 4 | import org.springframework.data.domain.Page; 5 | import org.springframework.data.domain.Pageable; 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | import org.springframework.stereotype.Repository; 8 | 9 | import java.util.List; 10 | 11 | @Repository 12 | public interface UserRepository extends JpaRepository { 13 | Long countByName(String lastname); 14 | 15 | List findByAdressOrderByName(String adress); 16 | 17 | Page queryFirst10ByAdress(String adress, Pageable pageable); 18 | 19 | Page findByAdress(String adress, Pageable pageable); 20 | } 21 | -------------------------------------------------------------------------------- /lsb-crub-jpa/src/main/java/com/example/lsbcrudjpa/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudjpa.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | import lombok.NoArgsConstructor; 7 | import lombok.experimental.Accessors; 8 | 9 | import javax.persistence.Entity; 10 | import javax.persistence.Id; 11 | import javax.persistence.Table; 12 | import java.io.Serializable; 13 | 14 | /** 15 | *

16 | * 17 | *

18 | * 19 | * @author jobob 20 | * @since 2019-12-09 21 | */ 22 | @Data 23 | @EqualsAndHashCode(callSuper = false) 24 | @Accessors(chain = true) 25 | @AllArgsConstructor 26 | @NoArgsConstructor 27 | @Entity 28 | @Table(name = "user") 29 | public class User implements Serializable { 30 | 31 | 32 | private static final long serialVersionUID=1L; 33 | 34 | /** 35 | * 主键ID 36 | */ 37 | @Id 38 | private Long id; 39 | 40 | /** 41 | * 姓名 42 | */ 43 | private String name; 44 | 45 | private String password; 46 | 47 | /** 48 | * 邮箱 49 | */ 50 | private String adress; 51 | 52 | private Integer status; 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /lsb-crub-jpa/src/main/java/com/example/lsbcrudjpa/enums/ResultEnum.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudjpa.enums; 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-crub-jpa/src/main/java/com/example/lsbcrudjpa/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudjpa.service; 2 | 3 | 4 | import com.example.lsbcrudjpa.entity.User; 5 | import org.springframework.data.domain.Page; 6 | import org.springframework.data.domain.Pageable; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | *

12 | * 服务类 13 | *

14 | * 15 | * @author jobob 16 | * @since 2019-12-09 17 | */ 18 | public interface IUserService { 19 | 20 | Boolean saveOne(); 21 | 22 | void test1(); 23 | 24 | Long countByName(String name); 25 | 26 | List findByAdressOrderByName(String adress); 27 | 28 | Page queryFirst10ByAdress(String adress, Pageable pageable); 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /lsb-crub-jpa/src/main/java/com/example/lsbcrudjpa/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudjpa.service.impl; 2 | 3 | 4 | import com.example.lsbcrudjpa.dao.UserRepository; 5 | import com.example.lsbcrudjpa.entity.User; 6 | import com.example.lsbcrudjpa.service.IUserService; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.data.domain.Page; 10 | import org.springframework.data.domain.Pageable; 11 | import org.springframework.stereotype.Service; 12 | 13 | import java.util.List; 14 | import java.util.Optional; 15 | 16 | /** 17 | *

18 | * 服务实现类 19 | *

20 | * 21 | * @author jobob 22 | * @since 2019-12-09 23 | */ 24 | 25 | @Slf4j 26 | @Service 27 | public class UserServiceImpl implements IUserService { 28 | 29 | @Autowired 30 | private UserRepository userRepository; 31 | 32 | @Override 33 | public Boolean saveOne() { 34 | return null; 35 | } 36 | 37 | @Override 38 | public void test1() { 39 | log.info("i am userServiceImpl"); 40 | } 41 | 42 | @Override 43 | public Long countByName(String name) { 44 | return userRepository.countByName(name); 45 | } 46 | 47 | @Override 48 | public List findByAdressOrderByName(String adress) { 49 | return userRepository.findByAdressOrderByName(adress); 50 | } 51 | 52 | @Override 53 | public Page queryFirst10ByAdress(String adress, Pageable pageable) { 54 | return userRepository.queryFirst10ByAdress(adress, pageable); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /lsb-crub-jpa/src/main/java/com/example/lsbcrudjpa/util/GlobalException.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudjpa.util; 2 | 3 | import com.example.lsbcrudjpa.enums.ResultEnum; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.web.bind.annotation.ExceptionHandler; 6 | import org.springframework.web.bind.annotation.RestControllerAdvice; 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(ResultEnum.ERROR.getCode()); 22 | result.setMsg(ResultEnum.ERROR.getMsg()); 23 | result.setDate(e.getMessage()); 24 | log.error("报错了",e); 25 | return result; 26 | } 27 | 28 | 29 | } 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /lsb-crub-jpa/src/main/java/com/example/lsbcrudjpa/util/Result.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudjpa.util; 2 | 3 | import com.example.lsbcrudjpa.enums.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-crub-jpa/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | url: jdbc:mysql://127.0.0.1/dev?serverTimezone=GMT%2B8 4 | username: root 5 | password: 123456 6 | jpa: 7 | hibernate: 8 | ddl-auto: update # 更新或者创建数据表结构 之前提到过,如果数据库中没做表,Jpa会我们创建 这个配置就是在没有表的时候创建,实体类发生改变的话 会更新表结构 9 | show-sql: true # 配置在日志中打印出执行的 SQL 语句信息 10 | logging: 11 | level: 12 | com.example.lsbcrudplus.mapper.UserMapper: debug # 改成你的mapper文件所在包路径 13 | -------------------------------------------------------------------------------- /lsb-crub-plus/README.md: -------------------------------------------------------------------------------- 1 | # 做一个优雅的CRUD-BOY 2 | 3 | ### 统一的返回更规范 4 | ![](http://javahouse.xyz/20200106113536.png) 5 | ### 枚举类更清晰 6 | ### 继承RuntimeException更专业 7 | ### 全局捕获异常返回更省心 8 | 9 | ![](http://javahouse.xyz/20200106113453.png) 10 | -------------------------------------------------------------------------------- /lsb-crub-plus/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-crub-plus 13 | 0.0.1-SNAPSHOT 14 | war 15 | lsb-crub-plus 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 | mysql 30 | mysql-connector-java 31 | runtime 32 | 33 | 34 | org.projectlombok 35 | lombok 36 | true 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-tomcat 41 | provided 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-test 46 | test 47 | 48 | 49 | 50 | com.baomidou 51 | mybatis-plus-boot-starter 52 | 3.4.0 53 | 54 | 55 | com.google.code.gson 56 | gson 57 | 2.8.5 58 | 59 | 60 | 61 | 62 | 63 | 64 | org.springframework.boot 65 | spring-boot-maven-plugin 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /lsb-crub-plus/src/main/java/com/example/lsbcrudplus/LsbCrubPlusApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudplus; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 5 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 6 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; 7 | import com.example.lsbcrudplus.entity.User; 8 | import com.example.lsbcrudplus.service.IUserService; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.hibernate.validator.constraints.br.TituloEleitoral; 11 | import org.mybatis.spring.annotation.MapperScan; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.boot.SpringApplication; 14 | import org.springframework.boot.autoconfigure.SpringBootApplication; 15 | import org.springframework.web.bind.annotation.GetMapping; 16 | import org.springframework.web.bind.annotation.RequestMapping; 17 | import org.springframework.web.bind.annotation.RestController; 18 | 19 | import java.util.HashMap; 20 | import java.util.List; 21 | import java.util.Map; 22 | import java.util.stream.Collectors; 23 | 24 | @SpringBootApplication 25 | @RestController 26 | @MapperScan("com.example.lsbcrudplus.mapper") 27 | @Slf4j 28 | public class LsbCrubPlusApplication { 29 | 30 | public static void main(String[] args) { 31 | SpringApplication.run(LsbCrubPlusApplication.class, args); 32 | 33 | } 34 | 35 | @Autowired 36 | private IUserService userService; 37 | 38 | @RequestMapping 39 | public String hello() { 40 | 41 | return "LsbCrubPlus"; 42 | } 43 | 44 | @GetMapping("/list") 45 | public User list() { 46 | log.info("开始查询"); 47 | List userList = userService.list(); 48 | userList.forEach(System.out::println); 49 | System.out.println("============================"); 50 | userList.forEach(System.out::println); 51 | System.out.println("=============================="); 52 | userList.stream().filter(u -> u.getId() == 1).collect(Collectors.toList()).forEach(System.out::println); 53 | System.out.println("==============================="); 54 | userList.stream().map(User::getId).collect(Collectors.toList()).forEach(System.out::println); 55 | System.out.println("=====================1"); 56 | Map longStringMap = userList.stream().collect(Collectors.toMap(User::getId, User::getName)); 57 | 58 | longStringMap.forEach((k, v) -> System.out.println(k + "--" + v)); 59 | return null; 60 | } 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /lsb-crub-plus/src/main/java/com/example/lsbcrudplus/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudplus.controller; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 5 | import com.example.lsbcrudplus.entity.User; 6 | import com.example.lsbcrudplus.service.IUserService; 7 | import com.example.lsbcrudplus.util.Result; 8 | import lombok.extern.java.Log; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.bind.annotation.GetMapping; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import java.util.List; 16 | import java.util.Objects; 17 | 18 | /** 19 | *

20 | * 前端控制器 21 | *

22 | * 23 | * @author jobob 24 | * @since 2019-12-09 25 | */ 26 | @Log 27 | @RestController 28 | @RequestMapping("/lsbcrud/user") 29 | public class UserController { 30 | @Autowired 31 | private IUserService userService; 32 | 33 | @RequestMapping("/getList") 34 | public Result getList() { 35 | return Result.getResult(userService.list(new QueryWrapper().select().eq("id", 1))); 36 | } 37 | 38 | @RequestMapping("/saveOne") 39 | public Result saveOne() { 40 | return Result.getResult(userService.saveOne()); 41 | } 42 | 43 | @GetMapping("/add") 44 | public synchronized Boolean add() { 45 | String name = "chenwe"; 46 | List list = userService.list(new QueryWrapper().eq("name", name)); 47 | if (Objects.nonNull(list) && list.size() == 0) { 48 | User user = new User(); 49 | user.setName(name); 50 | user.setPassword("123"); 51 | user.setAddress("中国"); 52 | user.setStatus(0); 53 | return userService.save(user); 54 | } 55 | return false; 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /lsb-crub-plus/src/main/java/com/example/lsbcrudplus/emum/ResultEnum.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudplus.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-crub-plus/src/main/java/com/example/lsbcrudplus/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudplus.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | import com.baomidou.mybatisplus.annotation.IdType; 6 | import com.baomidou.mybatisplus.annotation.TableField; 7 | import com.baomidou.mybatisplus.annotation.TableId; 8 | import lombok.AllArgsConstructor; 9 | import lombok.Data; 10 | import lombok.EqualsAndHashCode; 11 | import lombok.NoArgsConstructor; 12 | import lombok.experimental.Accessors; 13 | 14 | /** 15 | *

16 | * 17 | *

18 | * 19 | * @author jobob 20 | * @since 2019-12-09 21 | */ 22 | @Data 23 | @EqualsAndHashCode(callSuper = false) 24 | @Accessors(chain = true) 25 | @AllArgsConstructor 26 | @NoArgsConstructor 27 | public class User implements Serializable { 28 | 29 | 30 | private static final long serialVersionUID=1L; 31 | 32 | /** 33 | * 主键ID 34 | */ 35 | @TableId(type = IdType.ASSIGN_ID) 36 | private Long id; 37 | 38 | /** 39 | * 姓名 40 | */ 41 | private String name; 42 | 43 | private String password; 44 | 45 | /** 46 | * 邮箱 47 | */ 48 | // @TableField(exist = false) 49 | private String address; 50 | 51 | private Integer status; 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /lsb-crub-plus/src/main/java/com/example/lsbcrudplus/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudplus.mapper; 2 | 3 | import com.example.lsbcrudplus.entity.User; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | /** 8 | *

9 | * Mapper 接口 10 | *

11 | * 12 | * @author jobob 13 | * @since 2019-12-09 14 | */ 15 | @Mapper 16 | public interface UserMapper extends BaseMapper { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /lsb-crub-plus/src/main/java/com/example/lsbcrudplus/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /lsb-crub-plus/src/main/java/com/example/lsbcrudplus/service/Compent.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudplus.service; 2 | 3 | import com.example.lsbcrudplus.entity.User; 4 | import com.example.lsbcrudplus.mapper.UserMapper; 5 | import org.springframework.stereotype.Service; 6 | import org.springframework.transaction.annotation.Propagation; 7 | import org.springframework.transaction.annotation.Transactional; 8 | 9 | import javax.annotation.Resource; 10 | 11 | /** 12 | * @Author 布尔bl 13 | * @create 2020/11/9 22:57 14 | */ 15 | @Service 16 | public class Compent { 17 | @Resource 18 | private UserMapper userMapper; 19 | 20 | @Transactional(propagation = Propagation.REQUIRES_NEW) 21 | public void test(){ 22 | User user = new User(); 23 | user.setName("chen1"); 24 | user.setId(1L); 25 | userMapper.updateById(user); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lsb-crub-plus/src/main/java/com/example/lsbcrudplus/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudplus.service; 2 | 3 | import com.example.lsbcrudplus.entity.User; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import org.springframework.stereotype.Service; 6 | 7 | /** 8 | *

9 | * 服务类 10 | *

11 | * 12 | * @author jobob 13 | * @since 2019-12-09 14 | */ 15 | 16 | public interface IUserService extends IService { 17 | 18 | Boolean saveOne(); 19 | 20 | void test1(User user); 21 | } 22 | -------------------------------------------------------------------------------- /lsb-crub-plus/src/main/java/com/example/lsbcrudplus/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudplus.service.impl; 2 | 3 | import com.example.lsbcrudplus.entity.User; 4 | import com.example.lsbcrudplus.mapper.UserMapper; 5 | import com.example.lsbcrudplus.service.Compent; 6 | import com.example.lsbcrudplus.service.IUserService; 7 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 8 | import com.example.lsbcrudplus.util.LsbcrudplusException; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.transaction.annotation.Propagation; 13 | import org.springframework.transaction.annotation.Transactional; 14 | 15 | /** 16 | *

17 | * 服务实现类 18 | *

19 | * 20 | * @author jobob 21 | * @since 2019-12-09 22 | */ 23 | 24 | @Slf4j 25 | @Service 26 | public class UserServiceImpl extends ServiceImpl implements IUserService { 27 | 28 | @Autowired 29 | private Compent compent; 30 | 31 | @Override 32 | public Boolean saveOne() { 33 | User user = new User(); 34 | user.setName("chen"); 35 | // boolean save = super.save(user); 36 | Boolean save = Boolean.FALSE; 37 | if (save){ 38 | return Boolean.TRUE; 39 | }else { 40 | log.info("插入失败"); 41 | throw new LsbcrudplusException("插入失败"); 42 | } 43 | } 44 | 45 | @Transactional 46 | @Override 47 | public void test1(User user) { 48 | updateById(user); 49 | compent.test(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /lsb-crub-plus/src/main/java/com/example/lsbcrudplus/util/CustomIdGenerator.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudplus.util; 2 | 3 | import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.apache.ibatis.reflection.MetaObject; 6 | import org.apache.ibatis.reflection.SystemMetaObject; 7 | import org.springframework.stereotype.Component; 8 | 9 | import java.util.concurrent.atomic.AtomicLong; 10 | 11 | /** 12 | * ,mybatis自定义id生成器 13 | */ 14 | @Slf4j 15 | @Component 16 | public class CustomIdGenerator implements IdentifierGenerator { 17 | private final AtomicLong al = new AtomicLong(1); 18 | 19 | 20 | @Override 21 | public Number nextId(Object entity) { 22 | // 填充自己的Id生成器, 23 | return IdGenerator.generateId(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lsb-crub-plus/src/main/java/com/example/lsbcrudplus/util/GlobalException.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudplus.util; 2 | 3 | import com.example.lsbcrudplus.emum.ResultEnum; 4 | import com.example.lsbcrudplus.util.Result; 5 | import lombok.extern.java.Log; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.web.bind.annotation.ExceptionHandler; 8 | import org.springframework.web.bind.annotation.RestControllerAdvice; 9 | 10 | import java.lang.invoke.LambdaConversionException; 11 | 12 | /** 13 | * @Description: 全局的异常返回 14 | * @Author: boolean 15 | * @Date: 2019/12/10 0:14 16 | */ 17 | @Slf4j 18 | @RestControllerAdvice 19 | public class GlobalException { 20 | 21 | // 拦截器 22 | @ExceptionHandler({Exception.class}) 23 | public Result exception(Exception e){ 24 | Result result = new Result(); 25 | result.setCode(ResultEnum.ERROR.getCode()); 26 | result.setMsg(ResultEnum.ERROR.getMsg()); 27 | result.setDate(e.getMessage()); 28 | log.error("报错了",e); 29 | return result; 30 | } 31 | 32 | 33 | } 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /lsb-crub-plus/src/main/java/com/example/lsbcrudplus/util/LsbcrudplusException.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudplus.util; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | /** 7 | * @Description: 8 | * @Author: boolean 9 | * @Date: 2019/12/10 0:41 10 | */ 11 | 12 | public class LsbcrudplusException extends RuntimeException{ 13 | public LsbcrudplusException(String msg){ 14 | super(msg); 15 | } 16 | } 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /lsb-crub-plus/src/main/java/com/example/lsbcrudplus/util/MybatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudplus.util; 2 | 3 | import com.baomidou.mybatisplus.annotation.DbType; 4 | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; 5 | import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; 6 | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | @Configuration 11 | public class MybatisPlusConfig { 12 | /** 13 | * 分页插件 14 | * @return 15 | */ 16 | @Bean 17 | public MybatisPlusInterceptor mybatisPlusInterceptor() { 18 | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); 19 | interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); 20 | return interceptor; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lsb-crub-plus/src/main/java/com/example/lsbcrudplus/util/Result.java: -------------------------------------------------------------------------------- 1 | package com.example.lsbcrudplus.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-crub-plus/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | url: jdbc:mysql://127.0.0.1/test?serverTimezone=GMT%2B8 4 | username: root 5 | password: 123456 6 | logging: 7 | level: 8 | com.example.lsbcrudplus.mapper.UserMapper: debug # 改成你的mapper文件所在包路径 -------------------------------------------------------------------------------- /lsb-crub/clean.sh: -------------------------------------------------------------------------------- 1 | echo sss -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/CrudApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.crud; 2 | 3 | import com.example.crud.service.AsyncService; 4 | import com.example.crud.service.impl.TestService; 5 | import org.mybatis.spring.annotation.MapperScan; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.SpringApplication; 8 | import org.springframework.boot.autoconfigure.SpringBootApplication; 9 | import org.springframework.scheduling.annotation.EnableAsync; 10 | import org.springframework.transaction.annotation.EnableTransactionManagement; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | @SpringBootApplication 14 | @RestController 15 | @MapperScan("com.example.crud.mapper") 16 | @EnableAsync 17 | @EnableTransactionManagement 18 | 19 | public class CrudApplication { 20 | @Autowired 21 | private AsyncService asyncService; 22 | 23 | @Autowired 24 | private TestService testService; 25 | 26 | public static void main(String[] args) { 27 | SpringApplication.run(CrudApplication.class, args); 28 | } 29 | 30 | @RequestMapping("/lsb_crub") 31 | public String test(){ 32 | return "hello,crud"; 33 | } 34 | 35 | @PostMapping("/get/{id}") 36 | public String getId(@PathVariable(value = "id") String id){ 37 | return id; 38 | } 39 | 40 | 41 | @RequestMapping("/aad") 42 | public String test1(){ 43 | try { 44 | testService.test(); 45 | } catch (Exception e) { 46 | e.printStackTrace(); 47 | } 48 | return "success"; 49 | } 50 | 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/ServletInitializer.java: -------------------------------------------------------------------------------- 1 | package com.example.crud; 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(CrudApplication.class); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/controller/NameController.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.controller; 2 | 3 | 4 | import com.example.crud.entity.Name; 5 | import com.example.crud.service.INameService; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.dao.DuplicateKeyException; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | /** 14 | *

15 | * 前端控制器 16 | *

17 | * 18 | * @author jobob 19 | * @since 2020-10-12 20 | */ 21 | @RestController 22 | @RequestMapping("/name") 23 | @Slf4j 24 | public class NameController { 25 | @Autowired 26 | private INameService nameService; 27 | 28 | @RequestMapping("/test") 29 | public Name test(){ 30 | return nameService.getById(1); 31 | } 32 | 33 | 34 | @RequestMapping("/add") 35 | public String add(){ 36 | Name name = new Name(); 37 | name.setName("chen"); 38 | try { 39 | return nameService.save(name)?"1":"0"; 40 | }catch (DuplicateKeyException e){ 41 | log.error("重复了,报错:", e); 42 | return "重复了"; 43 | }catch (Exception e){ 44 | log.error("报错", e); 45 | return "报错"; 46 | } 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/controller/PeopleController.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | *

10 | * 前端控制器 11 | *

12 | * 13 | * @author jobob 14 | * @since 2025-05-19 15 | */ 16 | @RestController 17 | @RequestMapping("/people") 18 | public class PeopleController { 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/entity/Name.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.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-10-12 17 | */ 18 | @Data 19 | @EqualsAndHashCode(callSuper = false) 20 | @Accessors(chain = true) 21 | public class Name implements Serializable { 22 | 23 | private static final long serialVersionUID=1L; 24 | 25 | @TableId(value = "id", type = IdType.AUTO) 26 | private Integer id; 27 | 28 | private String name; 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/entity/People.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.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 2025-05-19 17 | */ 18 | @Data 19 | @EqualsAndHashCode(callSuper = false) 20 | @Accessors(chain = true) 21 | public class People implements Serializable { 22 | 23 | private static final long serialVersionUID=1L; 24 | 25 | @TableId(value = "id", type = IdType.AUTO) 26 | private Integer id; 27 | 28 | private String name; 29 | 30 | private String sex; 31 | 32 | private String adress; 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | import com.baomidou.mybatisplus.annotation.IdType; 6 | import com.baomidou.mybatisplus.annotation.TableId; 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | import lombok.experimental.Accessors; 10 | 11 | /** 12 | *

13 | * 14 | *

15 | * 16 | * @author jobob 17 | * @since 2019-12-06 18 | */ 19 | @Data 20 | @EqualsAndHashCode(callSuper = false) 21 | @Accessors(chain = true) 22 | 23 | public class User implements Serializable { 24 | 25 | private static final long serialVersionUID=1L; 26 | 27 | /** 28 | * 主键ID 29 | */ 30 | @TableId(value = "id", type = IdType.AUTO) 31 | private Long id; 32 | 33 | /** 34 | * 姓名 35 | */ 36 | private String name; 37 | 38 | /** 39 | * 年龄 40 | */ 41 | private Integer age; 42 | 43 | /** 44 | * 邮箱 45 | */ 46 | private String email; 47 | 48 | private String username; 49 | private String address; 50 | 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/mapper/NameMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.mapper; 2 | 3 | import com.example.crud.entity.Name; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author jobob 12 | * @since 2020-10-12 13 | */ 14 | public interface NameMapper extends BaseMapper { 15 | 16 | Name getById( Name name); 17 | } 18 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/mapper/NameMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/mapper/PeopleMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.mapper; 2 | 3 | import com.example.crud.entity.People; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author jobob 12 | * @since 2025-05-19 13 | */ 14 | public interface PeopleMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/mapper/PeopleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.mapper; 2 | 3 | import com.example.crud.entity.User; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.MapKey; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | /** 13 | *

14 | * Mapper 接口 15 | *

16 | * 17 | * @author jobob 18 | * @since 2019-12-06 19 | */ 20 | public interface UserMapper extends BaseMapper { 21 | @MapKey("id") 22 | Map testDoubleIf(Integer code); 23 | 24 | Map testDoubleIf1(Integer code, Integer code2); 25 | 26 | String testStringForLong(Long id); 27 | 28 | Integer asdas(@Param("id") Integer id); 29 | 30 | Integer batchInsert(List integers); 31 | } 32 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 27 | 28 | 31 | 32 | 33 | insert into async (async_id) values (#{id}) 34 | 35 | 36 | 37 | insert into async (async_id) 38 | VALUES 39 | 40 | (#{item}) 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/service/AsyncConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.service; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.core.task.AsyncTaskExecutor; 6 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 7 | 8 | /** 9 | * @Author buerbl 10 | * @create 2020/9/10 14:22 11 | */ 12 | @Configuration 13 | public class AsyncConfig { 14 | private static final int MAX_POOL_SIZE = 50; 15 | 16 | private static final int CORE_POOL_SIZE = 20; 17 | 18 | @Bean("asyncTaskExecutor") 19 | public AsyncTaskExecutor asyncTaskExecutor() { 20 | ThreadPoolTaskExecutor asyncTaskExecutor = new ThreadPoolTaskExecutor(); 21 | asyncTaskExecutor.setMaxPoolSize(MAX_POOL_SIZE); 22 | asyncTaskExecutor.setCorePoolSize(CORE_POOL_SIZE); 23 | asyncTaskExecutor.setThreadNamePrefix("task1-thread-"); 24 | asyncTaskExecutor.initialize(); 25 | return asyncTaskExecutor; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/service/AsyncService.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.service; 2 | 3 | import com.example.crud.mapper.UserMapper; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.dao.DuplicateKeyException; 7 | import org.springframework.scheduling.annotation.Async; 8 | import org.springframework.stereotype.Service; 9 | 10 | import javax.annotation.Resource; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | import java.util.Random; 14 | import java.util.stream.Collectors; 15 | import java.util.stream.Stream; 16 | 17 | /** 18 | * @Author buerbl 19 | * @create 2020/9/10 12:54 20 | */ 21 | @Slf4j 22 | @Service 23 | public class AsyncService { 24 | @Resource 25 | private UserMapper userMapper; 26 | @Async 27 | public void test() { 28 | int a = 1000000; //指定为100 29 | int times = 25000; 30 | ArrayList arrayList = new ArrayList<>(); 31 | for (int i = 0; i < times; i ++){ 32 | int num = new Random().nextInt(a); 33 | arrayList.add(num); 34 | } 35 | List integerList = arrayList.stream().distinct().collect(Collectors.toList()); 36 | log.info("去重的后大小[{}]", integerList.size()); 37 | // for (int i = 0; i < integerList.size(); i++){ 38 | // userMapper.asdas(integerList.get(i)); 39 | // } 40 | 41 | 42 | 43 | 44 | try { 45 | //切割插入,控制每次插入的数量 建议:100条/次 by JASON on 20190912 46 | int count = integerList.size(); 47 | for (int i = 0; i < count; i+= 100) { 48 | if (i+100 <= count){ 49 | userMapper.batchInsert(integerList.subList(i, i+100)); 50 | }else { 51 | userMapper.batchInsert(integerList.subList(i, count)); 52 | } 53 | } 54 | }catch (DuplicateKeyException e){ 55 | //备注:此处加异常机制是针对trade_seat_status的唯一约束的处理。 56 | log.error("trade_seat_status 插入动态座位图异常,座位图已经存在",e.getCause()); 57 | } 58 | 59 | 60 | } 61 | 62 | private synchronized void test1(){ 63 | int a = 1000000; //指定为100 64 | int times = 2000; 65 | ArrayList arrayList = new ArrayList<>(); 66 | for (int i = 0; i < 10; i ++){ 67 | int num = new Random().nextInt(a); 68 | arrayList.add(num); 69 | try { 70 | Thread.sleep(1000); 71 | } catch (InterruptedException e) { 72 | e.printStackTrace(); 73 | } 74 | } 75 | 76 | log.info("当前线程为[{}]", Thread.currentThread().getName()); 77 | // log.info("生成的随机数集合大小为[{}]",arrayList.size()); 78 | // List integerList = arrayList.stream().distinct().collect(Collectors.toList()); 79 | // log.info("去重后的随机数集合大小为[{}]", integerList.size()); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/service/CompentService.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.service; 2 | 3 | public interface CompentService { 4 | 5 | void test(String name); 6 | } 7 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/service/INameService.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.service; 2 | 3 | import com.example.crud.entity.Name; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import org.springframework.stereotype.Service; 6 | 7 | /** 8 | *

9 | * 服务类 10 | *

11 | * 12 | * @author jobob 13 | * @since 2020-10-12 14 | */ 15 | 16 | public interface INameService extends IService { 17 | 18 | Name getById(Name name); 19 | 20 | void localUpdate(Name name); 21 | 22 | void AddName(); 23 | 24 | void addPeople(); 25 | } 26 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/service/IPeopleService.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.service; 2 | 3 | import com.example.crud.entity.People; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author jobob 12 | * @since 2025-05-19 13 | */ 14 | public interface IPeopleService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.service; 2 | 3 | import com.example.crud.entity.User; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import org.springframework.lang.Nullable; 6 | 7 | /** 8 | *

9 | * 服务类 10 | *

11 | * 12 | * @author jobob 13 | * @since 2019-12-06 14 | */ 15 | public interface IUserService extends IService { 16 | void test(); 17 | 18 | void testDoubleIf(Integer code); 19 | 20 | @Nullable 21 | void testDoubleIf(Integer code, Integer code2); 22 | } 23 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/service/impl/Compant.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.service.impl; 2 | 3 | import com.example.crud.service.IUserService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Component; 6 | 7 | import java.util.HashMap; 8 | 9 | /** 10 | * @Author 布尔bl 11 | * @create 2020/11/19 0:07 12 | */ 13 | //@Component 14 | public class Compant { 15 | @Autowired 16 | private HashMap hashMap; 17 | 18 | public void get(){ 19 | hashMap.forEach((k, v)-> System.out.println(k)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/service/impl/CompentServiceImplOne.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.service.impl; 2 | 3 | import com.example.crud.service.CompentService; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component("CompentServiceImplOne") 7 | public class CompentServiceImplOne implements CompentService { 8 | @Override 9 | public void test(String name) { 10 | System.out.println("CompentServiceImplOne"+name); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/service/impl/CompentServiceImplThird.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.service.impl; 2 | 3 | import com.example.crud.service.CompentService; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component 7 | public class CompentServiceImplThird implements CompentService { 8 | @Override 9 | public void test(String name) { 10 | System.out.println("CompentServiceImplThird"+name); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/service/impl/CompentServiceImplTotal.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.service.impl; 2 | 3 | import com.example.crud.service.CompentService; 4 | import com.google.common.base.Preconditions; 5 | import org.apache.commons.lang3.StringUtils; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Component; 8 | 9 | import java.util.List; 10 | import java.util.Map; 11 | import java.util.concurrent.ConcurrentHashMap; 12 | 13 | @Component 14 | public class CompentServiceImplTotal { 15 | private final Map map = new ConcurrentHashMap<>(); 16 | 17 | @Autowired 18 | public CompentServiceImplTotal(Map compentServiceMap) { 19 | this.map.clear(); 20 | compentServiceMap.forEach(this.map::put); 21 | System.out.println(this.map); 22 | } 23 | 24 | public CompentService strategySelect(String mode) { 25 | Preconditions.checkArgument(!StringUtils.isEmpty(mode), "不允许输入空字符串"); 26 | return this.map.get(mode); 27 | } 28 | 29 | public static void main(String[] args) { 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/service/impl/CompentServiceImplTwo.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.service.impl; 2 | 3 | import com.example.crud.service.CompentService; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component 7 | public class CompentServiceImplTwo implements CompentService { 8 | @Override 9 | public void test(String name) { 10 | System.out.println("CompentServiceImplTWO"+name); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/service/impl/NameServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.service.impl; 2 | 3 | import com.example.crud.entity.Name; 4 | import com.example.crud.entity.People; 5 | import com.example.crud.mapper.NameMapper; 6 | import com.example.crud.mapper.PeopleMapper; 7 | import com.example.crud.service.INameService; 8 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | import javax.annotation.Resource; 14 | 15 | /** 16 | *

17 | * 服务实现类 18 | *

19 | * 20 | * @author jobob 21 | * @since 2020-10-12 22 | */ 23 | @Service 24 | public class NameServiceImpl extends ServiceImpl implements INameService { 25 | 26 | @Resource 27 | private NameMapper nameMapper; 28 | 29 | @Autowired 30 | private TestService testService; 31 | 32 | @Autowired 33 | private PeopleMapper peopleMapper; 34 | 35 | @Autowired 36 | private INameService nameService; 37 | 38 | @Override 39 | public Name getById(Name name) { 40 | return nameMapper.getById(name); 41 | } 42 | 43 | @Transactional(rollbackFor = Exception.class) 44 | @Override 45 | public void localUpdate(Name name) { 46 | updateById(name); 47 | testService.test1(name); 48 | } 49 | 50 | @Override 51 | public void AddName() { 52 | // nameService.addPeople(); 53 | addPeople(); 54 | } 55 | 56 | @Transactional(rollbackFor = Exception.class) 57 | public void addPeople() { 58 | People people = new People(); 59 | people.setName("赵六"); 60 | people.setAdress("北京"); 61 | people.setSex("男"); 62 | peopleMapper.insert(people); 63 | int i = 1 / 0; 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/service/impl/TestService.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.service.impl; 2 | 3 | import com.example.crud.entity.Name; 4 | import com.example.crud.mapper.NameMapper; 5 | import com.example.crud.service.AsyncService; 6 | import com.example.crud.service.INameService; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.transaction.annotation.Transactional; 11 | import org.springframework.util.StopWatch; 12 | 13 | import javax.annotation.Resource; 14 | 15 | /** 16 | * @Author buerbl 17 | * @create 2020/9/10 13:52 18 | */ 19 | @Slf4j 20 | @Service 21 | public class TestService { 22 | @Autowired 23 | private AsyncService asyncService; 24 | 25 | @Autowired 26 | private INameService nameService; 27 | 28 | @Resource 29 | private NameMapper nameMapper; 30 | 31 | 32 | public void test(){ 33 | log.info("开始"); 34 | StopWatch stopWatch = new StopWatch(); 35 | stopWatch.start(); 36 | asyncService.test(); 37 | stopWatch.stop(); 38 | log.info("时间为[{}]", stopWatch.getTotalTimeMillis()); 39 | log.info("结束"); 40 | } 41 | 42 | // @Transactional(rollbackFor = Exception.class) 43 | public void test1(Name name){ 44 | nameMapper.updateById(name); 45 | log.info("1111"); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/service/impl/UserJDBCServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.service.impl; 2 | 3 | import com.example.crud.entity.User; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.jdbc.core.JdbcTemplate; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.transaction.annotation.Transactional; 8 | 9 | import java.util.List; 10 | 11 | @Service 12 | public class UserJDBCServiceImpl { 13 | @Autowired 14 | private JdbcTemplate jdbcTemplate; 15 | 16 | @Autowired 17 | private UserJDBCServiceImplA userJDBCServiceImplA; 18 | 19 | @Autowired 20 | private UserJDBCServiceImplB userJDBCServiceImplB; 21 | 22 | @Transactional(rollbackFor=Exception.class) 23 | public int addUser() { 24 | User user = new User(); 25 | user.setAddress("chen"); 26 | user.setUsername("chen"); 27 | jdbcTemplate.update("insert into user (username,address) values (?,?);", user.getUsername(), user.getAddress()); 28 | return userJDBCServiceImplA.addUser(); 29 | } 30 | 31 | public String getUser(){ 32 | return jdbcTemplate.queryForObject("SELECT username FROM user WHERE id = 1", String.class); 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/service/impl/UserJDBCServiceImplA.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.service.impl; 2 | 3 | import com.example.crud.entity.User; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.jdbc.core.JdbcTemplate; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.transaction.annotation.Transactional; 8 | 9 | @Service 10 | public class UserJDBCServiceImplA { 11 | @Autowired 12 | private JdbcTemplate jdbcTemplate; 13 | @Autowired 14 | private UserJDBCServiceImplB userJDBCServiceImplB; 15 | 16 | @Transactional(rollbackFor=Exception.class) 17 | public int addUser() { 18 | User user = new User(); 19 | user.setAddress("A"); 20 | user.setUsername("AA"); 21 | 22 | jdbcTemplate.update("insert into user (username,address) values (?,?);", user.getUsername(), user.getAddress()); 23 | 24 | try{ 25 | return userJDBCServiceImplB.addUser(); 26 | }catch (Exception e){ 27 | 28 | } 29 | return 0; 30 | } 31 | 32 | public String getUser(){ 33 | return jdbcTemplate.queryForObject("SELECT username FROM user WHERE id = 1", String.class); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/service/impl/UserJDBCServiceImplB.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.service.impl; 2 | 3 | import com.example.crud.entity.User; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.jdbc.core.JdbcTemplate; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.transaction.annotation.Propagation; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | @Service 11 | public class UserJDBCServiceImplB { 12 | @Autowired 13 | private JdbcTemplate jdbcTemplate; 14 | 15 | @Transactional(rollbackFor=Exception.class,propagation = Propagation.REQUIRES_NEW) 16 | public int addUser() { 17 | User user = new User(); 18 | user.setUsername("BB"); 19 | user.setAddress("B"); 20 | int a= 0; 21 | System.out.println(2 / a); 22 | return jdbcTemplate.update("insert into user (username,address) values (?,?);", user.getUsername(), user.getAddress()); 23 | } 24 | 25 | public String getUser(){ 26 | return jdbcTemplate.queryForObject("SELECT username FROM user WHERE id = 1", String.class); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lsb-crub/src/main/java/com/example/crud/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.crud.service.impl; 2 | 3 | import com.example.crud.entity.User; 4 | import com.example.crud.mapper.UserMapper; 5 | import com.example.crud.service.IUserService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Repository; 10 | import org.springframework.stereotype.Service; 11 | 12 | import javax.annotation.Resource; 13 | 14 | /** 15 | *

16 | * 服务实现类 17 | *

18 | * 19 | * @author jobob 20 | * @since 2019-12-06 21 | */ 22 | @Service 23 | @Slf4j 24 | public class UserServiceImpl extends ServiceImpl 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 |
11 | 12 | 姓名:
13 | 年龄:
14 | 邮箱:
15 | 16 | 17 | 18 | 19 |
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 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
id姓名年龄邮箱编辑删除
编辑删除
28 |
29 |
30 | [首 页] 31 | [上一页] 32 | [下一页] 33 |
34 |
35 |
36 | 姓名:
37 | 年龄:
38 | 邮箱:
39 | 40 | 41 |
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 | ![](http://javahouse.xyz/20200106104817.png) 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 | ![](http://javahouse.xyz/20200106104817.png) 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 | ![](https://bu.dusays.com/2022/03/27/47925f49cf46e.png) -------------------------------------------------------------------------------- /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 | ![](http://javahouse.xyz/20200320123233.png) 3 | 4 | ## 配置2 5 | ![](http://javahouse.xyz/20200320123305.png) 6 | 7 | ## 配置3 8 | ![](http://javahouse.xyz/20200320123320.png) -------------------------------------------------------------------------------- /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 | ![](http://javahouse.xyz/20200124125212.png) 4 | 5 | ## 注销 6 | 7 | ![](http://javahouse.xyz/20200124125153.png) 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 | ![](http://javahouse.xyz/shiro.gif) 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 |
9 |

10 |

11 |

12 | 13 | 增加用户
14 | 更新用户
15 | 退出登陆 16 |
17 | 18 | -------------------------------------------------------------------------------- /lsb-shiro/src/main/resources/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 登录 6 | 7 | 8 |
9 |

10 |
11 | 用户名:
12 | 密码:
13 | 14 |
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 | ![](http://javahouse.xyz/20200122173059.png) -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------