├── jdk12-demo └── src │ ├── file1.txt │ ├── file2.txt │ ├── SnowFlakeShortUrl.java │ └── TestJDK12.java ├── easy-excel-demo ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── excel │ │ │ │ └── users.xlsx │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── easyexcel │ │ │ └── demo │ │ │ ├── service │ │ │ ├── IUser.java │ │ │ └── impl │ │ │ │ └── UserServiceImpl.java │ │ │ ├── DemoApplication.java │ │ │ ├── entity │ │ │ └── User.java │ │ │ ├── converter │ │ │ └── GenderConverter.java │ │ │ ├── listener │ │ │ └── UserExcelListener.java │ │ │ ├── utils │ │ │ └── ExcelDemoUtils.java │ │ │ └── controller │ │ │ └── UserController.java │ └── test │ │ ├── resources │ │ ├── .DS_Store │ │ └── excel │ │ │ ├── users1.xlsx │ │ │ └── ~$users1.xlsx │ │ └── java │ │ └── com │ │ └── example │ │ └── easyexcel │ │ └── demo │ │ ├── TestUtils.java │ │ └── DemoApplicationTests.java ├── .gitignore ├── pom.xml ├── mvnw.cmd └── mvnw ├── springboot-application-startup ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── top │ │ │ └── dayarch │ │ │ └── startup │ │ │ ├── service │ │ │ └── StartupService.java │ │ │ ├── SpringbootApplicationStartupApplication.java │ │ │ └── activity │ │ │ ├── MyInitializingBean.java │ │ │ ├── MyPostConstructBean.java │ │ │ ├── MySecondApplicationRunner.java │ │ │ ├── MyCommandLineRunner.java │ │ │ ├── MySecondCommandLineRunner.java │ │ │ ├── MyApplicationRunner.java │ │ │ └── MyApplicationListener.java │ └── test │ │ └── java │ │ └── top │ │ └── dayarch │ │ └── startup │ │ └── SpringbootApplicationStartupApplicationTests.java ├── .gitignore ├── pom.xml └── mvnw.cmd ├── dozer-demo ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.yml │ │ │ └── dozerBeanMapping.xml │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── dozer │ │ │ └── demo │ │ │ ├── DemoApplication.java │ │ │ ├── vo │ │ │ ├── AddressVo.java │ │ │ ├── ScoreEnum.java │ │ │ ├── CourseVo.java │ │ │ └── StudentVo.java │ │ │ ├── domain │ │ │ ├── AddressDomain.java │ │ │ ├── CourseDomain.java │ │ │ └── StudentDomain.java │ │ │ ├── converter │ │ │ └── ScoreConverter.java │ │ │ ├── listener │ │ │ └── StudentListener.java │ │ │ └── config │ │ │ └── DozerConfig.java │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── dozer │ │ └── demo │ │ └── DemoApplicationTests.java ├── .gitignore └── pom.xml ├── spring-boot-unified-return ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── unifiedreturn │ │ │ ├── vo │ │ │ ├── Modes.java │ │ │ ├── LoginUserVo.java │ │ │ ├── UserVo.java │ │ │ └── CommonResult.java │ │ │ ├── service │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ │ └── UserServiceImpl.java │ │ │ ├── exception │ │ │ ├── BusinessException.java │ │ │ └── TestBean.java │ │ │ ├── annotation │ │ │ └── LoginUser.java │ │ │ ├── converter │ │ │ ├── StringToEnumConverter.java │ │ │ ├── StringToLocalDateTimeConverter.java │ │ │ └── LoginUserArgumentResolver.java │ │ │ ├── UnifiedreturnApplication.java │ │ │ ├── api │ │ │ ├── BindingController.java │ │ │ └── UserController.java │ │ │ └── config │ │ │ └── UnifiedReturnConfig.java │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── unifiedreturn │ │ └── UnifiedreturnApplicationTests.java ├── .gitignore ├── pom.xml ├── mvnw.cmd └── mvnw ├── custom-starter ├── rgyb-spring-boot-starter │ ├── src │ │ └── main │ │ │ └── resources │ │ │ └── META-INF │ │ │ └── spring.providers │ └── pom.xml ├── rgyb-spring-boot-sample │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yml │ │ │ └── java │ │ │ │ └── top │ │ │ │ └── dayarch │ │ │ │ └── learnings │ │ │ │ └── rgybspringbootsample │ │ │ │ └── RgybSpringBootSampleApplication.java │ │ └── test │ │ │ └── java │ │ │ └── top │ │ │ └── dayarch │ │ │ └── learnings │ │ │ └── rgybspringbootsample │ │ │ ├── LambdaTest.java │ │ │ └── RgybSpringBootSampleApplicationTests.java │ ├── .gitignore │ ├── pom.xml │ └── mvnw.cmd ├── rgyb-spring-boot-autoconfigure │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── spring.factories │ │ │ └── java │ │ │ └── top │ │ │ └── dayarch │ │ │ ├── service │ │ │ ├── DummyEmail.java │ │ │ └── GreetingService.java │ │ │ └── autoconfigure │ │ │ ├── GreetingProperties.java │ │ │ └── GreetingAutoConfiguration.java │ └── pom.xml └── pom.xml ├── concurrency ├── src │ ├── main │ │ └── java │ │ │ └── top │ │ │ └── dayarch │ │ │ ├── App.java │ │ │ ├── topic07 │ │ │ ├── CreditRating.java │ │ │ ├── User.java │ │ │ ├── Product.java │ │ │ ├── CompletableFutureCombine.java │ │ │ ├── CompletableFutureException.java │ │ │ ├── CompletableFutureCompose.java │ │ │ ├── CompletableFuture1.java │ │ │ └── CompletableFutureCallback.java │ │ │ ├── topic06 │ │ │ ├── RunnalbleVsCallable.java │ │ │ ├── FutureAndCallableExample.java │ │ │ ├── MakeTeaExample.java │ │ │ ├── FutureCancelExample.java │ │ │ └── MakeTeaExample1.java │ │ │ ├── topic01 │ │ │ ├── OrderIssue.java │ │ │ └── VisibilityIssue.java │ │ │ ├── topic05 │ │ │ ├── JoinExample.java │ │ │ ├── CountDownLatchExample.java │ │ │ ├── CountDownLatchTimeoutExample.java │ │ │ └── CyclicBarrierExample.java │ │ │ ├── topic02 │ │ │ ├── SimpleBlockingQueue.java │ │ │ └── NotifyTest.java │ │ │ ├── topic08 │ │ │ └── ForkJoinDemo.java │ │ │ ├── topic04 │ │ │ └── ReentrantReadWriteLockCache.java │ │ │ ├── myjuc │ │ │ └── MyMutex.java │ │ │ ├── topic03 │ │ │ └── ThreadStateTest.java │ │ │ └── memoryleak │ │ │ └── MemLeakTest.java │ └── test │ │ └── java │ │ └── top │ │ └── dayarch │ │ ├── AppTest.java │ │ ├── ThreadNotSafeInteger.java │ │ └── StaticTest.java └── pom.xml ├── spring-bean-life-cycle ├── SpringDemo.java ├── MyBeanPostProcessor.java ├── spring-config.xml └── Book.java ├── configurationproperties ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── configurationproperties │ │ │ ├── converter │ │ │ └── WeightConverter.java │ │ │ ├── ConfigurationpropertiesApplication.java │ │ │ ├── configuration │ │ │ └── PropertiesConfig.java │ │ │ ├── entity │ │ │ └── Weight.java │ │ │ └── properties │ │ │ └── MailModuleProperties.java │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── configurationproperties │ │ └── ConfigurationpropertiesApplicationTests.java ├── .gitignore └── pom.xml ├── mybatis-interceptor └── interceptor │ ├── annotation │ ├── EncryptDecryptClass.java │ └── EncryptDecryptField.java │ ├── EncryptDecryptImpl.java │ ├── IEncryptDecrypt.java │ ├── ResultInterceptor.java │ ├── ParamInterceptor.java │ └── EncryptDecryptUtils.java ├── learnings mind map.mmd ├── lombok-demo ├── src │ └── main │ │ └── java │ │ ├── Employee.java │ │ ├── Student.java │ │ └── Test.java └── pom.xml ├── .gitignore └── xss-demo ├── GlobalSecurityFilter.java └── validation.properties /jdk12-demo/src/file1.txt: -------------------------------------------------------------------------------- 1 | 大家好,我是日拱一兵,叫我拱哥就好 -------------------------------------------------------------------------------- /jdk12-demo/src/file2.txt: -------------------------------------------------------------------------------- 1 | 大家好,我是日拱一兵,叫我兵兵就好 -------------------------------------------------------------------------------- /easy-excel-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /springboot-application-startup/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /dozer-demo/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | #dozer: 2 | # mapping-files: classpath:/*mapping.xml 3 | -------------------------------------------------------------------------------- /spring-boot-unified-return/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.servlet.context-path=/rgyb 2 | -------------------------------------------------------------------------------- /custom-starter/rgyb-spring-boot-starter/src/main/resources/META-INF/spring.providers: -------------------------------------------------------------------------------- 1 | providers: rgyb-spring-boot-autoconfigure -------------------------------------------------------------------------------- /easy-excel-demo/src/test/resources/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FraserYu/learnings/HEAD/easy-excel-demo/src/test/resources/.DS_Store -------------------------------------------------------------------------------- /easy-excel-demo/src/main/resources/excel/users.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FraserYu/learnings/HEAD/easy-excel-demo/src/main/resources/excel/users.xlsx -------------------------------------------------------------------------------- /easy-excel-demo/src/test/resources/excel/users1.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FraserYu/learnings/HEAD/easy-excel-demo/src/test/resources/excel/users1.xlsx -------------------------------------------------------------------------------- /custom-starter/rgyb-spring-boot-sample/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | rgyb: 2 | greeting: 3 | enable: true 4 | members: 5 | - 李雷 6 | - 韩梅梅 -------------------------------------------------------------------------------- /custom-starter/rgyb-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | top.dayarch.autoconfigure.GreetingAutoConfiguration 3 | -------------------------------------------------------------------------------- /easy-excel-demo/src/test/resources/excel/~$users1.xlsx: -------------------------------------------------------------------------------- 1 | Microsoft Office User Microsoft Office User -------------------------------------------------------------------------------- /spring-boot-unified-return/src/main/java/com/example/unifiedreturn/vo/Modes.java: -------------------------------------------------------------------------------- 1 | package com.example.unifiedreturn.vo; 2 | 3 | /** 4 | * 模式枚举 5 | * 6 | * @author fraser 7 | * @date 2019/12/12 1:51 PM 8 | */ 9 | public enum Modes { 10 | ALPHA, BETA; 11 | } 12 | -------------------------------------------------------------------------------- /custom-starter/rgyb-spring-boot-autoconfigure/src/main/java/top/dayarch/service/DummyEmail.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.service; 2 | 3 | /** 4 | * Dummy 类,为了条件注解使用 5 | * 6 | * @author fraser 7 | * @date 2019/10/15 5:00 PM 8 | */ 9 | public class DummyEmail { 10 | } 11 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/App.java: -------------------------------------------------------------------------------- 1 | package top.dayarch; 2 | 3 | /** 4 | * Hello world! 5 | * 6 | */ 7 | public class App 8 | { 9 | public static void main( String[] args ) 10 | { 11 | System.out.println( "Hello World!" ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic07/CreditRating.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic07; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | 6 | /** 7 | * 信用评级 8 | * 9 | * @author fraser 10 | * @date 2020/7/19 8:00 PM 11 | */ 12 | @Builder 13 | @Data 14 | public class CreditRating { 15 | 16 | private Double rating; 17 | } 18 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic07/User.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic07; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | 6 | /** 7 | * 用户 8 | * 9 | * @author fraser 10 | * @date 2020/7/19 7:58 PM 11 | */ 12 | @Builder 13 | @Data 14 | public class User { 15 | 16 | private Long id; 17 | private String name; 18 | } 19 | -------------------------------------------------------------------------------- /easy-excel-demo/src/test/java/com/example/easyexcel/demo/TestUtils.java: -------------------------------------------------------------------------------- 1 | package com.example.easyexcel.demo; 2 | 3 | /** 4 | * 测试工具类 5 | * 6 | * @author fraser 7 | * @date 2019/10/6 9:46 AM 8 | */ 9 | public class TestUtils { 10 | 11 | public static String getPath() { 12 | return TestUtils.class.getResource("/").getPath(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic07/Product.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic07; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | 6 | /** 7 | * 模拟商品 8 | * 9 | * @author fraser 10 | * @date 2020/7/19 7:27 PM 11 | */ 12 | @Builder 13 | @Data 14 | public class Product { 15 | 16 | private Long id; 17 | private String name; 18 | } 19 | -------------------------------------------------------------------------------- /spring-bean-life-cycle/SpringDemo.java: -------------------------------------------------------------------------------- 1 | public class SpringDemo { 2 | public static void main(String[] args) { 3 | AbstractApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml"); 4 | Book book = (Book) context.getBean("book"); 5 | System.out.println("Book Name:" + book.getBookName()); 6 | context.registerShutdownHook(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /spring-boot-unified-return/src/main/java/com/example/unifiedreturn/vo/LoginUserVo.java: -------------------------------------------------------------------------------- 1 | package com.example.unifiedreturn.vo; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 登陆用户信息 7 | * 8 | * @author fraser 9 | * @date 2019/12/12 2:22 PM 10 | */ 11 | @Data 12 | public class LoginUserVo { 13 | 14 | private Long id; 15 | 16 | private String name; 17 | } 18 | -------------------------------------------------------------------------------- /easy-excel-demo/src/main/java/com/example/easyexcel/demo/service/IUser.java: -------------------------------------------------------------------------------- 1 | package com.example.easyexcel.demo.service; 2 | 3 | import com.example.easyexcel.demo.entity.User; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * 用户人员接口 9 | * 10 | * @author fraser 11 | * @date 2019/10/7 2:01 PM 12 | */ 13 | public interface IUser { 14 | 15 | public boolean saveData(List users); 16 | } 17 | -------------------------------------------------------------------------------- /springboot-application-startup/src/test/java/top/dayarch/startup/SpringbootApplicationStartupApplicationTests.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.startup; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SpringbootApplicationStartupApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /configurationproperties/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | myapp.mail.enabled=true 2 | #myapp.mail.default-subject=This is a Test 3 | myapp. 4 | myapp.mail.unknown-property=foo 5 | myapp.mail.smtpServers[0]=server1 6 | myapp.mail.smtpServers[1]=server2 7 | myapp.mail.pause-between-mails=5s 8 | myapp.mail.max-attachment-size=2MB 9 | myapp.mail.max-attachment-weight=5kg 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /mybatis-interceptor/interceptor/annotation/EncryptDecryptClass.java: -------------------------------------------------------------------------------- 1 | package com.demo.interceptor.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 需要加解密的类注解 7 | * 8 | * @author fraser 9 | * @date 2019-05-15 11:11 10 | */ 11 | @Documented 12 | @Inherited 13 | @Target({ElementType.TYPE}) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface EncryptDecryptClass { 16 | } 17 | -------------------------------------------------------------------------------- /mybatis-interceptor/interceptor/annotation/EncryptDecryptField.java: -------------------------------------------------------------------------------- 1 | package com.demo.interceptor.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 加密字典注解 7 | * 8 | * @author fraser 9 | * @date 2019-05-15 11:08 10 | */ 11 | @Documented 12 | @Inherited 13 | @Target({ElementType.FIELD}) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface EncryptDecryptField { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /concurrency/src/test/java/top/dayarch/AppTest.java: -------------------------------------------------------------------------------- 1 | package top.dayarch; 2 | 3 | import static org.junit.Assert.assertTrue; 4 | 5 | import org.junit.Test; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | { 12 | /** 13 | * Rigorous Test :-) 14 | */ 15 | @Test 16 | public void shouldAnswerWithTrue() 17 | { 18 | assertTrue( true ); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-unified-return/src/main/java/com/example/unifiedreturn/vo/UserVo.java: -------------------------------------------------------------------------------- 1 | package com.example.unifiedreturn.vo; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | 6 | /** 7 | * 用户vo 8 | * 9 | * @author fraser 10 | * @date 2019-08-08 17:14 11 | */ 12 | @Data 13 | @Builder 14 | public class UserVo { 15 | 16 | private Long id; 17 | 18 | private String name; 19 | 20 | private Integer age; 21 | } 22 | -------------------------------------------------------------------------------- /dozer-demo/src/main/java/com/example/dozer/demo/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.dozer.demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class DemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(DemoApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /easy-excel-demo/src/main/java/com/example/easyexcel/demo/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.easyexcel.demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class DemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(DemoApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /learnings mind map.mmd: -------------------------------------------------------------------------------- 1 | Mind Map generated by NB MindMap plugin 2 | > __version__=`1.1` 3 | --- 4 | 5 | # Learnings 6 | > mmd.emoticon=`books` 7 | 8 | 9 | ## 并发 10 | > mmd.emoticon=`ruby` 11 | 12 | 13 | ### 并发三大概念 14 | > mmd.emoticon=`anchor` 15 | 16 | 17 | ### 并发三大问题 18 | > mmd.emoticon=`skull_old` 19 | 20 | 21 | ### Happens\-before 22 | > mmd.emoticon=`asterisk` 23 | 24 | 25 | ### Java 内存模型 26 | > mmd.emoticon=`compass` 27 | 28 | -------------------------------------------------------------------------------- /springboot-application-startup/src/main/java/top/dayarch/startup/service/StartupService.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.startup.service; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.stereotype.Service; 5 | 6 | /** 7 | * @author fraser 8 | * @date 2019/12/19 9:19 PM 9 | */ 10 | @Service 11 | @Slf4j 12 | public class StartupService { 13 | 14 | public void printLog(){ 15 | log.info("StartupService"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic06/RunnalbleVsCallable.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic06; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | /** 6 | * Runnable 与 Callable 的对比 7 | * 8 | * @author fraser 9 | * @date 2020/7/4 6:16 PM 10 | */ 11 | @Slf4j 12 | public class RunnalbleVsCallable { 13 | 14 | class MyThread implements Runnable{ 15 | @Override 16 | public void run() { 17 | log.info("my thread"); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /dozer-demo/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | /target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | .sts4-cache 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.iml 18 | *.ipr 19 | 20 | ### NetBeans ### 21 | /nbproject/private/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ 26 | /build/ 27 | 28 | ### VS Code ### 29 | .vscode/ 30 | -------------------------------------------------------------------------------- /spring-boot-unified-return/src/main/java/com/example/unifiedreturn/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.example.unifiedreturn.service; 2 | 3 | import com.example.unifiedreturn.vo.UserVo; 4 | 5 | /** 6 | * 用户服务 7 | * 8 | * @author fraser 9 | * @date 2019-08-09 11:22 10 | */ 11 | public interface UserService { 12 | 13 | /** 14 | * 根据用户ID查询用户 15 | * 16 | * @param id 17 | * @return 18 | */ 19 | public UserVo getUserById(Long id); 20 | } 21 | -------------------------------------------------------------------------------- /concurrency/src/test/java/top/dayarch/ThreadNotSafeInteger.java: -------------------------------------------------------------------------------- 1 | package top.dayarch; 2 | 3 | /** 4 | * 线程不安全的操作 5 | * 6 | * @author fraser 7 | * @date 2020/3/2 2:06 PM 8 | */ 9 | public class ThreadNotSafeInteger { 10 | /** 11 | * 共享变量 value 12 | */ 13 | private int value; 14 | 15 | public synchronized int getValue() { 16 | return value; 17 | } 18 | 19 | public synchronized void setValue(int value) { 20 | this.value = value; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lombok-demo/src/main/java/Employee.java: -------------------------------------------------------------------------------- 1 | import lombok.NonNull; 2 | import lombok.RequiredArgsConstructor; 3 | import lombok.Singular; 4 | 5 | /** 6 | * 员工,用于说明lombok 7 | * 8 | * @author fraser 9 | * @date 2019/11/24 8:56 PM 10 | */ 11 | 12 | @RequiredArgsConstructor 13 | public class Employee { 14 | 15 | final private Long id; 16 | 17 | @NonNull private String name; 18 | 19 | private static Integer age; 20 | 21 | private String password; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /spring-boot-unified-return/src/main/java/com/example/unifiedreturn/exception/BusinessException.java: -------------------------------------------------------------------------------- 1 | package com.example.unifiedreturn.exception; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | /** 7 | * 业务异常 8 | * 9 | * @author fraser 10 | * @date 2019-08-09 11:10 11 | */ 12 | @Data 13 | @AllArgsConstructor 14 | public final class BusinessException extends RuntimeException { 15 | 16 | private String errorCode; 17 | 18 | private String errorMsg; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /easy-excel-demo/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /spring-boot-unified-return/src/main/java/com/example/unifiedreturn/exception/TestBean.java: -------------------------------------------------------------------------------- 1 | package com.example.unifiedreturn.exception; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.beans.factory.InitializingBean; 5 | 6 | /** 7 | * @author fraser 8 | * @date 2019-08-09 11:50 9 | */ 10 | @Slf4j 11 | public class TestBean implements InitializingBean { 12 | @Override 13 | public void afterPropertiesSet() throws Exception { 14 | log.info("TestBean"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /configurationproperties/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /spring-boot-unified-return/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /spring-boot-unified-return/src/test/java/com/example/unifiedreturn/UnifiedreturnApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.unifiedreturn; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class UnifiedreturnApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-application-startup/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /springboot-application-startup/src/main/java/top/dayarch/startup/SpringbootApplicationStartupApplication.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.startup; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootApplicationStartupApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootApplicationStartupApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /custom-starter/rgyb-spring-boot-sample/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /spring-boot-unified-return/src/main/java/com/example/unifiedreturn/annotation/LoginUser.java: -------------------------------------------------------------------------------- 1 | package com.example.unifiedreturn.annotation; 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 | * 登陆用户注解 10 | * 11 | * @author fraser 12 | * @date 2019/12/12 2:16 PM 13 | */ 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Target(ElementType.PARAMETER) 16 | public @interface LoginUser { 17 | } 18 | -------------------------------------------------------------------------------- /dozer-demo/src/main/java/com/example/dozer/demo/vo/AddressVo.java: -------------------------------------------------------------------------------- 1 | package com.example.dozer.demo.vo; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 地址vo 7 | * 8 | * @author fraser 9 | * @date 2019-05-28 10:25 10 | */ 11 | @Data 12 | public class AddressVo { 13 | 14 | /** 15 | * 省 16 | */ 17 | private String province; 18 | 19 | /** 20 | * 市 21 | */ 22 | private String city; 23 | 24 | /** 25 | * 区 26 | */ 27 | private String district; 28 | 29 | /** 30 | * 详细 31 | */ 32 | private String detailAddr; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /dozer-demo/src/main/java/com/example/dozer/demo/vo/ScoreEnum.java: -------------------------------------------------------------------------------- 1 | package com.example.dozer.demo.vo; 2 | 3 | /** 4 | * 分数枚举 5 | * 6 | * @author fraser 7 | * @date 2019-05-30 10:12 8 | */ 9 | public enum ScoreEnum { 10 | 11 | /** 12 | * 优秀 13 | */ 14 | A("优秀"), 15 | 16 | /** 17 | * 良 18 | */ 19 | B("良"), 20 | 21 | /** 22 | * 及格 23 | */ 24 | C("及格"), 25 | 26 | /** 27 | * 不及格 28 | */ 29 | D("不及格"); 30 | 31 | private final String name; 32 | 33 | ScoreEnum(String name) { 34 | this.name = name; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic01/OrderIssue.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic01; 2 | 3 | /** 4 | * 并发编程有序性问题验证 5 | * 6 | * @author fraser 7 | * @date 2020/2/27 8:04 PM 8 | */ 9 | public class OrderIssue { 10 | private static OrderIssue instance; 11 | 12 | public static OrderIssue getInstance(){ 13 | if (instance == null){ 14 | synchronized (OrderIssue.class){ 15 | if (instance == null){ 16 | instance = new OrderIssue(); 17 | } 18 | } 19 | } 20 | return instance; 21 | } 22 | 23 | //TODO 单例模式的其他几种模式 24 | } 25 | -------------------------------------------------------------------------------- /dozer-demo/src/main/java/com/example/dozer/demo/domain/AddressDomain.java: -------------------------------------------------------------------------------- 1 | package com.example.dozer.demo.domain; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 地址domain 7 | * 8 | * @author fraser 9 | * @date 2019-05-28 10:24 10 | */ 11 | @Data 12 | public class AddressDomain { 13 | 14 | /** 15 | * 省 16 | */ 17 | private String province; 18 | 19 | /** 20 | * 市 21 | */ 22 | private String city; 23 | 24 | /** 25 | * 区 26 | */ 27 | private String district; 28 | 29 | /** 30 | * 详细 31 | */ 32 | private String detail; 33 | } 34 | -------------------------------------------------------------------------------- /configurationproperties/src/main/java/com/example/configurationproperties/converter/WeightConverter.java: -------------------------------------------------------------------------------- 1 | package com.example.configurationproperties.converter; 2 | 3 | import com.example.configurationproperties.entity.Weight; 4 | import org.springframework.core.convert.converter.Converter; 5 | 6 | /** 7 | * @author fraser 8 | * @date 2019-07-24 15:07 9 | */ 10 | public class WeightConverter implements Converter { 11 | 12 | @Override 13 | public Weight convert(String source) { 14 | return Weight.fromString(source); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /spring-boot-unified-return/src/main/java/com/example/unifiedreturn/converter/StringToEnumConverter.java: -------------------------------------------------------------------------------- 1 | package com.example.unifiedreturn.converter; 2 | 3 | import com.example.unifiedreturn.vo.Modes; 4 | import org.springframework.core.convert.converter.Converter; 5 | 6 | /** 7 | * String 2 Enum 转换器 8 | * 9 | * @author fraser 10 | * @date 2019/12/12 1:50 PM 11 | */ 12 | public class StringToEnumConverter implements Converter { 13 | 14 | @Override 15 | public Modes convert(String s) { 16 | return Modes.valueOf(s); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /dozer-demo/src/main/java/com/example/dozer/demo/vo/CourseVo.java: -------------------------------------------------------------------------------- 1 | package com.example.dozer.demo.vo; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 课程 7 | * 8 | * @author fraser 9 | * @date 2019-05-28 21:16 10 | */ 11 | 12 | @Data 13 | public class CourseVo { 14 | 15 | /** 16 | * 课程编码 17 | */ 18 | private String courseCode; 19 | 20 | /** 21 | * 课程Id 22 | */ 23 | private String courseId; 24 | 25 | /** 26 | * 课程名称 27 | */ 28 | private String courseName; 29 | 30 | /** 31 | * 老师名称 32 | */ 33 | private String teacherName; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /custom-starter/rgyb-spring-boot-autoconfigure/src/main/java/top/dayarch/service/GreetingService.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.service; 2 | 3 | import lombok.AllArgsConstructor; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /** 9 | * 问候service 10 | * 11 | * @author fraser 12 | * @date 2019/10/15 4:58 PM 13 | */ 14 | @AllArgsConstructor 15 | public class GreetingService { 16 | 17 | private List members = new ArrayList(); 18 | 19 | public void sayHello(){ 20 | members.forEach(s -> System.out.println("hello " + s)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /dozer-demo/src/main/java/com/example/dozer/demo/domain/CourseDomain.java: -------------------------------------------------------------------------------- 1 | package com.example.dozer.demo.domain; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 课程 7 | * 8 | * @author fraser 9 | * @date 2019-05-28 21:13 10 | */ 11 | @Data 12 | public class CourseDomain { 13 | 14 | /** 15 | * 课程编码 16 | */ 17 | private String courseCode; 18 | 19 | /** 20 | * 课程Id 21 | */ 22 | private Integer courseId; 23 | 24 | /** 25 | * 课程名称 26 | */ 27 | private String courseName; 28 | 29 | /** 30 | * 老师名称 31 | */ 32 | private String teacherName; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /spring-boot-unified-return/src/main/java/com/example/unifiedreturn/UnifiedreturnApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.unifiedreturn; 2 | 3 | import com.example.unifiedreturn.exception.TestBean; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | public class UnifiedreturnApplication { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(UnifiedreturnApplication.class, args); 12 | TestBean testBean = new TestBean(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /spring-bean-life-cycle/MyBeanPostProcessor.java: -------------------------------------------------------------------------------- 1 | public class MyBeanPostProcessor implements BeanPostProcessor { 2 | @Override 3 | public Object postProcessAfterInitialization(Object bean, String beanName) 4 | throws BeansException { 5 | System.out.println("BeanPostProcessor.postProcessAfterInitialization"); 6 | return bean; 7 | } 8 | 9 | @Override 10 | public Object postProcessBeforeInitialization(Object bean, String beanName) 11 | throws BeansException { 12 | System.out.println("BeanPostProcessor.postProcessBeforeInitialization"); 13 | return bean; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /dozer-demo/src/main/resources/dozerBeanMapping.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | false 8 | yyyy-MM-dd HH:mm:ss 9 | 10 | 11 | -------------------------------------------------------------------------------- /custom-starter/rgyb-spring-boot-sample/src/main/java/top/dayarch/learnings/rgybspringbootsample/RgybSpringBootSampleApplication.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.learnings.rgybspringbootsample; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | public class RgybSpringBootSampleApplication { 9 | 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(RgybSpringBootSampleApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /mybatis-interceptor/interceptor/EncryptDecryptImpl.java: -------------------------------------------------------------------------------- 1 | package com.demo.interceptor; 2 | 3 | /** 4 | * 加解密接口实现 5 | * 6 | * @author fraser 7 | * @date 2019-05-20 15:00 8 | */ 9 | @Component 10 | public class EncryptDecryptImpl implements IEncryptDecrypt { 11 | @Override 12 | public T encrypt(Field[] declaredFields, T parameterObject) throws IllegalAccessException { 13 | return EncryptDecryptUtils.encrypt(declaredFields, parameterObject); 14 | } 15 | 16 | @Override 17 | public T decrypt(T result) throws IllegalAccessException { 18 | return EncryptDecryptUtils.decrypt(result); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /concurrency/src/test/java/top/dayarch/StaticTest.java: -------------------------------------------------------------------------------- 1 | package top.dayarch; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /** 9 | * 静态变量使用 10 | * 11 | * @author fraser 12 | * @date 2020/7/29 11:08 AM 13 | */ 14 | @Slf4j 15 | public class StaticTest { 16 | public static List list = new ArrayList<>(); 17 | 18 | public void populateList() { 19 | List list = new ArrayList<>(); 20 | for (int i = 0; i < 10000000; i++) { 21 | list.add(Math.random()); 22 | } 23 | } 24 | 25 | public static void main(String[] args) { 26 | new StaticTest().populateList(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /custom-starter/rgyb-spring-boot-autoconfigure/src/main/java/top/dayarch/autoconfigure/GreetingProperties.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.autoconfigure; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * 问候属性配置 11 | * 12 | * @author fraser 13 | * @date 2019/10/15 5:01 PM 14 | */ 15 | @Data 16 | @ConfigurationProperties(prefix = "rgyb.greeting") 17 | public class GreetingProperties { 18 | 19 | /** 20 | * GreetingProperties 开关 21 | */ 22 | boolean enable = false; 23 | 24 | /** 25 | * 需要打招呼的成员列表 26 | */ 27 | List members = new ArrayList(); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /springboot-application-startup/src/main/java/top/dayarch/startup/activity/MyInitializingBean.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.startup.activity; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.beans.factory.InitializingBean; 5 | import org.springframework.context.annotation.DependsOn; 6 | import org.springframework.stereotype.Component; 7 | 8 | import javax.annotation.PostConstruct; 9 | 10 | /** 11 | * @author fraser 12 | * @date 2019/12/19 9:28 PM 13 | */ 14 | //@Component 15 | @Slf4j 16 | public class MyInitializingBean implements InitializingBean { 17 | 18 | 19 | @Override 20 | public void afterPropertiesSet() throws Exception { 21 | log.info("MyInitializingBean.afterPropertiesSet()"); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /mybatis-interceptor/interceptor/IEncryptDecrypt.java: -------------------------------------------------------------------------------- 1 | package com.demo.interceptor; 2 | 3 | import java.lang.reflect.Field; 4 | 5 | /** 6 | * 加解密接口, 可实现自定义方法定义加密解密规则 7 | * 8 | * @author fraser 9 | * @date 2019-05-20 14:53 10 | */ 11 | public interface IEncryptDecrypt { 12 | 13 | /** 14 | * 加密方法 15 | * 16 | * @param declaredFields 反射bean成员变量 17 | * @param parameterObject Mybatis入参 18 | * @param 19 | * @return 20 | */ 21 | public T encrypt(Field[] declaredFields, T parameterObject) throws IllegalAccessException; 22 | 23 | 24 | /** 25 | * 解密方法 26 | * 27 | * @param result Mybatis 返回值,需要判断是否是ArrayList类型 28 | * @param 29 | * @return 30 | */ 31 | public T decrypt(T result) throws IllegalAccessException; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /spring-boot-unified-return/src/main/java/com/example/unifiedreturn/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.unifiedreturn.service.impl; 2 | 3 | import com.example.unifiedreturn.exception.BusinessException; 4 | import com.example.unifiedreturn.service.UserService; 5 | import com.example.unifiedreturn.vo.UserVo; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * 用户服务实现 10 | * 11 | * @author fraser 12 | * @date 2019-08-09 11:23 13 | */ 14 | @Service 15 | public class UserServiceImpl implements UserService { 16 | 17 | /** 18 | * 根据用户ID查询用户 19 | * 20 | * @param id 21 | * @return 22 | */ 23 | @Override 24 | public UserVo getUserById(Long id) { 25 | throw new BusinessException("1001", "根据ID查询用户异常"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /easy-excel-demo/src/main/java/com/example/easyexcel/demo/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.easyexcel.demo.service.impl; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.example.easyexcel.demo.entity.User; 5 | import com.example.easyexcel.demo.service.IUser; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * 用户人员实现类 13 | * 14 | * @author fraser 15 | * @date 2019/10/7 2:02 PM 16 | */ 17 | @Service 18 | @Slf4j 19 | public class UserServiceImpl implements IUser { 20 | @Override 21 | public boolean saveData(List users) { 22 | log.info("UserService {}条数据,开始存储数据库!", users.size()); 23 | log.info(JSON.toJSONString(users)); 24 | log.info("UserService 存储数据库成功!"); 25 | return true; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-boot-unified-return/src/main/java/com/example/unifiedreturn/converter/StringToLocalDateTimeConverter.java: -------------------------------------------------------------------------------- 1 | package com.example.unifiedreturn.converter; 2 | 3 | import org.springframework.core.convert.converter.Converter; 4 | import org.springframework.stereotype.Component; 5 | 6 | import java.time.LocalDateTime; 7 | import java.time.format.DateTimeFormatter; 8 | import java.util.Locale; 9 | 10 | /** 11 | * String 2 Localdatetime 转换器 12 | * 13 | * @author fraser 14 | * @date 2019/12/12 1:14 PM 15 | */ 16 | public class StringToLocalDateTimeConverter implements Converter { 17 | @Override 18 | public LocalDateTime convert(String s) { 19 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.CHINESE); 20 | return LocalDateTime.parse(s, formatter); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /custom-starter/rgyb-spring-boot-sample/src/test/java/top/dayarch/learnings/rgybspringbootsample/LambdaTest.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.learnings.rgybspringbootsample; 2 | 3 | import org.junit.Test; 4 | 5 | /** 6 | * Lambda Test 7 | * 8 | * @author fraser 9 | * @date 2019/10/24 11:09 AM 10 | */ 11 | public class LambdaTest { 12 | 13 | 14 | 15 | 16 | 17 | public void testRunnable(Runnable runnable){ 18 | runnable.run(); 19 | } 20 | 21 | 22 | @Test 23 | public void callTestRunnable1(){ 24 | testRunnable(new Runnable() { 25 | @Override 26 | public void run() { 27 | System.out.println("hello Runnable"); 28 | } 29 | }); 30 | } 31 | 32 | @Test 33 | public void callTestRunnable(){ 34 | testRunnable(() -> System.out.println("hello Runnable")); 35 | } 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /lombok-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | top.dayarch 8 | lombok-demo 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | 14 | 15 | org.projectlombok 16 | lombok 17 | 1.18.10 18 | provided 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /springboot-application-startup/src/main/java/top/dayarch/startup/activity/MyPostConstructBean.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.startup.activity; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.annotation.DependsOn; 6 | import org.springframework.stereotype.Component; 7 | import top.dayarch.startup.service.StartupService; 8 | 9 | import javax.annotation.PostConstruct; 10 | 11 | 12 | /** 13 | * @author fraser 14 | * @date 2019/12/19 9:22 PM 15 | */ 16 | @Component 17 | @Slf4j 18 | @DependsOn("myApplicationListener") 19 | public class MyPostConstructBean { 20 | 21 | @Autowired 22 | private StartupService startupService; 23 | 24 | @PostConstruct 25 | public void testPostConstruct(){ 26 | log.info("MyPostConstructBean"); 27 | // startupService.printLog(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /custom-starter/rgyb-spring-boot-sample/src/test/java/top/dayarch/learnings/rgybspringbootsample/RgybSpringBootSampleApplicationTests.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.learnings.rgybspringbootsample; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | import top.dayarch.service.GreetingService; 9 | 10 | @RunWith(SpringRunner.class) 11 | @SpringBootTest 12 | public class RgybSpringBootSampleApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | @Autowired(required = false) 19 | private GreetingService greetingService; 20 | 21 | @Test 22 | public void testGreeting() { 23 | greetingService.sayHello(); 24 | } 25 | 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /springboot-application-startup/src/main/java/top/dayarch/startup/activity/MySecondApplicationRunner.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.startup.activity; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.ApplicationArguments; 5 | import org.springframework.boot.ApplicationRunner; 6 | import org.springframework.core.annotation.Order; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * MyApplicationRunner 测试类 11 | * 12 | * @author fraser 13 | * @date 2019/12/19 8:48 PM 14 | */ 15 | //@Component 16 | @Slf4j 17 | @Order(4) 18 | public class MySecondApplicationRunner implements ApplicationRunner { 19 | 20 | 21 | @Override 22 | public void run(ApplicationArguments args) throws Exception { 23 | log.info("MySecondApplicationRunner order is 4"); 24 | log.info("MyApplicationRunner Current parameter is {}:", args.getOptionValues("foo")); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Java template 3 | # Compiled class file 4 | *.class 5 | 6 | # Log file 7 | *.log 8 | 9 | # BlueJ files 10 | *.ctxt 11 | 12 | # Mobile Tools for Java (J2ME) 13 | .mtj.tmp/ 14 | 15 | # Package Files # 16 | *.jar 17 | *.war 18 | *.nar 19 | *.ear 20 | *.zip 21 | *.tar.gz 22 | *.rar 23 | 24 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 25 | hs_err_pid* 26 | 27 | target/ 28 | target/*.* 29 | pom.xml.tag 30 | pom.xml.releaseBackup 31 | pom.xml.versionsBackup 32 | pom.xml.next 33 | release.properties 34 | dependency-reduced-pom.xml 35 | buildNumber.properties 36 | .mvn/timing.properties 37 | 38 | # Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) 39 | !/.mvn/wrapper/maven-wrapper.jar 40 | 41 | .DS_Store 42 | .idea 43 | .mvn 44 | *.iml 45 | *.lst 46 | /out 47 | 48 | 49 | -------------------------------------------------------------------------------- /springboot-application-startup/src/main/java/top/dayarch/startup/activity/MyCommandLineRunner.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.startup.activity; 2 | 3 | import lombok.Data; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.boot.CommandLineRunner; 6 | import org.springframework.core.annotation.Order; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * CommandLineRunner 测试类 11 | * 12 | * @author fraser 13 | * @date 2019/12/19 7:05 PM 14 | */ 15 | @Slf4j 16 | @Component 17 | @Order(2) 18 | public class MyCommandLineRunner implements CommandLineRunner { 19 | 20 | @Override 21 | public void run(String... args) throws Exception { 22 | log.info("MyCommandLineRunner order is 2"); 23 | if (args.length > 0){ 24 | for (int i = 0; i < args.length; i++) { 25 | log.info("MyCommandLineRunner current parameter is: {}", args[i]); 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-bean-life-cycle/spring-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /lombok-demo/src/main/java/Student.java: -------------------------------------------------------------------------------- 1 | import java.util.Objects; 2 | 3 | /** 4 | * 学生类 5 | * 6 | * @author fraser 7 | * @date 2019/12/16 9:34 PM 8 | */ 9 | public class Student { 10 | 11 | private String name; 12 | 13 | private int age; 14 | 15 | @Override 16 | public boolean equals(Object o) { 17 | if (this == o) return true; 18 | if (o == null || getClass() != o.getClass()) return false; 19 | Student student = (Student) o; 20 | return age == student.age && 21 | Objects.equals(name, student.name); 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | return Objects.hash(name, age); 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | public int getAge() { 38 | return age; 39 | } 40 | 41 | public void setAge(int age) { 42 | this.age = age; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /springboot-application-startup/src/main/java/top/dayarch/startup/activity/MySecondCommandLineRunner.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.startup.activity; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.CommandLineRunner; 5 | import org.springframework.core.annotation.Order; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * CommandLineRunner 测试类 10 | * 11 | * @author fraser 12 | * @date 2019/12/19 7:05 PM 13 | */ 14 | @Slf4j 15 | //@Component 16 | @Order(-2) 17 | public class MySecondCommandLineRunner implements CommandLineRunner { 18 | 19 | 20 | @Override 21 | public void run(String... args) throws Exception { 22 | log.info("MySecondCommandLineRunner order is -2"); 23 | if (args.length > 0){ 24 | for (int i = 0; i < args.length; i++) { 25 | log.info("MyCommandLineRunner current parameter is: {}", args[i]); 26 | } 27 | } 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /springboot-application-startup/src/main/java/top/dayarch/startup/activity/MyApplicationRunner.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.startup.activity; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.ApplicationArguments; 5 | import org.springframework.boot.ApplicationRunner; 6 | import org.springframework.core.annotation.Order; 7 | import org.springframework.stereotype.Component; 8 | import org.springframework.util.CollectionUtils; 9 | 10 | /** 11 | * MyApplicationRunner 测试类 12 | * 13 | * @author fraser 14 | * @date 2019/12/19 8:48 PM 15 | */ 16 | @Component 17 | @Slf4j 18 | @Order(1) 19 | public class MyApplicationRunner implements ApplicationRunner { 20 | 21 | 22 | @Override 23 | public void run(ApplicationArguments args) throws Exception { 24 | log.info("MyApplicationRunner order is 1"); 25 | log.info("MyApplicationRunner Current parameter is {}:", args.getOptionValues("foo")); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /configurationproperties/src/test/java/com/example/configurationproperties/ConfigurationpropertiesApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.configurationproperties; 2 | 3 | import com.example.configurationproperties.properties.MailModuleProperties; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | 11 | @RunWith(SpringRunner.class) 12 | @SpringBootTest 13 | @Slf4j 14 | public class ConfigurationpropertiesApplicationTests { 15 | 16 | @Autowired 17 | private MailModuleProperties mailModuleProperties; 18 | 19 | @Test 20 | public void contextLoads() { 21 | } 22 | 23 | @Test 24 | public void testProperties() { 25 | log.info(mailModuleProperties.toString()); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /dozer-demo/src/main/java/com/example/dozer/demo/vo/StudentVo.java: -------------------------------------------------------------------------------- 1 | package com.example.dozer.demo.vo; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | import java.util.List; 7 | 8 | /** 9 | * 用户Vo 10 | * 11 | * @author fraser 12 | * @date 2019-05-27 11:43 13 | */ 14 | @Data 15 | public class StudentVo { 16 | 17 | /** 18 | * 身份ID 19 | */ 20 | private Long id; 21 | 22 | /** 23 | * 姓名 24 | */ 25 | private String name; 26 | 27 | /** 28 | * 年龄 29 | */ 30 | private Integer age; 31 | 32 | /** 33 | * 电话 34 | */ 35 | private String mobile; 36 | 37 | /** 38 | * 地址 39 | */ 40 | private AddressVo address; 41 | 42 | /** 43 | * 课程 44 | */ 45 | private List courses; 46 | // 47 | /** 48 | * 班主任 49 | */ 50 | private String counsellor; 51 | 52 | /** 53 | * 入学日期 54 | */ 55 | private Date enrollmentDate; 56 | 57 | /** 58 | * 分数 59 | */ 60 | private ScoreEnum score; 61 | 62 | } 63 | -------------------------------------------------------------------------------- /dozer-demo/src/main/java/com/example/dozer/demo/converter/ScoreConverter.java: -------------------------------------------------------------------------------- 1 | package com.example.dozer.demo.converter; 2 | 3 | import com.example.dozer.demo.vo.ScoreEnum; 4 | import org.dozer.DozerConverter; 5 | 6 | /** 7 | * 分数Converter 8 | * 9 | * @author fraser 10 | * @date 2019-05-30 10:53 11 | */ 12 | public class ScoreConverter extends DozerConverter { 13 | 14 | 15 | public ScoreConverter() { 16 | super(Integer.class, ScoreEnum.class); 17 | } 18 | 19 | @Override 20 | public ScoreEnum convertTo(Integer score, ScoreEnum scoreEnum) { 21 | if (60 <= score && score < 80) { 22 | return ScoreEnum.C; 23 | } else if (80 <= score && score < 90) { 24 | return ScoreEnum.B; 25 | } else if (90 <= score) { 26 | return ScoreEnum.A; 27 | } else { 28 | return ScoreEnum.D; 29 | } 30 | } 31 | 32 | @Override 33 | public Integer convertFrom(ScoreEnum scoreEnum, Integer integer) { 34 | return null; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic05/JoinExample.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic05; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | /** 6 | * Join 的使用 7 | * 8 | * @author fraser 9 | * @date 2020/6/26 5:39 PM 10 | */ 11 | @Slf4j 12 | public class JoinExample { 13 | 14 | public static void main(String[] args) throws InterruptedException { 15 | Thread thread1 = new Thread(() -> { 16 | try { 17 | Thread.sleep(1000); 18 | } catch (InterruptedException e) { 19 | e.printStackTrace(); 20 | } finally { 21 | log.info("Thread-1 执行完毕"); 22 | } 23 | }, "Thread-1"); 24 | 25 | Thread thread2 = new Thread(() -> { 26 | try { 27 | Thread.sleep(1000); 28 | } catch (InterruptedException e) { 29 | e.printStackTrace(); 30 | } finally { 31 | log.info("Thread-2 执行完毕"); 32 | } 33 | }, "Thread-2"); 34 | 35 | thread1.start(); 36 | thread2.start(); 37 | 38 | thread1.join(); 39 | thread2.join(); 40 | 41 | log.info("主线程执行完毕"); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /configurationproperties/src/main/java/com/example/configurationproperties/ConfigurationpropertiesApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.configurationproperties; 2 | 3 | import com.example.configurationproperties.properties.MailModuleProperties; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.WebApplicationType; 8 | import org.springframework.boot.autoconfigure.SpringBootApplication; 9 | import org.springframework.boot.builder.SpringApplicationBuilder; 10 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 11 | 12 | @SpringBootApplication 13 | @Slf4j 14 | @EnableConfigurationProperties(MailModuleProperties.class) 15 | public class ConfigurationpropertiesApplication { 16 | 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(ConfigurationpropertiesApplication.class, args); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /easy-excel-demo/src/test/java/com/example/easyexcel/demo/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.easyexcel.demo; 2 | 3 | import com.alibaba.excel.EasyExcel; 4 | import com.example.easyexcel.demo.entity.User; 5 | import com.example.easyexcel.demo.listener.UserExcelListener; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.boot.test.context.SpringBootTest; 10 | import org.springframework.test.context.junit4.SpringRunner; 11 | 12 | import java.io.File; 13 | 14 | @RunWith(SpringRunner.class) 15 | @SpringBootTest 16 | @Slf4j 17 | public class DemoApplicationTests { 18 | 19 | @Test 20 | public void contextLoads() { 21 | } 22 | 23 | /** 24 | * 非web环境的简单读取excel内容 25 | */ 26 | @Test 27 | public void readExcel(){ 28 | String fileName = TestUtils.getPath() + "excel" + File.separator + "users1.xlsx"; 29 | EasyExcel.read(fileName, User.class, new UserExcelListener()).sheet().doRead(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /dozer-demo/src/main/java/com/example/dozer/demo/domain/StudentDomain.java: -------------------------------------------------------------------------------- 1 | package com.example.dozer.demo.domain; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * 用户Domain 11 | * 12 | * @author fraser 13 | * @date 2019-05-27 11:43 14 | */ 15 | @Data 16 | @NoArgsConstructor 17 | @AllArgsConstructor 18 | public class StudentDomain { 19 | 20 | /** 21 | * 身份ID 22 | */ 23 | private Long id; 24 | 25 | /** 26 | * 姓名 27 | */ 28 | private String name; 29 | 30 | /** 31 | * 年龄 32 | */ 33 | private Integer age; 34 | 35 | /** 36 | * 电话 37 | */ 38 | private String mobile; 39 | 40 | 41 | /** 42 | * 地址 43 | */ 44 | private AddressDomain address; 45 | 46 | /** 47 | * 课程 48 | */ 49 | private List courses; 50 | 51 | /** 52 | * 入学日期 53 | */ 54 | private String enrollmentDate; 55 | 56 | /** 57 | * 分数 58 | */ 59 | private Integer score; 60 | } 61 | -------------------------------------------------------------------------------- /dozer-demo/src/main/java/com/example/dozer/demo/listener/StudentListener.java: -------------------------------------------------------------------------------- 1 | package com.example.dozer.demo.listener; 2 | 3 | 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.dozer.DozerConverter; 6 | import org.dozer.DozerEventListener; 7 | import org.dozer.event.DozerEvent; 8 | 9 | /** 10 | * 学生监听器 11 | * 12 | * @author fraser 13 | * @date 2019-05-30 13:44 14 | */ 15 | @Slf4j 16 | public class StudentListener implements DozerEventListener { 17 | 18 | @Override 19 | public void mappingStarted(DozerEvent dozerEvent) { 20 | log.info("mappingStarted"); 21 | } 22 | 23 | @Override 24 | public void preWritingDestinationValue(DozerEvent dozerEvent) { 25 | log.info("preWritingDestinationValue"); 26 | 27 | } 28 | 29 | @Override 30 | public void postWritingDestinationValue(DozerEvent dozerEvent) { 31 | log.info("postWritingDestinationValue"); 32 | } 33 | 34 | @Override 35 | public void mappingFinished(DozerEvent dozerEvent) { 36 | log.info("mappingFinished"); 37 | } 38 | } 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /custom-starter/rgyb-spring-boot-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | custom-starter 7 | top.dayarch.learnings 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | rgyb-spring-boot-starter 13 | 1.0.0.RELEASE 14 | jar 15 | 16 | 17 | 18 | top.dayarch.learnings 19 | rgyb-spring-boot-autoconfigure 20 | 1.0.0.RELEASE 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /springboot-application-startup/src/main/java/top/dayarch/startup/activity/MyApplicationListener.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.startup.activity; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.context.event.ApplicationReadyEvent; 6 | import org.springframework.context.ApplicationListener; 7 | import org.springframework.core.annotation.Order; 8 | import org.springframework.stereotype.Component; 9 | import top.dayarch.startup.service.StartupService; 10 | 11 | /** 12 | * @author fraser 13 | * @date 2019/12/19 9:17 PM 14 | */ 15 | @Slf4j 16 | @Component 17 | @Order(0) 18 | public class MyApplicationListener implements ApplicationListener { 19 | 20 | @Autowired 21 | private StartupService startupService; 22 | 23 | @Override 24 | public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) { 25 | log.info("MyApplicationListener is started up"); 26 | // startupService.printLog(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic07/CompletableFutureCombine.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic07; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.util.concurrent.CompletableFuture; 6 | import java.util.concurrent.ExecutionException; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | /** 10 | * callback compose 11 | * 12 | * @author fraser 13 | * @date 2020/7/19 6:59 PM 14 | */ 15 | @Slf4j 16 | public class CompletableFutureCombine { 17 | 18 | public static void main(String[] args) throws ExecutionException, InterruptedException { 19 | CompletableFuture weightFuture = CompletableFuture.supplyAsync(() -> 65.0); 20 | CompletableFuture heightFuture = CompletableFuture.supplyAsync(() -> 183.8); 21 | 22 | CompletableFuture combinedFuture = weightFuture 23 | .thenCombine(heightFuture, (weight, height) -> { 24 | Double heightInMeter = height/100; 25 | return weight/(heightInMeter*heightInMeter); 26 | }); 27 | 28 | log.info("身体BMI指标 - " + combinedFuture.get()); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /configurationproperties/src/main/java/com/example/configurationproperties/configuration/PropertiesConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.configurationproperties.configuration; 2 | 3 | import com.example.configurationproperties.converter.WeightConverter; 4 | import com.example.configurationproperties.properties.MailModuleProperties; 5 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 6 | import org.springframework.boot.context.properties.ConfigurationPropertiesBinding; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | /** 11 | * 属性配置 12 | * 13 | * @author fraser 14 | * @date 2019-07-23 19:39 15 | */ 16 | @Configuration 17 | public class PropertiesConfig { 18 | 19 | // @Bean 20 | // public MailModuleProperties mailModuleProperties(){ 21 | // return new MailModuleProperties(); 22 | // 23 | // } 24 | 25 | @Bean 26 | @ConfigurationPropertiesBinding 27 | public WeightConverter weightConverter() { 28 | return new WeightConverter(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lombok-demo/src/main/java/Test.java: -------------------------------------------------------------------------------- 1 | import lombok.EqualsAndHashCode; 2 | 3 | import java.util.HashMap; 4 | import java.util.HashSet; 5 | import java.util.Map; 6 | import java.util.Set; 7 | 8 | /** 9 | * @author fraser 10 | * @date 2019/11/25 9:55 AM 11 | */ 12 | public class Test { 13 | 14 | public static void main(String[] args) { 15 | Student student1 = new Student(); 16 | student1.setName("日拱一兵"); 17 | student1.setAge(18); 18 | 19 | Student student2 = new Student(); 20 | student2.setName("日拱一兵"); 21 | student2.setAge(18); 22 | 23 | System.out.println("student1.equals(student2)的结果是:" + student1.equals(student2)); 24 | 25 | Set students = new HashSet(); 26 | students.add(student1); 27 | students.add(student2); 28 | System.out.println("Student Set 集合长度是:" + students.size()); 29 | 30 | Map map = new HashMap(); 31 | map.put(student1, "student1"); 32 | map.put(student2, "student2"); 33 | System.out.println("Student Map 集合长度是:" + map.keySet().size()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-boot-unified-return/src/main/java/com/example/unifiedreturn/vo/CommonResult.java: -------------------------------------------------------------------------------- 1 | package com.example.unifiedreturn.vo; 2 | 3 | import lombok.Data; 4 | import lombok.RequiredArgsConstructor; 5 | 6 | /** 7 | * Api统一结果 8 | * 9 | * @author fraser 10 | * @date 2019-08-08 16:57 11 | */ 12 | @Data 13 | public final class CommonResult { 14 | 15 | private int status = 1; 16 | 17 | private String errorCode = ""; 18 | 19 | private String errorMsg = ""; 20 | 21 | private T resultBody; 22 | 23 | public CommonResult() { 24 | } 25 | 26 | public CommonResult(T resultBody) { 27 | this.resultBody = resultBody; 28 | } 29 | 30 | public CommonResult(int status, T resultBody) { 31 | this.status = status; 32 | this.resultBody = resultBody; 33 | } 34 | 35 | public static CommonResult errorResult(String errorCode, String errorMsg) { 36 | CommonResult commonResult = new CommonResult<>(); 37 | commonResult.errorCode = errorCode; 38 | commonResult.errorMsg = errorMsg; 39 | commonResult.status = -1; 40 | return commonResult; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /xss-demo/GlobalSecurityFilter.java: -------------------------------------------------------------------------------- 1 | import lombok.extern.slf4j.Slf4j; 2 | import org.apache.commons.lang3.StringUtils; 3 | import org.springframework.web.filter.OncePerRequestFilter; 4 | 5 | import javax.servlet.FilterChain; 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import java.io.IOException; 10 | 11 | 12 | @Slf4j 13 | public class GlobalSecurityFilter extends OncePerRequestFilter { 14 | 15 | 16 | @Override 17 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { 18 | String contentType = request.getContentType(); 19 | if (StringUtils.isNotBlank(contentType) && contentType.contains("multipart/form-data")) { 20 | filterChain.doFilter(request, response); 21 | } else { 22 | GlobalSecurityRequestWrapper xssHttpServletRequestWrapper = new GlobalSecurityRequestWrapper((HttpServletRequest) request); 23 | filterChain.doFilter(xssHttpServletRequestWrapper, response); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-boot-unified-return/src/main/java/com/example/unifiedreturn/api/BindingController.java: -------------------------------------------------------------------------------- 1 | package com.example.unifiedreturn.api; 2 | 3 | import com.example.unifiedreturn.annotation.LoginUser; 4 | import com.example.unifiedreturn.vo.LoginUserVo; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import java.time.LocalDateTime; 12 | 13 | /** 14 | * 绑定机制controller 15 | * 16 | * @author fraser 17 | * @date 2019/12/11 2:15 PM 18 | */ 19 | @RestController 20 | @RequestMapping("/bindings/") 21 | @Slf4j 22 | public class BindingController { 23 | 24 | 25 | @GetMapping("/{date}") 26 | public void getSpecificDateInfo(@PathVariable("date") LocalDateTime date) { 27 | log.info(date.toString()); 28 | } 29 | 30 | @GetMapping("/id") 31 | public void getLoginUserInfo(@LoginUser LoginUserVo loginUserVo) { 32 | log.info(loginUserVo.toString()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic01/VisibilityIssue.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic01; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | /** 6 | * 并发编程可见性问题验证 7 | * 8 | * @author fraser 9 | * @date 2020/2/27 7:40 PM 10 | */ 11 | @Slf4j 12 | public class VisibilityIssue { 13 | private static final int TOTAL = 10000; 14 | // private int count; 15 | 16 | // 即便像下面这样加了 volatile 关键字修饰依旧不会解决问题,因为并没有解决原子性问题 17 | private volatile int count; 18 | 19 | public static void main(String[] args) { 20 | VisibilityIssue visibilityIssue = new VisibilityIssue(); 21 | 22 | Thread thread1 = new Thread(() -> visibilityIssue.add10KCount()); 23 | Thread thread2 = new Thread(() -> visibilityIssue.add10KCount()); 24 | 25 | thread1.start(); 26 | thread2.start(); 27 | 28 | try { 29 | thread1.join(); 30 | thread2.join(); 31 | } catch (InterruptedException e) { 32 | log.error(e.getMessage()); 33 | } 34 | 35 | log.info("count 值为:{}", visibilityIssue.count); 36 | 37 | } 38 | 39 | private void add10KCount(){ 40 | int start = 0; 41 | while (start ++ < TOTAL){ 42 | this.count ++; 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic07/CompletableFutureException.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic07; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.util.concurrent.CompletableFuture; 6 | import java.util.concurrent.ExecutionException; 7 | 8 | /** 9 | * callback exception 10 | * 11 | * @author fraser 12 | * @date 2020/7/19 6:59 PM 13 | */ 14 | @Slf4j 15 | public class CompletableFutureException { 16 | 17 | public static void main(String[] args) throws ExecutionException, InterruptedException { 18 | Integer age = -1; 19 | 20 | CompletableFuture maturityFuture = CompletableFuture.supplyAsync(() -> { 21 | if( age < 0 ) { 22 | throw new IllegalArgumentException("何方神圣?"); 23 | } 24 | if(age > 18) { 25 | return "大家都是成年人"; 26 | } else { 27 | return "未成年禁止入内"; 28 | } 29 | }).thenApply((str) -> { 30 | log.info("游戏开始"); 31 | return str; 32 | }).handle((res, ex) -> { 33 | if(ex != null) { 34 | log.info("必有蹊跷,来者" + ex.getMessage()); 35 | return "Unknown!"; 36 | } 37 | return res; 38 | }); 39 | 40 | log.info(maturityFuture.get()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /custom-starter/rgyb-spring-boot-autoconfigure/src/main/java/top/dayarch/autoconfigure/GreetingAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.autoconfigure; 2 | 3 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 4 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 5 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import top.dayarch.service.DummyEmail; 9 | import top.dayarch.service.GreetingService; 10 | 11 | /** 12 | * 问候自动配置类 13 | * 14 | * @author fraser 15 | * @date 2019/10/15 4:55 PM 16 | */ 17 | @Configuration 18 | @ConditionalOnProperty(value = "rgyb.greeting.enable", havingValue = "true") 19 | @ConditionalOnClass(DummyEmail.class) 20 | @EnableConfigurationProperties(GreetingProperties.class) 21 | public class GreetingAutoConfiguration { 22 | 23 | @Bean 24 | public GreetingService greetingService(GreetingProperties greetingProperties){ 25 | return new GreetingService(greetingProperties.getMembers()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /easy-excel-demo/src/main/java/com/example/easyexcel/demo/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.example.easyexcel.demo.entity; 2 | 3 | import com.alibaba.excel.annotation.ExcelIgnore; 4 | import com.alibaba.excel.annotation.ExcelProperty; 5 | import com.alibaba.excel.annotation.format.DateTimeFormat; 6 | import com.example.easyexcel.demo.converter.GenderConverter; 7 | import lombok.Data; 8 | 9 | import java.util.Date; 10 | 11 | /** 12 | * 用户人员实体 13 | * 14 | * @author fraser 15 | * @date 2019/10/6 10:05 AM 16 | */ 17 | @Data 18 | public class User { 19 | 20 | /** 21 | * 姓名 22 | */ 23 | @ExcelProperty(index = 0) 24 | private String name; 25 | 26 | /** 27 | * 年龄 28 | */ 29 | @ExcelProperty(index = 1) 30 | private Integer age; 31 | 32 | /** 33 | * 性别 1:男;2:女 34 | */ 35 | @ExcelProperty(index = 2, converter = GenderConverter.class) 36 | private Integer gender; 37 | 38 | /** 39 | * 出生日期 40 | */ 41 | @ExcelProperty(index = 3) 42 | @DateTimeFormat("yyyy-MM-dd HH:mm:ss") 43 | private String birth; 44 | 45 | /** 46 | * 是否已婚 47 | */ 48 | // @ExcelProperty(index = 4) 49 | // @ExcelIgnore 50 | // private boolean married; 51 | } 52 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic02/SimpleBlockingQueue.java: -------------------------------------------------------------------------------- 1 | //package top.dayarch.topic02; 2 | // 3 | //import java.util.concurrent.locks.Condition; 4 | //import java.util.concurrent.locks.Lock; 5 | //import java.util.concurrent.locks.ReentrantLock; 6 | // 7 | ///** 8 | // * 简单队列模型抽象 9 | // * 10 | // * @author fraser 11 | // * @date 2020/3/15 10:19 AM 12 | // */ 13 | //public class SimpleBlockingQueue { 14 | // 15 | // final Lock lock = new ReentrantLock(); 16 | // // 条件变量:队列不满 17 | // final Condition notFull = lock.newCondition(); 18 | // // 条件变量:队列不空 19 | // final Condition notEmpty = lock.newCondition(); 20 | // 21 | // // 入队 22 | // void enq(T x) { 23 | // lock.lock(); 24 | // try { 25 | // while (队列已满){ 26 | // // 等待队列不满 27 | // notFull.await(); 28 | // } 29 | // // 省略入队操作... 30 | // //入队后,通知可出队 31 | // notEmpty.signal(); 32 | // }finally { 33 | // lock.unlock(); 34 | // } 35 | // } 36 | // // 出队 37 | // void deq(){ 38 | // lock.lock(); 39 | // try { 40 | // while (队列已空){ 41 | // // 等待队列不空 42 | // notEmpty.await(); 43 | // } 44 | // // 省略出队操作... 45 | // //出队后,通知可入队 46 | // notFull.signal(); 47 | // }finally { 48 | // lock.unlock(); 49 | // } 50 | // } 51 | //} 52 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic06/FutureAndCallableExample.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic06; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.util.concurrent.*; 6 | 7 | /** 8 | * Callable Future 例子 9 | * 10 | * @author fraser 11 | * @date 2020/7/4 8:01 PM 12 | */ 13 | @Slf4j 14 | public class FutureAndCallableExample { 15 | 16 | public static void main(String[] args) throws InterruptedException, ExecutionException { 17 | ExecutorService executorService = Executors.newSingleThreadExecutor(); 18 | 19 | Callable callable = () -> { 20 | log.info("进入 Callable 的 call 方法"); 21 | // 模拟子线程任务,在此睡眠 2s, 22 | // 小细节:由于 call 方法会抛出 Exception,这里不用像使用 Runnable 的run 方法那样 try/catch 了 23 | Thread.sleep(5000); 24 | return "Hello from Callable"; 25 | }; 26 | 27 | log.info("提交 Callable 到线程池"); 28 | Future future = executorService.submit(callable); 29 | 30 | log.info("主线程继续执行"); 31 | 32 | while(!future.isDone()) { 33 | System.out.println("子线程任务还没有结束..."); 34 | Thread.sleep(1000); 35 | } 36 | 37 | // log.info("主线程等待获取 Future 结果"); 38 | // Future.get() blocks until the result is available 39 | String result = future.get(); 40 | log.info("主线程获取到 Future 结果: {}", result); 41 | 42 | executorService.shutdown(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /configurationproperties/src/main/java/com/example/configurationproperties/entity/Weight.java: -------------------------------------------------------------------------------- 1 | package com.example.configurationproperties.entity; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.regex.Matcher; 6 | import java.util.regex.Pattern; 7 | 8 | /** 9 | * @author fraser 10 | * @date 2019-07-24 15:05 11 | */ 12 | @Data 13 | public class Weight { 14 | 15 | private static final Pattern PATTERN = Pattern.compile("^([0-9]+)(g|kg|t)$"); 16 | 17 | private long grams; 18 | 19 | private Weight(long grams) { 20 | this.grams = grams; 21 | } 22 | 23 | public static Weight fromString(String string) { 24 | Matcher matcher = PATTERN.matcher(string); 25 | if (matcher.matches()) { 26 | Long amount = Long.valueOf(matcher.group(1)); 27 | String unit = matcher.group(2); 28 | 29 | switch (unit) { 30 | case "g": 31 | return new Weight(amount); 32 | case "kg": 33 | return new Weight(amount * 1_000); 34 | case "t": 35 | return new Weight(amount * 1_000 * 1_000); 36 | default: 37 | throw new IllegalArgumentException(String.format("invalid weight unit %s", unit)); 38 | } 39 | } 40 | throw new IllegalArgumentException(String.format("invalid weight string %s", string)); 41 | } 42 | 43 | public long getGrams() { 44 | return grams; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic07/CompletableFutureCompose.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic07; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.util.concurrent.CompletableFuture; 6 | import java.util.concurrent.ExecutionException; 7 | 8 | /** 9 | * callback compose 10 | * 11 | * @author fraser 12 | * @date 2020/7/19 6:59 PM 13 | */ 14 | @Slf4j 15 | public class CompletableFutureCompose { 16 | 17 | public static void main(String[] args) throws ExecutionException, InterruptedException { 18 | CompletableFutureCompose completableFutureCompose = new CompletableFutureCompose(); 19 | // CompletableFuture> result = completableFutureCompose.getUsersDetail(12345L) 20 | // .thenApply(user -> completableFutureCompose.getCreditRating(user)); 21 | 22 | CompletableFuture result = completableFutureCompose.getUsersDetail(12345L) 23 | .thenCompose(user -> completableFutureCompose.getCreditRating(user)); 24 | } 25 | 26 | //获取用户信息详情 27 | CompletableFuture getUsersDetail(Long userId) { 28 | return CompletableFuture.supplyAsync(() -> User.builder().id(12345L).name("日拱一兵").build()); 29 | } 30 | 31 | //获取用户信用评级 32 | CompletableFuture getCreditRating(User user) { 33 | return CompletableFuture.supplyAsync(() -> CreditRating.builder().rating(7.5).build().getRating()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /easy-excel-demo/src/main/java/com/example/easyexcel/demo/converter/GenderConverter.java: -------------------------------------------------------------------------------- 1 | package com.example.easyexcel.demo.converter; 2 | 3 | import com.alibaba.excel.converters.Converter; 4 | import com.alibaba.excel.enums.CellDataTypeEnum; 5 | import com.alibaba.excel.metadata.CellData; 6 | import com.alibaba.excel.metadata.GlobalConfiguration; 7 | import com.alibaba.excel.metadata.property.ExcelContentProperty; 8 | 9 | /** 10 | * 性别converter 11 | * 12 | * @author fraser 13 | * @date 2019/10/7 9:26 AM 14 | */ 15 | public class GenderConverter implements Converter { 16 | 17 | public static final String MALE = "男"; 18 | public static final String FEMALE = "女"; 19 | 20 | @Override 21 | public Class supportJavaTypeKey() { 22 | return Integer.class; 23 | } 24 | 25 | @Override 26 | public CellDataTypeEnum supportExcelTypeKey() { 27 | return CellDataTypeEnum.STRING; 28 | } 29 | 30 | @Override 31 | public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception { 32 | String stringValue = cellData.getStringValue(); 33 | if (MALE.equals(stringValue)){ 34 | return 1; 35 | }else { 36 | return 2; 37 | } 38 | } 39 | 40 | @Override 41 | public CellData convertToExcelData(Integer integer, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception { 42 | return null; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic07/CompletableFuture1.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic07; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.util.concurrent.CompletableFuture; 6 | import java.util.concurrent.ExecutionException; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | /** 10 | * get() 阻塞事demo 11 | * 12 | * @author fraser 13 | * @date 2020/7/19 6:59 PM 14 | */ 15 | @Slf4j 16 | public class CompletableFuture1 { 17 | 18 | public static void main(String[] args) throws ExecutionException, InterruptedException { 19 | // CompletableFuture completableFuture = new CompletableFuture(); 20 | // completableFuture.complete("Future's Result Here Manually"); 21 | // completableFuture.getNow(null); 22 | // String result = completableFuture.get(); 23 | 24 | 25 | // CompletableFuture future = CompletableFuture.runAsync(() -> { 26 | // try { 27 | // TimeUnit.SECONDS.sleep(3); 28 | // } catch (InterruptedException e) { 29 | // throw new IllegalStateException(e); 30 | // } 31 | // log.info("运行在一个单独的线程当中"); 32 | // }); 33 | // 34 | // future.get(); 35 | 36 | 37 | 38 | CompletableFuture future = CompletableFuture.supplyAsync(() -> { 39 | try { 40 | TimeUnit.SECONDS.sleep(3); 41 | } catch (InterruptedException e) { 42 | throw new IllegalStateException(e); 43 | } 44 | log.info("运行在一个单独的线程当中"); 45 | return "我有返回值"; 46 | }); 47 | 48 | log.info(future.get()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /easy-excel-demo/src/main/java/com/example/easyexcel/demo/listener/UserExcelListener.java: -------------------------------------------------------------------------------- 1 | package com.example.easyexcel.demo.listener; 2 | 3 | import com.alibaba.excel.context.AnalysisContext; 4 | import com.alibaba.excel.event.AnalysisEventListener; 5 | import com.alibaba.fastjson.JSON; 6 | import com.example.easyexcel.demo.entity.User; 7 | import com.example.easyexcel.demo.service.IUser; 8 | import lombok.extern.slf4j.Slf4j; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | /** 14 | * 用户人员excel监听器 15 | * 16 | * @author fraser 17 | * @date 2019/10/6 10:22 AM 18 | */ 19 | @Slf4j 20 | public class UserExcelListener extends AnalysisEventListener { 21 | 22 | private IUser iUser; 23 | 24 | public UserExcelListener(){ 25 | 26 | } 27 | 28 | public UserExcelListener(IUser iUser){ 29 | this.iUser = iUser; 30 | } 31 | 32 | 33 | /** 34 | * 批处理阈值 35 | */ 36 | private static final int BATCH_COUNT = 2; 37 | List list = new ArrayList(); 38 | 39 | @Override 40 | public void invoke(User user, AnalysisContext analysisContext) { 41 | log.info("解析到一条数据:{}", JSON.toJSONString(user)); 42 | list.add(user); 43 | if (list.size() >= BATCH_COUNT) { 44 | saveData(); 45 | list.clear(); 46 | } 47 | } 48 | 49 | @Override 50 | public void doAfterAllAnalysed(AnalysisContext analysisContext) { 51 | saveData(); 52 | log.info("所有数据解析完成!"); 53 | } 54 | 55 | private void saveData(){ 56 | iUser.saveData(list); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic05/CountDownLatchExample.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic05; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.util.concurrent.CountDownLatch; 6 | import java.util.concurrent.ExecutorService; 7 | import java.util.concurrent.Executors; 8 | 9 | /** 10 | * CountDownLatch 使用案例 11 | * 12 | * @author fraser 13 | * @date 2020/6/26 6:08 PM 14 | */ 15 | @Slf4j 16 | public class CountDownLatchExample { 17 | 18 | private static CountDownLatch countDownLatch = new CountDownLatch(2); 19 | 20 | public static void main(String[] args) throws InterruptedException { 21 | // 这里不推荐这样创建线程池,最好通过 ThreadPoolExecutor 手动创建线程池 22 | ExecutorService executorService = Executors.newFixedThreadPool(2); 23 | 24 | executorService.submit(() -> { 25 | try { 26 | Thread.sleep(1000); 27 | } catch (InterruptedException e) { 28 | e.printStackTrace(); 29 | } finally { 30 | log.info("Thread-1 执行完毕"); 31 | //计数器减1 32 | countDownLatch.countDown(); 33 | } 34 | }); 35 | 36 | executorService.submit(() -> { 37 | try { 38 | Thread.sleep(1000); 39 | } catch (InterruptedException e) { 40 | e.printStackTrace(); 41 | } finally { 42 | log.info("Thread-2 执行完毕"); 43 | //计数器减1 44 | countDownLatch.countDown(); 45 | } 46 | }); 47 | 48 | log.info("主线程等待子线程执行完毕"); 49 | log.info("计数器值为:" + countDownLatch.getCount()); 50 | countDownLatch.await(); 51 | log.info("计数器值为:" + countDownLatch.getCount()); 52 | log.info("主线程执行完毕"); 53 | executorService.shutdown(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic06/MakeTeaExample.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic06; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.util.concurrent.*; 6 | 7 | /** 8 | * 烧水泡茶程序 9 | * 10 | * @author fraser 11 | * @date 2020/7/5 11:58 AM 12 | */ 13 | @Slf4j 14 | public class MakeTeaExample { 15 | 16 | public static void main(String[] args) throws ExecutionException, InterruptedException { 17 | ExecutorService executorService = Executors.newFixedThreadPool(2); 18 | 19 | // 创建线程1的FutureTask 20 | FutureTask ft1 = new FutureTask(new T1Task()); 21 | // 创建线程2的FutureTask 22 | FutureTask ft2 = new FutureTask(new T2Task()); 23 | 24 | executorService.submit(ft1); 25 | executorService.submit(ft2); 26 | 27 | log.info(ft1.get() + ft2.get()); 28 | log.info("开始泡茶"); 29 | 30 | executorService.shutdown(); 31 | } 32 | 33 | static class T1Task implements Callable { 34 | @Override 35 | public String call() throws Exception { 36 | log.info("T1:洗水壶..."); 37 | TimeUnit.SECONDS.sleep(1); 38 | 39 | log.info("T1:烧开水..."); 40 | TimeUnit.SECONDS.sleep(15); 41 | 42 | return "T1:开水已备好"; 43 | } 44 | } 45 | 46 | static class T2Task implements Callable { 47 | @Override 48 | public String call() throws Exception { 49 | log.info("T2:洗茶壶..."); 50 | TimeUnit.SECONDS.sleep(1); 51 | 52 | log.info("T2:洗茶杯..."); 53 | TimeUnit.SECONDS.sleep(2); 54 | 55 | log.info("T2:拿茶叶..."); 56 | TimeUnit.SECONDS.sleep(1); 57 | return "T2:福鼎白茶拿到了"; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic02/NotifyTest.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic02; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | /** 6 | * 测试notify 7 | * 8 | * @author fraser 9 | * @date 2020/3/12 8:33 PM 10 | */ 11 | @Slf4j 12 | public class NotifyTest { 13 | 14 | private static volatile Object resourceA = new Object(); 15 | 16 | public static void main(String[] args) throws InterruptedException { 17 | Thread threadA = new Thread(() -> { 18 | synchronized (resourceA){ 19 | log.info("threadA get resourceA lock"); 20 | 21 | try{ 22 | log.info("threadA begins to wait"); 23 | resourceA.wait(); 24 | log.info("threadA ends wait"); 25 | }catch (InterruptedException e){ 26 | log.error(e.getMessage()); 27 | } 28 | } 29 | }); 30 | 31 | Thread threadB = new Thread(() -> { 32 | synchronized (resourceA){ 33 | log.info("threadB get resourceA lock"); 34 | 35 | try{ 36 | log.info("threadB begins to wait"); 37 | resourceA.wait(); 38 | log.info("threadB ends wait"); 39 | }catch (InterruptedException e){ 40 | log.error(e.getMessage()); 41 | } 42 | } 43 | }); 44 | 45 | Thread threadC = new Thread(() -> { 46 | synchronized (resourceA){ 47 | log.info("threadC begin to notify"); 48 | resourceA.notifyAll(); 49 | } 50 | }); 51 | 52 | threadA.start(); 53 | threadB.start(); 54 | 55 | Thread.sleep(1000); 56 | 57 | threadC.start(); 58 | 59 | threadA.join(); 60 | threadB.join(); 61 | threadC.join(); 62 | 63 | log.info("main thread over now"); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /custom-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | top.dayarch.learnings 8 | custom-starter 9 | pom 10 | 1.0-SNAPSHOT 11 | 12 | rgyb-spring-boot-autoconfigure 13 | rgyb-spring-boot-starter 14 | rgyb-spring-boot-sample 15 | 16 | 17 | 18 | UTF-8 19 | UTF-8 20 | 1.8 21 | 2.1.9.RELEASE 22 | 23 | 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-dependencies 29 | ${spring-boot.version} 30 | pom 31 | import 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic06/FutureCancelExample.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic06; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.util.concurrent.*; 6 | 7 | /** 8 | * Callable Future 例子 9 | * 10 | * @author fraser 11 | * @date 2020/7/4 8:01 PM 12 | */ 13 | @Slf4j 14 | public class FutureCancelExample { 15 | 16 | public static void main(String[] args) throws InterruptedException, ExecutionException { 17 | ExecutorService executorService = Executors.newSingleThreadExecutor(); 18 | 19 | long startTime = System.nanoTime(); 20 | Callable callable = () -> { 21 | log.info("进入 Callable 的 call 方法"); 22 | // 模拟子线程任务,在此睡眠 2s, 23 | // 小细节:由于 call 方法会抛出 Exception,这里不用像使用 Runnable 的run 方法那样 try/catch 了 24 | Thread.sleep(5000); 25 | return "Hello from Callable"; 26 | }; 27 | 28 | log.info("提交 Callable 到线程池"); 29 | Future future = executorService.submit(callable); 30 | 31 | log.info("主线程继续执行"); 32 | 33 | while(!future.isDone()) { 34 | System.out.println("子线程任务还没有结束..."); 35 | Thread.sleep(1000); 36 | 37 | double elapsedTimeInSec = (System.nanoTime() - startTime)/1000000000.0; 38 | 39 | if(elapsedTimeInSec > 1) { 40 | future.cancel(true); 41 | } 42 | } 43 | 44 | // log.info("主线程等待获取 Future 结果"); 45 | // Future.get() blocks until the result is available 46 | if (!future.isCancelled()){ 47 | log.info("子线程任务已完成"); 48 | String result = future.get(); 49 | log.info("主线程获取到 Future 结果: {}", result); 50 | }else { 51 | log.warn("子线程任务被取消"); 52 | } 53 | 54 | 55 | executorService.shutdown(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic05/CountDownLatchTimeoutExample.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic05; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.util.concurrent.CountDownLatch; 6 | import java.util.concurrent.ExecutorService; 7 | import java.util.concurrent.Executors; 8 | import java.util.concurrent.TimeUnit; 9 | 10 | /** 11 | * CountDownLatch 使用案例 12 | * 13 | * @author fraser 14 | * @date 2020/6/26 6:08 PM 15 | */ 16 | @Slf4j 17 | public class CountDownLatchTimeoutExample { 18 | 19 | private static CountDownLatch countDownLatch = new CountDownLatch(2); 20 | 21 | public static void main(String[] args) throws InterruptedException { 22 | // 这里不推荐这样创建线程池,最好通过 ThreadPoolExecutor 手动创建线程池 23 | ExecutorService executorService = Executors.newFixedThreadPool(2); 24 | 25 | executorService.submit(() -> { 26 | try { 27 | Thread.sleep(5000); 28 | } catch (InterruptedException e) { 29 | e.printStackTrace(); 30 | } finally { 31 | log.info("Thread-1 执行完毕"); 32 | //计数器减1 33 | countDownLatch.countDown(); 34 | } 35 | }); 36 | 37 | executorService.submit(() -> { 38 | try { 39 | Thread.sleep(5000); 40 | } catch (InterruptedException e) { 41 | e.printStackTrace(); 42 | } finally { 43 | log.info("Thread-2 执行完毕"); 44 | //计数器减1 45 | countDownLatch.countDown(); 46 | } 47 | }); 48 | 49 | log.info("主线程等待子线程执行完毕"); 50 | log.info("计数器值为:" + countDownLatch.getCount()); 51 | countDownLatch.await(2, TimeUnit.SECONDS); 52 | log.info("计数器值为:" + countDownLatch.getCount()); 53 | log.info("主线程执行完毕"); 54 | executorService.shutdown(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /easy-excel-demo/src/main/java/com/example/easyexcel/demo/utils/ExcelDemoUtils.java: -------------------------------------------------------------------------------- 1 | package com.example.easyexcel.demo.utils; 2 | 3 | import com.alibaba.excel.context.AnalysisContext; 4 | import com.alibaba.excel.event.AnalysisEventListener; 5 | import com.alibaba.fastjson.JSON; 6 | import com.example.easyexcel.demo.entity.User; 7 | import lombok.extern.slf4j.Slf4j; 8 | 9 | import java.util.ArrayList; 10 | import java.util.LinkedList; 11 | import java.util.List; 12 | import java.util.function.Consumer; 13 | 14 | /** 15 | * @author fraser 16 | * @date 2019/10/7 2:41 PM 17 | */ 18 | @Slf4j 19 | public class ExcelDemoUtils { 20 | 21 | /** 22 | * 指定阈值 23 | * @param consumer 24 | * @param threshold 25 | * @param 26 | * @return 27 | */ 28 | public static AnalysisEventListener getListener(Consumer> consumer, int threshold) { 29 | return new AnalysisEventListener() { 30 | private LinkedList linkedList = new LinkedList(); 31 | 32 | @Override 33 | public void invoke(T t, AnalysisContext analysisContext) { 34 | linkedList.add(t); 35 | if (linkedList.size() == threshold){ 36 | consumer.accept(linkedList); 37 | linkedList.clear(); 38 | } 39 | } 40 | 41 | @Override 42 | public void doAfterAllAnalysed(AnalysisContext analysisContext) { 43 | if (linkedList.size() > 0){ 44 | consumer.accept(linkedList); 45 | } 46 | } 47 | }; 48 | } 49 | 50 | /** 51 | * 不指定阈值,阈值默认为10 52 | * @param consumer 53 | * @param 54 | * @return 55 | */ 56 | public static AnalysisEventListener getListener(Consumer> consumer){ 57 | return getListener(consumer, 10); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic06/MakeTeaExample1.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic06; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.util.concurrent.*; 6 | 7 | /** 8 | * 烧水泡茶程序 9 | * 10 | * @author fraser 11 | * @date 2020/7/5 11:58 AM 12 | */ 13 | @Slf4j 14 | public class MakeTeaExample1 { 15 | 16 | public static void main(String[] args) throws ExecutionException, InterruptedException { 17 | ExecutorService executorService = Executors.newFixedThreadPool(2); 18 | 19 | // 创建线程2的FutureTask 20 | FutureTask ft2 = new FutureTask(new T2Task()); 21 | // 创建线程1的FutureTask 22 | FutureTask ft1 = new FutureTask(new T1Task(ft2)); 23 | 24 | executorService.submit(ft1); 25 | executorService.submit(ft2); 26 | 27 | executorService.shutdown(); 28 | } 29 | 30 | static class T1Task implements Callable { 31 | 32 | private FutureTask ft2; 33 | public T1Task(FutureTask ft2) { 34 | this.ft2 = ft2; 35 | } 36 | 37 | @Override 38 | public String call() throws Exception { 39 | log.info("T1:洗水壶..."); 40 | TimeUnit.SECONDS.sleep(1); 41 | 42 | log.info("T1:烧开水..."); 43 | TimeUnit.SECONDS.sleep(15); 44 | 45 | String t2Result = ft2.get(); 46 | log.info("T1 拿到T2的 {}, 开始泡茶", t2Result); 47 | return "T1: 上茶!!!"; 48 | } 49 | } 50 | 51 | static class T2Task implements Callable { 52 | @Override 53 | public String call() throws Exception { 54 | log.info("T2:洗茶壶..."); 55 | TimeUnit.SECONDS.sleep(1); 56 | 57 | log.info("T2:洗茶杯..."); 58 | TimeUnit.SECONDS.sleep(2); 59 | 60 | log.info("T2:拿茶叶..."); 61 | TimeUnit.SECONDS.sleep(1); 62 | return "福鼎白茶"; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /xss-demo/validation.properties: -------------------------------------------------------------------------------- 1 | # The ESAPI validator does many security checks on input, such as canonicalization 2 | # and whitelist validation. Note that all of these validation rules are applied *after* 3 | # canonicalization. Double-encoded characters (even with different encodings involved, 4 | # are never allowed. 5 | # 6 | # To use: 7 | # 8 | # First set up a pattern below. You can choose any name you want, prefixed by the word 9 | # "Validation." For example: 10 | # Validation.Email=^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\\.[a-zA-Z]{2,4}$ 11 | # 12 | # Then you can validate in your code against the pattern like this: 13 | # ESAPI.validator().isValidInput("User Email", input, "Email", maxLength, allowNull); 14 | # Where maxLength and allowNull are set for you needs, respectively. 15 | # 16 | # But note, when you use boolean variants of validation functions, you lose critical 17 | # canonicalization. It is preferable to use the "get" methods (which throw exceptions) and 18 | # and use the returned user input which is in canonical form. Consider the following: 19 | # 20 | # try { 21 | # someObject.setEmail(ESAPI.validator().getValidInput("User Email", input, "Email", maxLength, allowNull)); 22 | # 23 | Validator.SafeString=^[.\\p{Alnum}\\p{Space}]{0,1024}$ 24 | Validator.Email=^[A-Za-z0-9._%'-]+@[A-Za-z0-9.-]+\\.[a-zA-Z]{2,4}$ 25 | Validator.IPAddress=^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$ 26 | Validator.URL=^(ht|f)tp(s?)\\:\\/\\/[0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\.\\?\\,\\:\\'\\/\\\\\\+=&;%\\$#_]*)?$ 27 | Validator.CreditCard=^(\\d{4}[- ]?){3}\\d{4}$ 28 | Validator.SSN=^(?!000)([0-6]\\d{2}|7([0-6]\\d|7[012]))([ -]?)(?!00)\\d\\d\\3(?!0000)\\d{4}$ -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic07/CompletableFutureCallback.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic07; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.util.concurrent.CompletableFuture; 6 | import java.util.concurrent.ExecutionException; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | /** 10 | * callback 11 | * 12 | * @author fraser 13 | * @date 2020/7/19 6:59 PM 14 | */ 15 | @Slf4j 16 | public class CompletableFutureCallback { 17 | 18 | public static void main(String[] args) throws ExecutionException, InterruptedException { 19 | // CompletableFuture comboText = CompletableFuture.supplyAsync(() -> { 20 | // try { 21 | // TimeUnit.SECONDS.sleep(3); 22 | // } catch (InterruptedException e) { 23 | // throw new IllegalStateException(e); 24 | // } 25 | //// log.info("👍"); 26 | // return "赞"; 27 | // }) 28 | // .thenApply(first -> { 29 | // log.info("在看"); 30 | // return first + ", 在看"; 31 | // }) 32 | // .thenApply(second -> second + ", 转发"); 33 | // 34 | // log.info("三连有没有?"); 35 | // log.info(comboText.get()); 36 | 37 | 38 | // final CompletableFuture voidCompletableFuture = CompletableFuture.supplyAsync( 39 | // // 模拟远端API调用,这里只返回了一个构造的对象 40 | // () -> Product.builder().id(12345L).name("颈椎/腰椎治疗仪").build()) 41 | // .thenAccept(product -> { 42 | // log.info("获取到远程API产品名称 " + product.getName()); 43 | // }); 44 | // voidCompletableFuture.get(); 45 | 46 | CompletableFuture stringCompletableFuture = CompletableFuture.supplyAsync(() -> { 47 | log.info("前序操作"); 48 | return "前需操作结果"; 49 | }).thenApplyAsync(result -> { 50 | log.info("后续操作"); 51 | return "后续操作结果"; 52 | }); 53 | 54 | stringCompletableFuture.get(); 55 | 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /mybatis-interceptor/interceptor/ResultInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.demo.interceptor; 2 | 3 | 4 | /** 5 | * Mybatis 返回值加解密拦截器 6 | * 7 | * @author fraser 8 | * @date 2019-05-15 14:40 9 | */ 10 | @Intercepts({ 11 | @Signature(type = ResultSetHandler.class, method = "handleResultSets", args = {Statement.class}) 12 | }) 13 | @ConditionalOnProperty(value = "domain.decrypt", havingValue = "true") 14 | @Component 15 | @Slf4j 16 | public class ResultInterceptor implements Interceptor { 17 | 18 | @Autowired 19 | private IEncryptDecrypt encryptDecrypt; 20 | 21 | @Override 22 | public Object intercept(Invocation invocation) throws Throwable { 23 | log.info("拦截器ResultInterceptor"); 24 | Object result = invocation.proceed(); 25 | if (Objects.isNull(result)) { 26 | return null; 27 | } 28 | 29 | if (result instanceof ArrayList) { 30 | ArrayList resultList = (ArrayList) result; 31 | if (CollectionUtils.isNotEmpty(resultList) && needToDecrypt(resultList.get(0))) { 32 | for (int i = 0; i < resultList.size(); i++) { 33 | encryptDecrypt.decrypt(resultList.get(i)); 34 | } 35 | } 36 | } else { 37 | if (needToDecrypt(result)) { 38 | encryptDecrypt.decrypt(result); 39 | } 40 | } 41 | return result; 42 | } 43 | 44 | public boolean needToDecrypt(Object object) { 45 | Class objectClass = object.getClass(); 46 | EncryptDecryptClass encryptDecryptClass = AnnotationUtils.findAnnotation(objectClass, EncryptDecryptClass.class); 47 | if (Objects.nonNull(encryptDecryptClass)) { 48 | return true; 49 | } 50 | return false; 51 | } 52 | 53 | @Override 54 | public Object plugin(Object target) { 55 | return Plugin.wrap(target, this); 56 | } 57 | 58 | @Override 59 | public void setProperties(Properties properties) { 60 | 61 | } 62 | } 63 | 64 | -------------------------------------------------------------------------------- /spring-bean-life-cycle/Book.java: -------------------------------------------------------------------------------- 1 | public class Book implements InitializingBean, DisposableBean, BeanFactoryAware, BeanNameAware, BeanClassLoaderAware { 2 | private String bookName; 3 | 4 | private Book() { 5 | System.out.println("---inside constructor---"); 6 | } 7 | 8 | @Override 9 | public void setBeanClassLoader(ClassLoader classLoader) { 10 | System.out.println("---BeanClassLoaderAware.setBeanClassLoader---"); 11 | } 12 | 13 | @Override 14 | public void setBeanName(String name) { 15 | System.out.println("---BeanNameAware.setBeanName---"); 16 | } 17 | 18 | public void myPostConstruct() { 19 | System.out.println("---init-method---"); 20 | } 21 | 22 | @PostConstruct 23 | public void springPostConstruct() { 24 | System.out.println("---@PostConstruct---"); 25 | } 26 | 27 | @Override 28 | public void setBeanFactory(BeanFactory beanFactory) throws BeansException { 29 | System.out.println("---BeanFactoryAware.setBeanFactory---"); 30 | } 31 | 32 | @Override 33 | public void afterPropertiesSet() throws Exception { 34 | System.out.println("---InitializingBean.afterPropertiesSet---"); 35 | } 36 | 37 | public String getBookName() { 38 | return bookName; 39 | } 40 | 41 | public void setBookName(String bookName) { 42 | this.bookName = bookName; 43 | System.out.println("setBookName: Book name has set."); 44 | } 45 | 46 | public void myPreDestroy() { 47 | System.out.println("---destroy-method---"); 48 | } 49 | 50 | @PreDestroy 51 | public void springPreDestroy() { 52 | System.out.println("---@PreDestroy---"); 53 | } 54 | 55 | @Override 56 | public void destroy() throws Exception { 57 | System.out.println("---DisposableBean.destroy---"); 58 | } 59 | 60 | @Override 61 | protected void finalize() { 62 | System.out.println("---inside finalize---"); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /spring-boot-unified-return/src/main/java/com/example/unifiedreturn/converter/LoginUserArgumentResolver.java: -------------------------------------------------------------------------------- 1 | package com.example.unifiedreturn.converter; 2 | 3 | import com.example.unifiedreturn.annotation.LoginUser; 4 | import com.example.unifiedreturn.vo.LoginUserVo; 5 | import com.example.unifiedreturn.vo.UserVo; 6 | import org.apache.logging.log4j.util.Strings; 7 | import org.springframework.core.MethodParameter; 8 | import org.springframework.web.bind.support.WebDataBinderFactory; 9 | import org.springframework.web.context.request.NativeWebRequest; 10 | import org.springframework.web.method.support.HandlerMethodArgumentResolver; 11 | import org.springframework.web.method.support.ModelAndViewContainer; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | 15 | /** 16 | * 登陆用户信息 resolver 17 | * 18 | * @author fraser 19 | * @date 2019/12/12 2:12 PM 20 | */ 21 | public class LoginUserArgumentResolver implements HandlerMethodArgumentResolver { 22 | @Override 23 | public boolean supportsParameter(MethodParameter methodParameter) { 24 | return methodParameter.hasParameterAnnotation(LoginUser.class); 25 | } 26 | 27 | @Override 28 | public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) throws Exception { 29 | 30 | HttpServletRequest request = (HttpServletRequest) nativeWebRequest.getNativeRequest(); 31 | 32 | LoginUserVo loginUserVo = new LoginUserVo(); 33 | 34 | String token = request.getHeader("token"); 35 | if (Strings.isNotBlank(token)){ 36 | //通常这里需要编写 token 解析逻辑,并将其放到 LoginUserVo 对象中 37 | //logic 38 | } 39 | 40 | //在此为了快速简洁的做演示说明,省略掉解析 token 部分,直接从 header 指定 key 中获取数据 41 | loginUserVo.setId(Long.valueOf(request.getHeader("userId"))); 42 | loginUserVo.setName(request.getHeader("userName")); 43 | return loginUserVo; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic05/CyclicBarrierExample.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic05; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.util.concurrent.*; 6 | 7 | /** 8 | * CyclicBarrierExample 9 | * 10 | * @author fraser 11 | * @date 2020/6/27 3:13 PM 12 | */ 13 | @Slf4j 14 | public class CyclicBarrierExample { 15 | 16 | private static Executor executor = Executors.newSingleThreadExecutor(); 17 | 18 | // 创建 CyclicBarrier 实例,计数器的值设置为2 19 | private static CyclicBarrier cyclicBarrier = new CyclicBarrier(2, () -> { 20 | executor.execute(() -> gather()); 21 | }); 22 | 23 | private static void gather() { 24 | try { 25 | Thread.sleep(2000); 26 | } catch (InterruptedException e) { 27 | e.printStackTrace(); 28 | } 29 | log.info("全部运行结束"); 30 | } 31 | 32 | public static void main(String[] args) { 33 | ExecutorService executorService = Executors.newFixedThreadPool(2); 34 | int breakCount = 0; 35 | 36 | executorService.submit(() -> { 37 | try { 38 | log.info(Thread.currentThread() + "第一回合"); 39 | Thread.sleep(1000); 40 | cyclicBarrier.await(); 41 | 42 | log.info(Thread.currentThread() + "第二回合"); 43 | Thread.sleep(2000); 44 | cyclicBarrier.await(); 45 | 46 | log.info(Thread.currentThread() + "第三回合"); 47 | } catch (InterruptedException | BrokenBarrierException e) { 48 | e.printStackTrace(); 49 | } 50 | }); 51 | 52 | executorService.submit(() -> { 53 | try { 54 | log.info(Thread.currentThread() + "第一回合"); 55 | Thread.sleep(2000); 56 | cyclicBarrier.await(); 57 | 58 | log.info(Thread.currentThread() + "第二回合"); 59 | Thread.sleep(1000); 60 | cyclicBarrier.await(); 61 | 62 | log.info(Thread.currentThread() + "第三回合"); 63 | } catch (InterruptedException | BrokenBarrierException e) { 64 | e.printStackTrace(); 65 | } 66 | }); 67 | 68 | executorService.shutdown(); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic08/ForkJoinDemo.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic08; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.concurrent.ForkJoinPool; 8 | import java.util.concurrent.ForkJoinWorkerThread; 9 | import java.util.concurrent.RecursiveTask; 10 | 11 | /** 12 | * ForkJoinDemo 13 | * 14 | * @author rgyb 15 | * @date 2020/12/29 9:56 PM 16 | */ 17 | @Slf4j 18 | public class ForkJoinDemo { 19 | public static void main(String[] args) { 20 | int n = 6; 21 | 22 | // 为了追踪子线程名称,需要重写 ForkJoinWorkerThreadFactory 的方法 23 | final ForkJoinPool.ForkJoinWorkerThreadFactory factory = pool -> { 24 | final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool); 25 | worker.setName("my-thread" + worker.getPoolIndex()); 26 | return worker; 27 | }; 28 | 29 | //创建分治任务线程池,可以追踪到线程名称 30 | ForkJoinPool forkJoinPool = new ForkJoinPool(4, factory, null, false); 31 | 32 | // 快速创建 ForkJoinPool 方法 33 | // ForkJoinPool forkJoinPool = new ForkJoinPool(4); 34 | // ForkJoinPool forkJoinPool = ForkJoinPool.commonPool(); 35 | 36 | //创建分治任务 37 | Fibonacci fibonacci = new Fibonacci(n); 38 | 39 | //调用 invoke 方法启动分治任务 40 | Integer result = forkJoinPool.invoke(fibonacci); 41 | log.info("Fibonacci {} 的结果是 {}", n, result); 42 | } 43 | } 44 | 45 | @Slf4j 46 | class Fibonacci extends RecursiveTask { 47 | final int n; 48 | Fibonacci(int n) { 49 | this.n = n; 50 | } 51 | 52 | @Override 53 | public Integer compute() { 54 | //和递归类似,定义可计算的最小单元 55 | if (n <= 1) { 56 | return n; 57 | } 58 | // 想查看子线程名称输出的可以打开下面注释 59 | log.info(Thread.currentThread().getName() + "#" + n); 60 | 61 | Fibonacci f1 = new Fibonacci(n - 1); 62 | // 拆分成子任务 63 | f1.fork(); 64 | Fibonacci f2 = new Fibonacci(n - 2); 65 | // f1.join 等待子任务执行结果 66 | return f2.compute() + f1.join(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /custom-starter/rgyb-spring-boot-autoconfigure/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | custom-starter 7 | top.dayarch.learnings 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | 1.0.0.RELEASE 13 | rgyb-spring-boot-autoconfigure 14 | jar 15 | 16 | 17 | 18 | 19 | org.apache.maven.plugins 20 | maven-compiler-plugin 21 | 22 | 8 23 | 8 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-autoconfigure 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-configuration-processor 38 | true 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-autoconfigure-processor 44 | true 45 | 46 | 47 | 48 | org.projectlombok 49 | lombok 50 | true 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /custom-starter/rgyb-spring-boot-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.9.RELEASE 9 | 10 | 11 | top.dayarch.learnings 12 | rgyb-spring-boot-sample 13 | 0.0.1-SNAPSHOT 14 | rgyb-spring-boot-sample 15 | Demo project for Spring Boot Starter 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | 28 | top.dayarch.learnings 29 | rgyb-spring-boot-starter 30 | 1.0.0.RELEASE 31 | 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-configuration-processor 37 | true 38 | 39 | 40 | org.projectlombok 41 | lombok 42 | true 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-test 47 | test 48 | 49 | 50 | 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-maven-plugin 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /spring-boot-unified-return/src/main/java/com/example/unifiedreturn/api/UserController.java: -------------------------------------------------------------------------------- 1 | package com.example.unifiedreturn.api; 2 | 3 | import com.example.unifiedreturn.exception.BusinessException; 4 | import com.example.unifiedreturn.service.UserService; 5 | import com.example.unifiedreturn.vo.UserVo; 6 | import com.google.common.collect.Lists; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.web.bind.annotation.*; 11 | 12 | import java.util.ArrayList; 13 | import java.util.Collections; 14 | import java.util.List; 15 | 16 | /** 17 | * 用户 18 | * 19 | * @author fraser 20 | * @date 2019-08-08 17:12 21 | */ 22 | @RestController 23 | @RequestMapping("/users") 24 | public class UserController { 25 | 26 | @Autowired 27 | private UserService userService; 28 | 29 | 30 | @GetMapping("") 31 | public List getUserList() { 32 | List userVoList = Lists.newArrayListWithCapacity(2); 33 | userVoList.add(UserVo.builder().id(1L).name("日拱一兵").age(18).build()); 34 | userVoList.add(UserVo.builder().id(2L).name("tan").age(19).build()); 35 | return userVoList; 36 | } 37 | 38 | 39 | 40 | /*@GetMapping("/{id}") 41 | public UserVo getUserById(@PathVariable Long id){ 42 | return UserVo.builder().id(1L).name("日拱一兵").age(18).build(); 43 | }*/ 44 | 45 | @GetMapping("/testResponseEntity") 46 | public ResponseEntity testResponseEntity() { 47 | return new ResponseEntity(UserVo.builder().id(1L).name("日拱一兵").age(18).build(), HttpStatus.OK); 48 | } 49 | 50 | /*@GetMapping("/{id}") 51 | public UserVo getUserById(@PathVariable Long id){ 52 | // throw new BusinessException("1001", "根据ID查询用户异常"); 53 | // return userService.getUserById(id); 54 | return UserVo.builder().id(1L).name("日拱一兵").age(18).build(); 55 | 56 | }*/ 57 | 58 | @GetMapping("/{id}") 59 | public String getUserById(@PathVariable Long id) { 60 | return "success"; 61 | // return userService.getUserById(id); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /configurationproperties/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.6.RELEASE 9 | 10 | 11 | com.example 12 | configurationproperties 13 | 0.0.1-SNAPSHOT 14 | configurationproperties 15 | configuration properties annotations 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-configuration-processor 30 | true 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 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic04/ReentrantReadWriteLockCache.java: -------------------------------------------------------------------------------- 1 | //package top.dayarch.topic04; 2 | // 3 | //import java.util.HashMap; 4 | //import java.util.Map; 5 | //import java.util.concurrent.locks.Lock; 6 | //import java.util.concurrent.locks.ReadWriteLock; 7 | //import java.util.concurrent.locks.ReentrantReadWriteLock; 8 | // 9 | ///** 10 | // * 读写锁示例一 11 | // * 12 | // * @author fraser 13 | // * @date 2020/6/21 12:51 PM 14 | // */ 15 | //public class ReentrantReadWriteLockCache { 16 | // 17 | // // 定义一个非线程安全的 HashMap 用于缓存对象 18 | // static Map map = new HashMap(); 19 | // // 创建读写锁对象 20 | // static ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); 21 | // // 构建读锁 22 | // static Lock rl = readWriteLock.readLock(); 23 | // // 构建写锁 24 | // static Lock wl = readWriteLock.writeLock(); 25 | // 26 | // public static final Object get(String key) { 27 | // Object obj = null; 28 | // rl.lock(); 29 | // try{ 30 | // obj = map.get(key); 31 | // }finally { 32 | // rl.unlock(); 33 | // } 34 | // 35 | // if (obj!= null) { 36 | // return obj; 37 | // } 38 | // 39 | // wl.lock(); 40 | // try{ 41 | // obj = map.get(key); 42 | // if (obj == null) { 43 | // obj = getDataFromDB(key); // 伪代码:getDataFromDB 44 | // map.put(key, obj); 45 | // } 46 | // }finally { 47 | // wl.unlock(); 48 | // } 49 | // return obj; 50 | // } 51 | // 52 | // public static final Object put(String key, Object value){ 53 | // wl.lock(); 54 | // try{ 55 | // return map.put(key, value); 56 | // }finally { 57 | // wl.unlock(); 58 | // } 59 | // } 60 | // 61 | // public static final Object getLockUpgrade(String key) { 62 | // Object obj = null; 63 | // rl.lock(); 64 | // try{ 65 | // obj = map.get(key); 66 | // if (obj == null){ 67 | // wl.lock(); 68 | // try{ 69 | // obj = map.get(key); 70 | // if (obj == null) { 71 | // obj = getDataFromDB(key); // 伪代码:getDataFromDB 72 | // map.put(key, obj); 73 | // } 74 | // }finally { 75 | // wl.unlock(); 76 | // } 77 | // } 78 | // }finally { 79 | // rl.unlock(); 80 | // } 81 | // 82 | // return obj; 83 | // } 84 | //} 85 | -------------------------------------------------------------------------------- /springboot-application-startup/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.2.RELEASE 9 | 10 | 11 | top.dayarch 12 | springboot-application-startup 13 | 0.0.1-SNAPSHOT 14 | springboot-application-startup 15 | Executing Code on Spring Boot Application Startup 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.junit.vintage 39 | junit-vintage-engine 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /mybatis-interceptor/interceptor/ParamInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.demo.interceptor; 2 | 3 | /** 4 | * Mybatis 参数拦截器 5 | * 6 | * @author fraser 7 | * @date 2019-05-15 12:50 8 | */ 9 | 10 | 11 | @Intercepts({ 12 | @Signature(type = ParameterHandler.class, method = "setParameters", args = PreparedStatement.class), 13 | }) 14 | @ConditionalOnProperty(value = "domain.encrypt", havingValue = "true") 15 | @Component 16 | @Slf4j 17 | public class ParamInterceptor implements Interceptor { 18 | 19 | @Autowired 20 | private IEncryptDecrypt encryptDecrypt; 21 | 22 | @Override 23 | public Object intercept(Invocation invocation) throws Throwable { 24 | 25 | log.info("拦截器ParamInterceptor"); 26 | //拦截 ParameterHandler 的 setParameters 方法 动态设置参数 27 | if (invocation.getTarget() instanceof ParameterHandler) { 28 | ParameterHandler parameterHandler = (ParameterHandler) invocation.getTarget(); 29 | PreparedStatement ps = (PreparedStatement) invocation.getArgs()[0]; 30 | 31 | // 反射获取 BoundSql 对象,此对象包含生成的sql和sql的参数map映射 32 | /*Field boundSqlField = parameterHandler.getClass().getDeclaredField("boundSql"); 33 | boundSqlField.setAccessible(true); 34 | BoundSql boundSql = (BoundSql) boundSqlField.get(parameterHandler);*/ 35 | 36 | // 反射获取 参数对像 37 | Field parameterField = 38 | parameterHandler.getClass().getDeclaredField("parameterObject"); 39 | parameterField.setAccessible(true); 40 | Object parameterObject = parameterField.get(parameterHandler); 41 | if (Objects.nonNull(parameterObject)) { 42 | Class parameterObjectClass = parameterObject.getClass(); 43 | EncryptDecryptClass encryptDecryptClass = AnnotationUtils.findAnnotation(parameterObjectClass, EncryptDecryptClass.class); 44 | if (Objects.nonNull(encryptDecryptClass)) { 45 | Field[] declaredFields = parameterObjectClass.getDeclaredFields(); 46 | 47 | final Object encrypt = encryptDecrypt.encrypt(declaredFields, parameterObject); 48 | } 49 | } 50 | } 51 | return invocation.proceed(); 52 | } 53 | 54 | @Override 55 | public Object plugin(Object o) { 56 | return Plugin.wrap(o, this); 57 | } 58 | 59 | @Override 60 | public void setProperties(Properties properties) { 61 | 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /dozer-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.5.RELEASE 9 | 10 | 11 | com.example.dozer 12 | dozer-demo 13 | 0.0.1-SNAPSHOT 14 | demo 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 6.2.0 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 | 35 | 36 | 37 | 38 | 39 | com.github.dozermapper 40 | dozer-spring-boot-starter 41 | ${dozer-version} 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-test 46 | test 47 | 48 | 49 | 50 | 51 | 52 | 53 | org.springframework.boot 54 | spring-boot-maven-plugin 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /spring-boot-unified-return/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.7.RELEASE 9 | 10 | 11 | com.example 12 | spring-boot-unified-return 13 | 0.0.1-SNAPSHOT 14 | unifiedreturn 15 | Demo for performing unified return in SpringBoot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | 28 | 29 | com.google.guava 30 | guava 31 | 28.0-jre 32 | 33 | 34 | 35 | com.alibaba 36 | fastjson 37 | 1.2.59 38 | 39 | 40 | 41 | 42 | org.projectlombok 43 | lombok 44 | true 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-test 49 | test 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /easy-excel-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.9.RELEASE 9 | 10 | 11 | com.example.easyexcel 12 | easy-excel-demo 13 | 0.0.1-SNAPSHOT 14 | demo 15 | Easyexcel usage 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 | com.alibaba 29 | easyexcel 30 | 2.0.5 31 | 32 | 33 | 34 | cn.hutool 35 | hutool-all 36 | 4.6.6 37 | 38 | 39 | 40 | com.alibaba 41 | fastjson 42 | 1.2.61 43 | 44 | 45 | 46 | 47 | org.projectlombok 48 | lombok 49 | true 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-starter-test 54 | test 55 | 56 | 57 | 58 | 59 | 60 | 61 | org.springframework.boot 62 | spring-boot-maven-plugin 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/myjuc/MyMutex.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.myjuc; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | import java.util.concurrent.locks.AbstractQueuedSynchronizer; 5 | import java.util.concurrent.locks.Condition; 6 | import java.util.concurrent.locks.Lock; 7 | import java.util.concurrent.locks.ReentrantLock; 8 | 9 | /** 10 | * 自定义互斥锁 11 | * 12 | * @author tanrgyb 13 | * @date 2020/5/23 9:33 PM 14 | */ 15 | public class MyMutex implements Lock { 16 | 17 | private ReentrantLock mylock = new ReentrantLock(true); 18 | 19 | public void test(){ 20 | mylock.tryLock(); 21 | } 22 | 23 | 24 | // 静态内部类-自定义同步器 25 | private static class MySync extends AbstractQueuedSynchronizer{ 26 | @Override 27 | protected boolean tryAcquire(int arg) { 28 | // 通过CAS保证原子性 29 | if (compareAndSetState(0, arg)){ 30 | // 我们实现的式互斥锁,所以标记获取到同步状态(更新state成功)的线程, 31 | // 主要为了判断是否可重入(一会会说明) 32 | setExclusiveOwnerThread(Thread.currentThread()); 33 | //获取同步状态成功,返回 true 34 | return true; 35 | } 36 | // 获取同步状态失败,返回 false 37 | return false; 38 | } 39 | 40 | @Override 41 | protected boolean tryRelease(int arg) { 42 | // 未曾拥有锁却让释放,会抛出IMSE 43 | if (getState() == 0){ 44 | throw new IllegalMonitorStateException(); 45 | } 46 | // 清空排它标记 47 | setExclusiveOwnerThread(null); 48 | // 设置同步状态为0,表示释放锁 49 | setState(0); 50 | return true; 51 | } 52 | 53 | // 是否排它式持有 54 | @Override 55 | protected boolean isHeldExclusively() { 56 | return getState() == 1; 57 | } 58 | 59 | // 后续会用到,主要用于等待/通知机制,每个condition都有一个与之对应的条件等待队列, 60 | // 不知道你是否还记得锁模型的内容 61 | Condition newCondition() { 62 | return new ConditionObject(); 63 | } 64 | } 65 | 66 | private final MySync sync = new MySync(); 67 | 68 | 69 | @Override 70 | public void lock() { 71 | // 阻塞式的获取锁,调用同步器模版方法独占式,获取同步状态 72 | sync.acquire(1); 73 | } 74 | 75 | @Override 76 | public void lockInterruptibly() throws InterruptedException { 77 | // 调用同步器模版方法可中断式获取同步状态 78 | sync.acquireInterruptibly(1); 79 | } 80 | 81 | @Override 82 | public boolean tryLock() { 83 | // 调用自己重写的方法,非阻塞式的获取同步状态 84 | return sync.tryAcquire(1); 85 | } 86 | 87 | @Override 88 | public boolean tryLock(long time, TimeUnit unit) throws InterruptedException { 89 | // 调用同步器模版方法,可响应中断和超时时间限制 90 | return sync.tryAcquireNanos(1, unit.toNanos(time)); 91 | } 92 | 93 | @Override 94 | public void unlock() { 95 | // 释放锁 96 | sync.release(1); 97 | } 98 | 99 | @Override 100 | public Condition newCondition() { 101 | // 使用自定义的条件 102 | return sync.newCondition(); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/topic03/ThreadStateTest.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.topic03; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.util.concurrent.locks.Lock; 6 | import java.util.concurrent.locks.ReentrantLock; 7 | 8 | /** 9 | * 线程状态测试 10 | * 11 | * @author fraser 12 | * @date 2020/3/22 9:15 PM 13 | */ 14 | @Slf4j 15 | public class ThreadStateTest { 16 | 17 | public static void main(String[] args) throws InterruptedException { 18 | TestLock testLock = new TestLock(); 19 | 20 | Thread thread2 = new Thread(() -> { 21 | testLock.myTestLock(); 22 | }, "thread2"); 23 | 24 | Thread thread1 = new Thread(() -> { 25 | testLock.myTestLock(); 26 | }, "thread1"); 27 | 28 | thread1.start(); 29 | Thread.sleep(1000); 30 | 31 | thread2.start(); 32 | Thread.sleep(1000); 33 | 34 | System.out.println("****" + (thread2.getState())); 35 | 36 | Thread.sleep(20000); 37 | 38 | 39 | // Thread thread = new Thread(() -> {}); 40 | // thread.start(); 41 | //// Thread.sleep(1000); 42 | // System.out.println(thread.getState()); 43 | 44 | // Thread t1 = new Thread(new DemoThreadB()); 45 | // Thread t2 = new Thread(new DemoThreadB()); 46 | // 47 | // t1.start(); 48 | // t2.start(); 49 | // 50 | // Thread.sleep(1000); 51 | // 52 | // System.out.println((t2.getState())); 53 | // System.exit(0); 54 | // Thread main = Thread.currentThread(); 55 | // 56 | // Thread thread2 = new Thread(() -> { 57 | // try { 58 | // Thread.sleep(100000); 59 | // } catch (InterruptedException e) { 60 | // e.printStackTrace(); 61 | // } 62 | // System.out.println(main.getState()); 63 | // }); 64 | // thread2.start(); 65 | // thread2.join(); 66 | 67 | // Thread thread3 = new Thread(() -> { 68 | // try { 69 | // Thread.sleep(3000); 70 | // } catch (InterruptedException e) { 71 | // Thread.currentThread().interrupt(); 72 | // e.printStackTrace(); 73 | // } 74 | // }); 75 | // thread3.start(); 76 | // 77 | // Thread.sleep(1000); 78 | // System.out.println(thread3.getState()); 79 | } 80 | 81 | 82 | } 83 | 84 | @Slf4j 85 | class TestLock{ 86 | private final Lock lock = new ReentrantLock(); 87 | 88 | public void myTestLock(){ 89 | lock.lock(); 90 | try{ 91 | Thread.sleep(10000); 92 | log.info("testLock status"); 93 | } catch (InterruptedException e) { 94 | log.error(e.getMessage()); 95 | } finally { 96 | lock.unlock(); 97 | } 98 | } 99 | } 100 | 101 | //class DemoThreadB implements Runnable { 102 | // @Override 103 | // public void run() { 104 | // commonResource(); 105 | // } 106 | // 107 | // public static synchronized void commonResource() { 108 | // while(true) { 109 | // 110 | // } 111 | // } 112 | //} 113 | -------------------------------------------------------------------------------- /configurationproperties/src/main/java/com/example/configurationproperties/properties/MailModuleProperties.java: -------------------------------------------------------------------------------- 1 | package com.example.configurationproperties.properties; 2 | 3 | import com.example.configurationproperties.entity.Weight; 4 | import lombok.Data; 5 | import org.springframework.boot.context.properties.ConfigurationProperties; 6 | import org.springframework.boot.context.properties.DeprecatedConfigurationProperty; 7 | import org.springframework.boot.convert.DataSizeUnit; 8 | import org.springframework.boot.convert.DurationUnit; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.util.unit.DataSize; 11 | import org.springframework.util.unit.DataUnit; 12 | import org.springframework.validation.annotation.Validated; 13 | 14 | import javax.validation.constraints.NotEmpty; 15 | import javax.validation.constraints.NotNull; 16 | import java.time.Duration; 17 | import java.time.temporal.ChronoUnit; 18 | import java.util.List; 19 | 20 | /** 21 | * @author fraser 22 | * @date 2019-07-23 19:40 23 | */ 24 | //@Data 25 | //@Validated 26 | @Component 27 | @ConfigurationProperties(prefix = "myapp.mail") 28 | public class MailModuleProperties { 29 | 30 | @NotNull 31 | private Boolean enabled; 32 | 33 | @NotEmpty 34 | private String defaultSubject; 35 | 36 | private List smtpServers; 37 | 38 | @DurationUnit(ChronoUnit.DAYS) 39 | private Duration pauseBetweenMails = Duration.ofSeconds(30); 40 | 41 | 42 | @DataSizeUnit(DataUnit.MEGABYTES) 43 | private DataSize maxAttachmentSize = DataSize.ofMegabytes(2); 44 | 45 | private Weight maxAttachmentWeight; 46 | 47 | @DeprecatedConfigurationProperty(reason = "change name", replacement = "none") 48 | public String getDefaultSubject() { 49 | return defaultSubject; 50 | } 51 | 52 | public Boolean getEnabled() { 53 | return enabled; 54 | } 55 | 56 | public void setEnabled(Boolean enabled) { 57 | this.enabled = enabled; 58 | } 59 | 60 | public void setDefaultSubject(String defaultSubject) { 61 | this.defaultSubject = defaultSubject; 62 | } 63 | 64 | public List getSmtpServers() { 65 | return smtpServers; 66 | } 67 | 68 | public void setSmtpServers(List smtpServers) { 69 | this.smtpServers = smtpServers; 70 | } 71 | 72 | public Duration getPauseBetweenMails() { 73 | return pauseBetweenMails; 74 | } 75 | 76 | public void setPauseBetweenMails(Duration pauseBetweenMails) { 77 | this.pauseBetweenMails = pauseBetweenMails; 78 | } 79 | 80 | public DataSize getMaxAttachmentSize() { 81 | return maxAttachmentSize; 82 | } 83 | 84 | public void setMaxAttachmentSize(DataSize maxAttachmentSize) { 85 | this.maxAttachmentSize = maxAttachmentSize; 86 | } 87 | 88 | public Weight getMaxAttachmentWeight() { 89 | return maxAttachmentWeight; 90 | } 91 | 92 | public void setMaxAttachmentWeight(Weight maxAttachmentWeight) { 93 | this.maxAttachmentWeight = maxAttachmentWeight; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /easy-excel-demo/src/main/java/com/example/easyexcel/demo/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.example.easyexcel.demo.controller; 2 | 3 | import com.alibaba.excel.EasyExcel; 4 | import com.alibaba.excel.context.AnalysisContext; 5 | import com.alibaba.excel.event.AnalysisEventListener; 6 | import com.alibaba.fastjson.JSON; 7 | import com.example.easyexcel.demo.entity.User; 8 | import com.example.easyexcel.demo.listener.UserExcelListener; 9 | import com.example.easyexcel.demo.service.IUser; 10 | import com.example.easyexcel.demo.utils.ExcelDemoUtils; 11 | import lombok.extern.slf4j.Slf4j; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.web.bind.annotation.PostMapping; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RestController; 16 | import org.springframework.web.multipart.MultipartFile; 17 | 18 | import java.io.IOException; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | import java.util.function.Consumer; 22 | 23 | /** 24 | * 用户人员API 25 | * 26 | * @author fraser 27 | * @date 2019/10/6 9:40 AM 28 | */ 29 | @RestController 30 | @RequestMapping("/users") 31 | @Slf4j 32 | public class UserController { 33 | 34 | @Autowired 35 | private IUser iUser; 36 | 37 | @PostMapping("/upload") 38 | public String upload(MultipartFile file) throws IOException { 39 | EasyExcel.read(file.getInputStream(), User.class, new UserExcelListener()).sheet().doRead(); 40 | return "success"; 41 | } 42 | 43 | @PostMapping("/uploadWithAnonyInnerClass") 44 | public String uploadWithAnonyInnerClass(MultipartFile file) throws IOException { 45 | EasyExcel.read(file.getInputStream(), User.class, new AnalysisEventListener(){ 46 | /** 47 | * 批处理阈值 48 | */ 49 | private static final int BATCH_COUNT = 2; 50 | List list = new ArrayList(); 51 | 52 | @Override 53 | public void invoke(User user, AnalysisContext analysisContext) { 54 | log.info("解析到一条数据:{}", JSON.toJSONString(user)); 55 | list.add(user); 56 | if (list.size() >= BATCH_COUNT) { 57 | saveData(); 58 | list.clear(); 59 | } 60 | } 61 | 62 | @Override 63 | public void doAfterAllAnalysed(AnalysisContext analysisContext) { 64 | saveData(); 65 | log.info("所有数据解析完成!"); 66 | } 67 | 68 | private void saveData(){ 69 | iUser.saveData(list); 70 | } 71 | }).sheet().doRead(); 72 | return "success"; 73 | } 74 | 75 | @PostMapping("/uploadWithConstructor") 76 | public String uploadWithConstructor(MultipartFile file) throws IOException { 77 | EasyExcel.read(file.getInputStream(), User.class, new UserExcelListener(iUser)).sheet().doRead(); 78 | return "success"; 79 | } 80 | 81 | @PostMapping("/uploadWithLambda") 82 | public String uploadWithLambda(MultipartFile file) throws IOException { 83 | AnalysisEventListener userAnalysisEventListener = ExcelDemoUtils.getListener(this.batchInsert(), 2); 84 | EasyExcel.read(file.getInputStream(), User.class, userAnalysisEventListener).sheet().doRead(); 85 | return "success"; 86 | } 87 | 88 | 89 | private Consumer> batchInsert(){ 90 | return users -> iUser.saveData(users); 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /concurrency/src/main/java/top/dayarch/memoryleak/MemLeakTest.java: -------------------------------------------------------------------------------- 1 | package top.dayarch.memoryleak; 2 | 3 | import lombok.Data; 4 | import lombok.EqualsAndHashCode; 5 | import lombok.Getter; 6 | import lombok.Setter; 7 | 8 | import java.util.HashMap; 9 | import java.util.HashSet; 10 | import java.util.Map; 11 | import java.util.Set; 12 | 13 | /** 14 | * 内存溢出测试 15 | * 16 | * @author fraser 17 | * @date 2020/7/26 11:49 AM 18 | */ 19 | public class MemLeakTest { 20 | 21 | public static void main(String[] args) throws InterruptedException { 22 | Set set = new HashSet(); 23 | 24 | Person p1 = new Person("zhangsan", 1); 25 | Person p2 = new Person("lisi", 2); 26 | Person p3 = new Person("wanger", 3); 27 | 28 | set.add(p1); 29 | set.add(p2); 30 | set.add(p3); 31 | 32 | System.out.println(set.size()); // 运行结果:3 33 | p3.setName("wangermao"); 34 | set.remove(p3); 35 | System.out.println(set.size()); // 运行结果:3 36 | set.add(p3); 37 | System.out.println(set.size()); // 运行结果:4 38 | set.forEach(person -> { 39 | System.out.println(person.toString() + "|" + person.hashCode()); 40 | }); 41 | 42 | 43 | 44 | // map.put(p1, "zhangsan"); 45 | // map.put(p2, "zhangsan"); 46 | // map.put(p3, "zhangsan"); 47 | 48 | // System.out.println(map.entrySet().size()); // 运行结果:3 49 | // 50 | //// Person p2 = new Person("lisi", 2); 51 | //// Person p3 = new Person("wanger", 3); 52 | // Set set = new HashSet(); 53 | 54 | // 55 | // System.out.println(set.size()); 56 | // p3.setName("wangermazi"); 57 | // set.remove(p3); 58 | // System.out.println(set.size()); 59 | // set.add(p3); 60 | // System.out.println(set.size()); 61 | // 62 | // for (Person person : set) 63 | // { 64 | // System.out.println(person); 65 | // } 66 | // System.out.println(p1.hashCode()); 67 | // System.out.println(System.identityHashCode(p1)); 68 | // System.out.println(System.identityHashCode(p1)); 69 | //// Person p3 = new Person("zhangsan"); 70 | //// Person p2 = new Person("lisi"); 71 | //// Person p3 = new Person("zhangsan"); 72 | //// map.put(p1, "hello"); 73 | //// map.put(p2, "world"); 74 | //// map.put(p3, "zhangsan"); 75 | // System.out.println(map.get(p1)); 76 | // 77 | //// p1.setName("zhangsanfeng"); 78 | //// System.out.println(map.get(p1)); 79 | //// System.out.println(map.entrySet().size()); 80 | //// System.out.println(map.get(new Person("zhangsan"))); 81 | //// 82 | // 83 | // 84 | //// System.out.println(p1.equals(p2)); 85 | //// 86 | //// map.put(p1, "zhangsan"); 87 | //// map.put(p2, "lisi"); 88 | //// 89 | //// System.out.println(p1.hashCode()); 90 | //// System.out.println(p3.hashCode()); 91 | //// System.out.println(map.get(p1)); 92 | //// p1.setName("zhangsanfeng"); 93 | //// System.out.println(p1.hashCode()); 94 | //// System.out.println(map.get(p1)); 95 | //// p1.setName("zhangsan"); 96 | //// System.out.println(map.get(p1)); 97 | //// 98 | //// System.out.println(new Person("zhangsan").hashCode()); 99 | //// System.out.println(new Person("zhangsan").hashCode()); 100 | //// System.out.println(map.get(new Person("zhangsan"))); 101 | 102 | } 103 | 104 | // @EqualsAndHashCode 105 | 106 | } 107 | 108 | @Data 109 | //@Getter 110 | //@Setter 111 | class Person { 112 | private String name; 113 | private Integer id; 114 | 115 | public Person(String name, Integer id){ 116 | this.name = name; 117 | this.id = id; 118 | } 119 | } -------------------------------------------------------------------------------- /jdk12-demo/src/SnowFlakeShortUrl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author fraser 3 | * @date 2020/2/18 8:47 AM 4 | */ 5 | 6 | /** 7 | * Twitter的SnowFlake算法,使用SnowFlake算法生成一个整数,然后转化为62进制变成一个短地址URL 8 | * 9 | * https://github.com/beyondfengyu/SnowFlake 10 | */ 11 | public class SnowFlakeShortUrl { 12 | 13 | /** 14 | * 起始的时间戳 15 | */ 16 | private final static long START_TIMESTAMP = 1480166465631L; 17 | 18 | /** 19 | * 每一部分占用的位数 20 | */ 21 | private final static long SEQUENCE_BIT = 12; //序列号占用的位数 22 | private final static long MACHINE_BIT = 5; //机器标识占用的位数 23 | private final static long DATA_CENTER_BIT = 5; //数据中心占用的位数 24 | 25 | /** 26 | * 每一部分的最大值 27 | */ 28 | private final static long MAX_SEQUENCE = -1L ^ (-1L << SEQUENCE_BIT); 29 | private final static long MAX_MACHINE_NUM = -1L ^ (-1L << MACHINE_BIT); 30 | private final static long MAX_DATA_CENTER_NUM = -1L ^ (-1L << DATA_CENTER_BIT); 31 | 32 | /** 33 | * 每一部分向左的位移 34 | */ 35 | private final static long MACHINE_LEFT = SEQUENCE_BIT; 36 | private final static long DATA_CENTER_LEFT = SEQUENCE_BIT + MACHINE_BIT; 37 | private final static long TIMESTAMP_LEFT = DATA_CENTER_LEFT + DATA_CENTER_BIT; 38 | 39 | private long dataCenterId; //数据中心 40 | private long machineId; //机器标识 41 | private long sequence = 0L; //序列号 42 | private long lastTimeStamp = -1L; //上一次时间戳 43 | 44 | private long getNextMill() { 45 | long mill = getNewTimeStamp(); 46 | while (mill <= lastTimeStamp) { 47 | mill = getNewTimeStamp(); 48 | } 49 | return mill; 50 | } 51 | 52 | private long getNewTimeStamp() { 53 | return System.currentTimeMillis(); 54 | } 55 | 56 | /** 57 | * 根据指定的数据中心ID和机器标志ID生成指定的序列号 58 | * 59 | * @param dataCenterId 数据中心ID 60 | * @param machineId 机器标志ID 61 | */ 62 | public SnowFlakeShortUrl(long dataCenterId, long machineId) { 63 | if (dataCenterId > MAX_DATA_CENTER_NUM || dataCenterId < 0) { 64 | throw new IllegalArgumentException("DtaCenterId can't be greater than MAX_DATA_CENTER_NUM or less than 0!"); 65 | } 66 | if (machineId > MAX_MACHINE_NUM || machineId < 0) { 67 | throw new IllegalArgumentException("MachineId can't be greater than MAX_MACHINE_NUM or less than 0!"); 68 | } 69 | this.dataCenterId = dataCenterId; 70 | this.machineId = machineId; 71 | } 72 | 73 | /** 74 | * 产生下一个ID 75 | * 76 | * @return 77 | */ 78 | public synchronized long nextId() { 79 | long currTimeStamp = getNewTimeStamp(); 80 | if (currTimeStamp < lastTimeStamp) { 81 | throw new RuntimeException("Clock moved backwards. Refusing to generate id"); 82 | } 83 | 84 | if (currTimeStamp == lastTimeStamp) { 85 | //相同毫秒内,序列号自增 86 | sequence = (sequence + 1) & MAX_SEQUENCE; 87 | //同一毫秒的序列数已经达到最大 88 | if (sequence == 0L) { 89 | currTimeStamp = getNextMill(); 90 | } 91 | } else { 92 | //不同毫秒内,序列号置为0 93 | sequence = 0L; 94 | } 95 | 96 | lastTimeStamp = currTimeStamp; 97 | 98 | return (currTimeStamp - START_TIMESTAMP) << TIMESTAMP_LEFT //时间戳部分 99 | | dataCenterId << DATA_CENTER_LEFT //数据中心部分 100 | | machineId << MACHINE_LEFT //机器标识部分 101 | | sequence; //序列号部分 102 | } 103 | 104 | public static void main(String[] args) { 105 | SnowFlakeShortUrl snowFlake = new SnowFlakeShortUrl(2, 3); 106 | 107 | for (int i = 0; i < (1 << 4); i++) { 108 | //10进制 109 | System.out.println(snowFlake.nextId()); 110 | } 111 | } 112 | } 113 | 114 | -------------------------------------------------------------------------------- /spring-boot-unified-return/src/main/java/com/example/unifiedreturn/config/UnifiedReturnConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.unifiedreturn.config; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.example.unifiedreturn.converter.LoginUserArgumentResolver; 5 | import com.example.unifiedreturn.converter.StringToLocalDateTimeConverter; 6 | import com.example.unifiedreturn.exception.BusinessException; 7 | import com.example.unifiedreturn.exception.TestBean; 8 | import com.example.unifiedreturn.vo.CommonResult; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.core.MethodParameter; 12 | import org.springframework.format.FormatterRegistry; 13 | import org.springframework.http.MediaType; 14 | import org.springframework.http.converter.HttpMessageConverter; 15 | import org.springframework.http.server.ServerHttpRequest; 16 | import org.springframework.http.server.ServerHttpResponse; 17 | import org.springframework.web.bind.annotation.ExceptionHandler; 18 | import org.springframework.web.bind.annotation.RestControllerAdvice; 19 | import org.springframework.web.method.support.HandlerMethodArgumentResolver; 20 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 21 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 22 | import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * 统一返回配置 28 | * 29 | * @author fraser 30 | * @date 2019-08-08 17:07 31 | */ 32 | @EnableWebMvc 33 | @Configuration 34 | public class UnifiedReturnConfig implements WebMvcConfigurer { 35 | 36 | /** 37 | * 配置 RESTful API 统一参数返回 38 | */ 39 | @RestControllerAdvice("com.example.unifiedreturn.api") 40 | static class CommonResultResponseAdvice implements ResponseBodyAdvice { 41 | @Override 42 | public boolean supports(MethodParameter methodParameter, Class> aClass) { 43 | return true; 44 | } 45 | 46 | @Override 47 | public Object beforeBodyWrite(Object body, MethodParameter methodParameter, 48 | MediaType mediaType, 49 | Class> aClass, 50 | ServerHttpRequest serverHttpRequest, 51 | ServerHttpResponse serverHttpResponse) { 52 | //应对特殊case,返回类型是String不做处理会导致StringMessageConverter转换异常,将其封装并转换为json对象 53 | if (body instanceof String) { 54 | String stringBody = (String) body; 55 | CommonResult objectCommonResult = new CommonResult<>(1, stringBody); 56 | return JSON.toJSONString(objectCommonResult); 57 | } 58 | 59 | if (body instanceof CommonResult) { 60 | return body; 61 | } 62 | 63 | return new CommonResult(body); 64 | } 65 | } 66 | 67 | 68 | @RestControllerAdvice("com.example.unifiedreturn.api") 69 | static class UnifiedExceptionHandler { 70 | 71 | @ExceptionHandler(BusinessException.class) 72 | public CommonResult handleBusinessException(BusinessException be) { 73 | return CommonResult.errorResult(be.getErrorCode(), be.getErrorMsg()); 74 | } 75 | } 76 | 77 | // @Bean 78 | public TestBean testBean() { 79 | return new TestBean(); 80 | } 81 | 82 | 83 | @Override 84 | public void addFormatters(FormatterRegistry registry) { 85 | registry.addConverter(new StringToLocalDateTimeConverter()); 86 | } 87 | 88 | @Override 89 | public void addArgumentResolvers(List resolvers) { 90 | resolvers.add(new LoginUserArgumentResolver()); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /mybatis-interceptor/interceptor/EncryptDecryptUtils.java: -------------------------------------------------------------------------------- 1 | package com.demo.util; 2 | 3 | /** 4 | * Domain数据加密工具类 5 | * 6 | * @author fraser 7 | * @date 2019-05-15 11:06 8 | */ 9 | public class EncryptDecryptUtils { 10 | 11 | 12 | /** 13 | * 多field加密方法 14 | * 15 | * @param declaredFields 16 | * @param parameterObject 17 | * @param 18 | * @return 19 | * @throws IllegalAccessException 20 | */ 21 | public static T encrypt(Field[] declaredFields, T parameterObject) throws IllegalAccessException { 22 | for (Field field : declaredFields) { 23 | EncryptDecryptField annotation = field.getAnnotation(EncryptDecryptField.class); 24 | if (Objects.isNull(annotation)) { 25 | continue; 26 | } 27 | encrypt(field, parameterObject); 28 | } 29 | return parameterObject; 30 | } 31 | 32 | 33 | /** 34 | * 单个field加密方法 35 | * 36 | * @param field 37 | * @param parameterObject 38 | * @param 39 | * @return 40 | * @throws IllegalAccessException 41 | */ 42 | public static T encrypt(Field field, T parameterObject) throws IllegalAccessException { 43 | field.setAccessible(true); 44 | Object object = field.get(parameterObject); 45 | if (object instanceof BigDecimal) { 46 | BigDecimal value = (BigDecimal) object; 47 | long longValue = value.movePointRight(4).subtract(BigDecimal.valueOf(Integer.MAX_VALUE >> 3)).longValue(); 48 | field.set(parameterObject, BigDecimal.valueOf(longValue)); 49 | } else if (object instanceof Integer) { 50 | //TODO 定制Integer类型的加密算法 51 | } else if (object instanceof Long) { 52 | //TODO 定制Long类型的加密算法 53 | } else if (object instanceof String) { 54 | String value = (String) object; 55 | field.set(parameterObject, value + "000"); 56 | //TODO 定制String类型的加密算法 57 | 58 | } 59 | return parameterObject; 60 | } 61 | 62 | /** 63 | * 解密方法 64 | * 65 | * @param result 66 | * @param 67 | * @return 68 | * @throws IllegalAccessException 69 | */ 70 | public static T decrypt(T result) throws IllegalAccessException { 71 | Class parameterObjectClass = result.getClass(); 72 | Field[] declaredFields = parameterObjectClass.getDeclaredFields(); 73 | decrypt(declaredFields, result); 74 | return result; 75 | } 76 | 77 | /** 78 | * 多个field解密方法 79 | * 80 | * @param declaredFields 81 | * @param result 82 | * @throws IllegalAccessException 83 | */ 84 | public static void decrypt(Field[] declaredFields, Object result) throws IllegalAccessException { 85 | for (Field field : declaredFields) { 86 | EncryptDecryptField annotation = field.getAnnotation(EncryptDecryptField.class); 87 | if (Objects.isNull(annotation)) { 88 | continue; 89 | } 90 | decrypt(field, result); 91 | } 92 | } 93 | 94 | /** 95 | * 单个field解密方法 96 | * 97 | * @param field 98 | * @param result 99 | * @throws IllegalAccessException 100 | */ 101 | public static void decrypt(Field field, Object result) throws IllegalAccessException { 102 | field.setAccessible(true); 103 | Object object = field.get(result); 104 | if (object instanceof BigDecimal) { 105 | BigDecimal value = (BigDecimal) object; 106 | double doubleValue = value.add(BigDecimal.valueOf(Integer.MAX_VALUE >> 3)).movePointLeft(4).doubleValue(); 107 | field.set(result, BigDecimal.valueOf(doubleValue)); 108 | } else if (object instanceof Integer) { 109 | //TODO 定制Integer类型的加密算法 110 | } else if (object instanceof Long) { 111 | //TODO 定制Long类型的加密算法 112 | } else if (object instanceof String) { 113 | //TODO 定制String类型的加密算法 114 | String value = (String) object; 115 | field.set(result, value.replace("000", "")); 116 | 117 | } 118 | } 119 | 120 | 121 | } 122 | -------------------------------------------------------------------------------- /concurrency/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 4.0.0 6 | 7 | top.dayarch 8 | concurrency 9 | 1.0-SNAPSHOT 10 | 11 | concurrency 12 | 13 | http://www.example.com 14 | 15 | 16 | UTF-8 17 | 1.7 18 | 1.7 19 | 20 | 21 | 22 | 23 | junit 24 | junit 25 | 4.11 26 | test 27 | 28 | 29 | 30 | 31 | org.projectlombok 32 | lombok 33 | 1.18.12 34 | provided 35 | 36 | 37 | 38 | 39 | ch.qos.logback 40 | logback-classic 41 | 1.2.3 42 | compile 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | maven-clean-plugin 55 | 3.1.0 56 | 57 | 58 | 59 | maven-resources-plugin 60 | 3.0.2 61 | 62 | 63 | maven-compiler-plugin 64 | 3.8.0 65 | 66 | 67 | maven-surefire-plugin 68 | 2.22.1 69 | 70 | 71 | maven-jar-plugin 72 | 3.0.2 73 | 74 | 75 | maven-install-plugin 76 | 2.5.2 77 | 78 | 79 | maven-deploy-plugin 80 | 2.8.2 81 | 82 | 83 | 84 | maven-site-plugin 85 | 3.7.1 86 | 87 | 88 | maven-project-info-reports-plugin 89 | 3.0.0 90 | 91 | 92 | 93 | 94 | 95 | org.apache.maven.plugins 96 | maven-compiler-plugin 97 | 98 | 8 99 | 8 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /dozer-demo/src/main/java/com/example/dozer/demo/config/DozerConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.dozer.demo.config; 2 | 3 | import com.example.dozer.demo.converter.ScoreConverter; 4 | import com.example.dozer.demo.domain.AddressDomain; 5 | import com.example.dozer.demo.domain.StudentDomain; 6 | import com.example.dozer.demo.listener.StudentListener; 7 | import com.example.dozer.demo.vo.AddressVo; 8 | import com.example.dozer.demo.vo.StudentVo; 9 | import org.dozer.DozerBeanMapperBuilder; 10 | import org.dozer.DozerEventListener; 11 | import org.dozer.Mapper; 12 | import org.dozer.fieldmap.DozerField; 13 | import org.dozer.loader.DozerBuilder; 14 | import org.dozer.loader.api.BeanMappingBuilder; 15 | import org.dozer.loader.api.FieldsMappingOption; 16 | import org.dozer.loader.api.FieldsMappingOptions; 17 | import org.dozer.loader.api.TypeMappingOptions; 18 | import org.springframework.context.annotation.Bean; 19 | import org.springframework.context.annotation.Configuration; 20 | 21 | import java.io.BufferedReader; 22 | 23 | import static org.dozer.loader.api.FieldsMappingOptions.customConverter; 24 | 25 | /** 26 | * Dozer 配置类 27 | * 28 | * @author fraser 29 | * @date 2019-05-27 11:36 30 | */ 31 | @Configuration 32 | public class DozerConfig { 33 | 34 | @Bean 35 | public Mapper dozerMapper() { 36 | Mapper mapper = DozerBeanMapperBuilder.create() 37 | // 1.这里我们可指定 dozer mapping 的配置文件,可添加多个 xml 文件,用逗号隔开即可 38 | // 2. 也可以通过 YAML 的方式配置, 39 | .withMappingFiles("dozerBeanMapping.xml") 40 | .withMappingBuilder(beanMappingBuilder()) 41 | .withEventListener(studentListener()) 42 | .build(); 43 | return mapper; 44 | } 45 | 46 | @Bean 47 | public DozerEventListener studentListener() { 48 | return new StudentListener(); 49 | } 50 | 51 | 52 | @Bean 53 | public BeanMappingBuilder beanMappingBuilder() { 54 | return new BeanMappingBuilder() { 55 | @Override 56 | protected void configure() { 57 | // //地址映射 58 | mapping(AddressDomain.class, AddressVo.class/*, TypeMappingOptions.mapId("addrAllProperties"),TypeMappingOptions.dateFormat("yyyy-MM-dd")*/) 59 | .fields("detail", "detailAddr"); 60 | // 61 | // //测试所有properties,为不同名的 property 手动配置映射关系 62 | // mapping(StudentDomain.class, StudentVo.class/*, TypeMappingOptions.mapId("userAllProperties")*/) 63 | // .fields("address", "addr"); 64 | // 65 | //测试所有properties,为不同名的 property 手动配置映射关系,排除 mobile 字段 66 | // mapping(StudentDomain.class, StudentVo.class, TypeMappingOptions.mapId("userExcludeMobile")) 67 | // .exclude("mobile") 68 | // .fields("address", "addr"); 69 | // 70 | // //测试所有properties,为不同名的 property 手动配置映射关系,排除 mobile 字段,空字段不显示 71 | // mapping(StudentDomain.class, StudentVo.class, TypeMappingOptions.mapId("userNonNullAndExcludeMobile"), TypeMappingOptions.mapEmptyString(true)) 72 | // .exclude("mobile") 73 | // .fields("address", "addr"); 74 | // 75 | // //测试指定properties 76 | // mapping(StudentDomain.class, StudentVo.class, TypeMappingOptions.mapId("userWildcardFalse"), TypeMappingOptions.wildcard(false)) 77 | // .fields("address", "addr"); 78 | // 79 | // //测试指定properties并指定mapid 80 | // mapping(StudentDomain.class, StudentVo.class, TypeMappingOptions.mapId("userFieldUseSpecifiedMapId"), TypeMappingOptions.wildcard(false)) 81 | // .fields("address", "addr", FieldsMappingOptions.useMapId("addrAllProperties")); 82 | // 83 | //关闭隐式匹配 84 | // mapping(StudentDomain.class, StudentVo.class, TypeMappingOptions.wildcard(false)) 85 | // .fields("address", "addr"); 86 | // 87 | // //测试mapping oneway 88 | // mapping(StudentDomain.class, StudentVo.class, TypeMappingOptions.mapId("userOneWay"), TypeMappingOptions.oneWay()) 89 | // .fields("address", "addr", FieldsMappingOptions.useMapId("addrAllProperties")); 90 | // 91 | // //测试field oneway 92 | // mapping(StudentDomain.class, StudentVo.class, TypeMappingOptions.mapId("userFieldOneWay")) 93 | // .fields("age", "age", FieldsMappingOptions.useMapId("addrAllProperties"),FieldsMappingOptions.oneWay()); 94 | // 95 | // //测试深度索引匹配 96 | // mapping(StudentDomain.class, StudentVo.class/*, TypeMappingOptions.mapId("userDeepMapping")*/, TypeMappingOptions.dateFormat("yyyy-MM-dd")) 97 | // .fields("courses[0].teacherName", "counsellor"); 98 | // 99 | // //测试自定义converter 100 | // mapping(StudentDomain.class, StudentVo.class/*, TypeMappingOptions.mapId("userScoreConverter")*/) 101 | // .fields("score", "score", customConverter(ScoreConverter.class)); 102 | 103 | mapping(StudentDomain.class, StudentVo.class/*, TypeMappingOptions.mapId("userScoreConverter")*/) 104 | .fields(field("enrollmentDate"), "enrollmentDate"); 105 | } 106 | }; 107 | 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /easy-excel-demo/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( 125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | echo Found %WRAPPER_JAR% 132 | ) else ( 133 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 134 | echo Downloading from: %DOWNLOAD_URL% 135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" 136 | echo Finished downloading %WRAPPER_JAR% 137 | ) 138 | @REM End of extension 139 | 140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 141 | if ERRORLEVEL 1 goto error 142 | goto end 143 | 144 | :error 145 | set ERROR_CODE=1 146 | 147 | :end 148 | @endlocal & set ERROR_CODE=%ERROR_CODE% 149 | 150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 154 | :skipRcPost 155 | 156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 158 | 159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 160 | 161 | exit /B %ERROR_CODE% 162 | -------------------------------------------------------------------------------- /spring-boot-unified-return/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( 125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | echo Found %WRAPPER_JAR% 132 | ) else ( 133 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 134 | echo Downloading from: %DOWNLOAD_URL% 135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" 136 | echo Finished downloading %WRAPPER_JAR% 137 | ) 138 | @REM End of extension 139 | 140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 141 | if ERRORLEVEL 1 goto error 142 | goto end 143 | 144 | :error 145 | set ERROR_CODE=1 146 | 147 | :end 148 | @endlocal & set ERROR_CODE=%ERROR_CODE% 149 | 150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 154 | :skipRcPost 155 | 156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 158 | 159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 160 | 161 | exit /B %ERROR_CODE% 162 | -------------------------------------------------------------------------------- /custom-starter/rgyb-spring-boot-sample/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( 125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | echo Found %WRAPPER_JAR% 132 | ) else ( 133 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 134 | echo Downloading from: %DOWNLOAD_URL% 135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" 136 | echo Finished downloading %WRAPPER_JAR% 137 | ) 138 | @REM End of extension 139 | 140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 141 | if ERRORLEVEL 1 goto error 142 | goto end 143 | 144 | :error 145 | set ERROR_CODE=1 146 | 147 | :end 148 | @endlocal & set ERROR_CODE=%ERROR_CODE% 149 | 150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 154 | :skipRcPost 155 | 156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 158 | 159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 160 | 161 | exit /B %ERROR_CODE% 162 | -------------------------------------------------------------------------------- /jdk12-demo/src/TestJDK12.java: -------------------------------------------------------------------------------- 1 | import java.io.File; 2 | import java.io.IOException; 3 | import java.nio.file.Files; 4 | import java.nio.file.Path; 5 | import java.nio.file.Paths; 6 | import java.text.NumberFormat; 7 | import java.util.*; 8 | import java.util.stream.Collectors; 9 | import java.util.stream.Stream; 10 | 11 | import static java.util.stream.Collectors.*; 12 | 13 | /** 14 | * 测试JDK12 Collectors. teeing API 15 | * 16 | * @author fraser 17 | * @date 2019/11/5 2:26 PM 18 | */ 19 | public class TestJDK12 { 20 | 21 | public static void main(String[] args) { 22 | 23 | NumberFormat formatter = NumberFormat.getCompactNumberInstance(Locale.US, NumberFormat.Style.SHORT); 24 | 25 | String formattedString = formatter.format(25000L); 26 | System.out.println(formattedString); 27 | 28 | // Path file1 = Paths.get("/Users/fraser/Documents/projects/personal/learning-demo-collection/jdk12-demo/src/file1.txt"); 29 | // Path file2 = Paths.get("/Users/fraser/Documents/projects/personal/learning-demo-collection/jdk12-demo/src/file2.txt"); 30 | // 31 | // 32 | // try { 33 | // long mismatch = Files.mismatch(file1, file2); 34 | // System.out.println(mismatch); 35 | // } catch (IOException e) { 36 | // e.printStackTrace(); 37 | // } 38 | 39 | // List names = List.of( " Alex", "brian"); 40 | // 41 | // List transformedNames = new ArrayList<>(); 42 | // 43 | // for (String name : names) 44 | // { 45 | // String transformedName = name.transform(String::strip) 46 | // .transform(StringUtils::toCamelCase); 47 | // 48 | // transformedNames.add(transformedName); 49 | // } 50 | 51 | 52 | // String result = "foo\nbar\n\tbar2".indent(4); 53 | // 54 | // System.out.println(result); 55 | // CountSum countsum = Stream.of(2, 11, 1, 5, 7, 8, 12) 56 | // .collect(Collectors.teeing( 57 | // counting(), 58 | // summingInt(e -> e), 59 | // CountSum::new)); 60 | // 61 | // System.out.println(countsum.toString()); 62 | // 63 | // //--------------------------------------------------------------------------------------- 64 | // 65 | // MinMax minmax = Stream.of(null, 2, 11, 1, 5, 7, 8, 12) 66 | // .collect(Collectors.teeing( 67 | // minBy(Comparator.nullsFirst(Comparator.naturalOrder())), 68 | // maxBy(Comparator.nullsLast(Comparator.naturalOrder())), 69 | // (Optional a, Optional b) -> new MinMax(a.orElse(Integer.MIN_VALUE), b.orElse(Integer.MAX_VALUE)))); 70 | // 71 | // System.out.println(minmax.toString()); 72 | // 73 | // //--------------------------------------------------------------------------------------- 74 | // 75 | // List melons = Arrays.asList(new Melon("Crenshaw", 1200), 76 | // new Melon("Gac", 3000), new Melon("Hemi", 2600), 77 | // new Melon("Hemi", 1600), new Melon("Gac", 1200), 78 | // new Melon("Apollo", 2600), new Melon("Horned", 1700), 79 | // new Melon("Gac", 3000), new Melon("Hemi", 2600) 80 | // ); 81 | // 82 | // 83 | // WeightsAndTotal weightsAndTotal = melons.stream() 84 | // .collect(Collectors.teeing( 85 | // summingInt(Melon::getWeight), 86 | // mapping(m -> m.getWeight(), toList()), 87 | // WeightsAndTotal::new)); 88 | // 89 | // System.out.println(weightsAndTotal.toString()); 90 | // 91 | // //--------------------------------------------------------------------------------------- 92 | // 93 | // var result = Stream.of( 94 | // new Guest("Marco", true, 3), 95 | // new Guest("David", false, 2), 96 | // new Guest("Roger",true, 6)) 97 | // .collect(Collectors.teeing( 98 | // Collectors.filtering(Guest::isParticipating, Collectors.mapping(Guest::getName, Collectors.toList())), 99 | // Collectors.summingInt(Guest::getParticipantsNumber), 100 | // EventParticipation::new 101 | // )); 102 | // System.out.println(result); 103 | } 104 | } 105 | 106 | 107 | class CountSum { 108 | private final Long count; 109 | private final Integer sum; 110 | public CountSum(Long count, Integer sum) { 111 | this.count = count; 112 | this.sum = sum; 113 | } 114 | 115 | @Override 116 | public String toString() { 117 | return "CountSum{" + 118 | "count=" + count + 119 | ", sum=" + sum + 120 | '}'; 121 | } 122 | } 123 | 124 | 125 | class MinMax { 126 | private final Integer min; 127 | private final Integer max; 128 | public MinMax(Integer min, Integer max) { 129 | this.min = min; 130 | this.max = max; 131 | } 132 | 133 | @Override 134 | public String toString() { 135 | return "MinMax{" + 136 | "min=" + min + 137 | ", max=" + max + 138 | '}'; 139 | } 140 | } 141 | 142 | 143 | class Melon { 144 | private final String type; 145 | private final int weight; 146 | public Melon(String type, int weight) { 147 | this.type = type; 148 | this.weight = weight; 149 | } 150 | 151 | public String getType() { 152 | return type; 153 | } 154 | 155 | public int getWeight() { 156 | return weight; 157 | } 158 | } 159 | 160 | class WeightsAndTotal { 161 | private final int totalWeight; 162 | private final List weights; 163 | public WeightsAndTotal(int totalWeight, List weights) { 164 | this.totalWeight = totalWeight; 165 | this.weights = weights; 166 | } 167 | 168 | @Override 169 | public String toString() { 170 | return "WeightsAndTotal{" + 171 | "totalWeight=" + totalWeight + 172 | ", weights=" + weights + 173 | '}'; 174 | } 175 | } 176 | 177 | class Guest { 178 | private String name; 179 | private boolean participating; 180 | private Integer participantsNumber; 181 | 182 | public Guest(String name, boolean participating, Integer participantsNumber) { 183 | this.name = name; 184 | this.participating = participating; 185 | this.participantsNumber = participantsNumber; 186 | } 187 | public boolean isParticipating() { 188 | return participating; 189 | } 190 | 191 | public Integer getParticipantsNumber() { 192 | return participantsNumber; 193 | } 194 | 195 | public String getName() { 196 | return name; 197 | } 198 | } 199 | 200 | class EventParticipation { 201 | private List guestNameList; 202 | private Integer totalNumberOfParticipants; 203 | 204 | public EventParticipation(List guestNameList, Integer totalNumberOfParticipants) { 205 | this.guestNameList = guestNameList; 206 | this.totalNumberOfParticipants = totalNumberOfParticipants; 207 | } 208 | 209 | @Override 210 | public String toString() { 211 | return "EventParticipation { " + 212 | "guests = " + guestNameList + 213 | ", total number of participants = " + totalNumberOfParticipants + 214 | " }"; 215 | } 216 | } 217 | -------------------------------------------------------------------------------- /dozer-demo/src/test/java/com/example/dozer/demo/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.dozer.demo; 2 | 3 | import com.example.dozer.demo.domain.AddressDomain; 4 | import com.example.dozer.demo.domain.CourseDomain; 5 | import com.example.dozer.demo.domain.StudentDomain; 6 | import com.example.dozer.demo.vo.StudentVo; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.dozer.Mapper; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.boot.test.context.SpringBootTest; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | @RunWith(SpringRunner.class) 19 | @SpringBootTest 20 | @Slf4j 21 | public class DemoApplicationTests { 22 | 23 | @Autowired 24 | private Mapper dozerMapper; 25 | 26 | @Test 27 | public void contextLoads() { 28 | } 29 | 30 | 31 | // @Test 32 | // public void testDefault(){ 33 | // StudentDomain studentDomain = new StudentDomain(1024L, "tan日拱一兵", 18, "18888888888"); 34 | // 35 | // StudentVo studentVo = dozerMapper.map(studentDomain, StudentVo.class); 36 | // log.info("StudentVo: [{}]", studentVo.toString()); 37 | // 38 | // studentVo.setAge(16); 39 | // log.info("StudentDomain: [{}]", dozerMapper.map(studentVo, StudentDomain.class)); 40 | // } 41 | 42 | 43 | @Test 44 | public void testCascadeObject() { 45 | StudentDomain studentDomain = getStudentDomain(); 46 | 47 | StudentVo studentVo = dozerMapper.map(studentDomain, StudentVo.class); 48 | log.info("StudentVo: [{}]", studentVo.toString()); 49 | } 50 | 51 | 52 | @Test 53 | public void testUserAllProperties() { 54 | StudentDomain studentDomain = getStudentDomain(); 55 | 56 | StudentVo studentVo = dozerMapper.map(studentDomain, StudentVo.class, "userAllProperties"); 57 | log.info("StudentVo: [{}]", studentVo.toString()); 58 | 59 | // 运行结果 60 | // StudentVo: [StudentVo(id=1024, name=tan日拱一兵, age=18, mobile=13333333333, addr=AddressVo(province=辽宁, city=大连, district=高新园区))] 61 | } 62 | 63 | 64 | @Test 65 | public void testUserExcludeMobile() { 66 | StudentDomain studentDomain = getStudentDomain(); 67 | StudentVo studentVo = dozerMapper.map(studentDomain, StudentVo.class, "userExcludeMobile"); 68 | log.info("StudentVo: [{}]", studentVo.toString()); 69 | // 运行结果 70 | // StudentVo: [StudentVo(id=1024, name=tan日拱一兵, age=18, mobile=null, addr=AddressVo(province=辽宁, city=大连, district=高新园区))] 71 | } 72 | 73 | 74 | //TODO 75 | @Test 76 | public void testUserNonNullAndExcludeMobile() { 77 | StudentDomain studentDomain = getStudentDomain(); 78 | studentDomain.setName(null); 79 | StudentVo studentVo = dozerMapper.map(studentDomain, StudentVo.class, "userNonNullAndExcludeMobile"); 80 | log.info("StudentVo: [{}]", studentVo.toString()); 81 | } 82 | 83 | @Test 84 | public void testUserWildcardFalse() { 85 | StudentDomain studentDomain = getStudentDomain(); 86 | StudentVo studentVo = dozerMapper.map(studentDomain, StudentVo.class, "userWildcardFalse"); 87 | log.info("StudentVo: [{}]", studentVo.toString()); 88 | // 运行结果 89 | // StudentVo: [StudentVo(id=null, name=null, age=null, mobile=null, addr=AddressVo(province=辽宁, city=大连, district=高新园区))] 90 | } 91 | 92 | @Test 93 | public void testUserFieldUseSpecifiedMapId() { 94 | StudentDomain studentDomain = getStudentDomain(); 95 | StudentVo studentVo = dozerMapper.map(studentDomain, StudentVo.class, "userFieldUseSpecifiedMapId"); 96 | log.info("StudentVo: [{}]", studentVo.toString()); 97 | // 运行结果 98 | // StudentVo: [StudentVo(id=null, name=null, age=null, mobile=null, addr=AddressVo(province=辽宁, city=大连, district=高新园区, detailAddr=腾飞软件园))] 99 | } 100 | 101 | @Test 102 | public void testUserOneWay() { 103 | StudentDomain studentDomain = getStudentDomain(); 104 | 105 | StudentVo studentVo = dozerMapper.map(studentDomain, StudentVo.class, "userOneWay"); 106 | log.info("StudentVo: [{}]", studentVo.toString()); 107 | 108 | studentVo.setAge(16); 109 | log.info("studentDomain: [{}]", dozerMapper.map(studentVo, StudentDomain.class, "userOneWay")); 110 | 111 | //运行结果: 112 | //org.dozer.MappingException: Class mapping not found by map-id: SRC-CLASS->com.example.dozer.demo.vo.StudentVo DST-CLASS->com.example.dozer.demo.domain.StudentDomain MAP-ID->userOneWay 113 | } 114 | 115 | @Test 116 | public void testUserFieldOneWay() { 117 | StudentDomain studentDomain = getStudentDomain(); 118 | 119 | StudentVo studentVo = dozerMapper.map(studentDomain, StudentVo.class, "userFieldOneWay"); 120 | log.info("StudentVo: [{}]", studentVo.toString()); 121 | 122 | studentVo.setAge(16); 123 | log.info("studentDomain: [{}]", dozerMapper.map(studentVo, StudentDomain.class, "userFieldOneWay")); 124 | 125 | //运行结果: 126 | //StudentVo: [StudentVo(id=1024, name=tan日拱一兵, age=18, mobile=13333333333, addr=null)] 127 | //studentDomain: [StudentDomain(id=1024, name=tan日拱一兵, age=null, mobile=13333333333, address=null)] 128 | 129 | } 130 | 131 | 132 | @Test 133 | public void testUserDeepMapping() { 134 | StudentDomain studentDomain = getStudentDomain(); 135 | 136 | StudentVo studentVo = dozerMapper.map(studentDomain, StudentVo.class, "userDeepMapping"); 137 | log.info("StudentVo: [{}]", studentVo.toString()); 138 | 139 | //运行结果: 140 | //StudentVo: [StudentVo(id=1024, name=tan日拱一兵, age=18, mobile=13333333333, addr=null)] 141 | //studentDomain: [StudentDomain(id=1024, name=tan日拱一兵, age=null, mobile=13333333333, address=null)] 142 | 143 | } 144 | 145 | @Test 146 | public void testUserScoreConverter() { 147 | StudentDomain studentDomain = getStudentDomain(); 148 | 149 | StudentVo studentVo = dozerMapper.map(studentDomain, StudentVo.class, "userScoreConverter"); 150 | log.info("StudentVo: [{}]", studentVo.toString()); 151 | 152 | } 153 | 154 | 155 | private StudentDomain getStudentDomain() { 156 | StudentDomain studentDomain = new StudentDomain(); 157 | studentDomain.setId(1024L); 158 | studentDomain.setName("tan日拱一兵"); 159 | studentDomain.setAge(18); 160 | studentDomain.setMobile("13996996996"); 161 | studentDomain.setScore(90); 162 | 163 | AddressDomain addressDomain = new AddressDomain(); 164 | addressDomain.setProvince("北京"); 165 | addressDomain.setCity("北京"); 166 | addressDomain.setDistrict("海淀区"); 167 | addressDomain.setDetail("西二旗"); 168 | studentDomain.setAddress(addressDomain); 169 | 170 | List courseDomains = new ArrayList<>(2); 171 | CourseDomain englishCourse = new CourseDomain(); 172 | englishCourse.setCourseId(1); 173 | englishCourse.setCourseCode("English"); 174 | englishCourse.setCourseName("英语"); 175 | englishCourse.setTeacherName("京晶"); 176 | courseDomains.add(englishCourse); 177 | 178 | CourseDomain chineseCourse = new CourseDomain(); 179 | chineseCourse.setCourseId(2); 180 | chineseCourse.setCourseCode("Chinese"); 181 | chineseCourse.setCourseName("语文"); 182 | chineseCourse.setTeacherName("水寒"); 183 | courseDomains.add(chineseCourse); 184 | 185 | studentDomain.setCourses(courseDomains); 186 | studentDomain.setEnrollmentDate("2019-09-01 10:00:00"); 187 | 188 | return studentDomain; 189 | } 190 | 191 | } 192 | -------------------------------------------------------------------------------- /springboot-application-startup/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" 124 | 125 | FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 162 | if ERRORLEVEL 1 goto error 163 | goto end 164 | 165 | :error 166 | set ERROR_CODE=1 167 | 168 | :end 169 | @endlocal & set ERROR_CODE=%ERROR_CODE% 170 | 171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 175 | :skipRcPost 176 | 177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 179 | 180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 181 | 182 | exit /B %ERROR_CODE% 183 | -------------------------------------------------------------------------------- /easy-excel-demo/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | ########################################################################################## 204 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 205 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 206 | ########################################################################################## 207 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 208 | if [ "$MVNW_VERBOSE" = true ]; then 209 | echo "Found .mvn/wrapper/maven-wrapper.jar" 210 | fi 211 | else 212 | if [ "$MVNW_VERBOSE" = true ]; then 213 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 214 | fi 215 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 216 | while IFS="=" read key value; do 217 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 218 | esac 219 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 220 | if [ "$MVNW_VERBOSE" = true ]; then 221 | echo "Downloading from: $jarUrl" 222 | fi 223 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 224 | 225 | if command -v wget > /dev/null; then 226 | if [ "$MVNW_VERBOSE" = true ]; then 227 | echo "Found wget ... using wget" 228 | fi 229 | wget "$jarUrl" -O "$wrapperJarPath" 230 | elif command -v curl > /dev/null; then 231 | if [ "$MVNW_VERBOSE" = true ]; then 232 | echo "Found curl ... using curl" 233 | fi 234 | curl -o "$wrapperJarPath" "$jarUrl" 235 | else 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Falling back to using Java to download" 238 | fi 239 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 240 | if [ -e "$javaClass" ]; then 241 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 242 | if [ "$MVNW_VERBOSE" = true ]; then 243 | echo " - Compiling MavenWrapperDownloader.java ..." 244 | fi 245 | # Compiling the Java class 246 | ("$JAVA_HOME/bin/javac" "$javaClass") 247 | fi 248 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 249 | # Running the downloader 250 | if [ "$MVNW_VERBOSE" = true ]; then 251 | echo " - Running MavenWrapperDownloader.java ..." 252 | fi 253 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 254 | fi 255 | fi 256 | fi 257 | fi 258 | ########################################################################################## 259 | # End of extension 260 | ########################################################################################## 261 | 262 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 263 | if [ "$MVNW_VERBOSE" = true ]; then 264 | echo $MAVEN_PROJECTBASEDIR 265 | fi 266 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 267 | 268 | # For Cygwin, switch paths to Windows format before running java 269 | if $cygwin; then 270 | [ -n "$M2_HOME" ] && 271 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 272 | [ -n "$JAVA_HOME" ] && 273 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 274 | [ -n "$CLASSPATH" ] && 275 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 276 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 277 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 278 | fi 279 | 280 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 281 | 282 | exec "$JAVACMD" \ 283 | $MAVEN_OPTS \ 284 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 285 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 286 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 287 | -------------------------------------------------------------------------------- /spring-boot-unified-return/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | ########################################################################################## 204 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 205 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 206 | ########################################################################################## 207 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 208 | if [ "$MVNW_VERBOSE" = true ]; then 209 | echo "Found .mvn/wrapper/maven-wrapper.jar" 210 | fi 211 | else 212 | if [ "$MVNW_VERBOSE" = true ]; then 213 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 214 | fi 215 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 216 | while IFS="=" read key value; do 217 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 218 | esac 219 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 220 | if [ "$MVNW_VERBOSE" = true ]; then 221 | echo "Downloading from: $jarUrl" 222 | fi 223 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 224 | 225 | if command -v wget > /dev/null; then 226 | if [ "$MVNW_VERBOSE" = true ]; then 227 | echo "Found wget ... using wget" 228 | fi 229 | wget "$jarUrl" -O "$wrapperJarPath" 230 | elif command -v curl > /dev/null; then 231 | if [ "$MVNW_VERBOSE" = true ]; then 232 | echo "Found curl ... using curl" 233 | fi 234 | curl -o "$wrapperJarPath" "$jarUrl" 235 | else 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Falling back to using Java to download" 238 | fi 239 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 240 | if [ -e "$javaClass" ]; then 241 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 242 | if [ "$MVNW_VERBOSE" = true ]; then 243 | echo " - Compiling MavenWrapperDownloader.java ..." 244 | fi 245 | # Compiling the Java class 246 | ("$JAVA_HOME/bin/javac" "$javaClass") 247 | fi 248 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 249 | # Running the downloader 250 | if [ "$MVNW_VERBOSE" = true ]; then 251 | echo " - Running MavenWrapperDownloader.java ..." 252 | fi 253 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 254 | fi 255 | fi 256 | fi 257 | fi 258 | ########################################################################################## 259 | # End of extension 260 | ########################################################################################## 261 | 262 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 263 | if [ "$MVNW_VERBOSE" = true ]; then 264 | echo $MAVEN_PROJECTBASEDIR 265 | fi 266 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 267 | 268 | # For Cygwin, switch paths to Windows format before running java 269 | if $cygwin; then 270 | [ -n "$M2_HOME" ] && 271 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 272 | [ -n "$JAVA_HOME" ] && 273 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 274 | [ -n "$CLASSPATH" ] && 275 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 276 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 277 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 278 | fi 279 | 280 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 281 | 282 | exec "$JAVACMD" \ 283 | $MAVEN_OPTS \ 284 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 285 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 286 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 287 | --------------------------------------------------------------------------------