-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd88fc2
commit b62f04a
Showing
21 changed files
with
523 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
HELP.md | ||
/target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
/build/ | ||
|
||
### VS Code ### | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.macro.mall</groupId> | ||
<artifactId>mall-tiny-lombok</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>mall-tiny-lombok</name> | ||
<description>Demo project for Spring Boot</description> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<java.version>1.8</java.version> | ||
<skipTests>true</skipTests> | ||
</properties> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.3.0.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<dependencies> | ||
<!--SpringBoot通用依赖模块--> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-aop</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<!--lombok依赖--> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
mall-tiny-lombok/src/main/java/com/macro/mall/tiny/MallTinyApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.macro.mall.tiny; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class MallTinyApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(MallTinyApplication.class, args); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
mall-tiny-lombok/src/main/java/com/macro/mall/tiny/example/BuilderExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.macro.mall.tiny.example; | ||
|
||
import lombok.Builder; | ||
import lombok.ToString; | ||
|
||
/** | ||
* Created by macro on 2020/12/17. | ||
*/ | ||
@Builder | ||
@ToString | ||
public class BuilderExample { | ||
private Long id; | ||
private String name; | ||
private Integer age; | ||
|
||
public static void main(String[] args) { | ||
BuilderExample example = BuilderExample.builder() | ||
.id(1L) | ||
.name("test") | ||
.age(20) | ||
.build(); | ||
System.out.println(example); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
mall-tiny-lombok/src/main/java/com/macro/mall/tiny/example/CleanupExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.macro.mall.tiny.example; | ||
|
||
import lombok.Cleanup; | ||
|
||
import java.io.*; | ||
|
||
/** | ||
* Created by macro on 2020/12/16. | ||
*/ | ||
public class CleanupExample { | ||
public static void main(String[] args) throws IOException { | ||
String inStr = "Hello World!"; | ||
//使用输入输出流自动关闭,无需编写try catch和调用close()方法 | ||
@Cleanup ByteArrayInputStream in = new ByteArrayInputStream(inStr.getBytes("UTF-8")); | ||
@Cleanup ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
byte[] b = new byte[1024]; | ||
while (true) { | ||
int r = in.read(b); | ||
if (r == -1) break; | ||
out.write(b, 0, r); | ||
} | ||
String outStr = out.toString("UTF-8"); | ||
System.out.println(outStr); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
mall-tiny-lombok/src/main/java/com/macro/mall/tiny/example/ConstructorExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.macro.mall.tiny.example; | ||
|
||
import lombok.*; | ||
|
||
/** | ||
* Created by macro on 2020/12/17. | ||
*/ | ||
@NoArgsConstructor | ||
@RequiredArgsConstructor(staticName = "of") | ||
@AllArgsConstructor | ||
public class ConstructorExample { | ||
@NonNull | ||
private Long id; | ||
private String name; | ||
private Integer age; | ||
|
||
public static void main(String[] args) { | ||
//无参构造器 | ||
ConstructorExample example1 = new ConstructorExample(); | ||
//全部参数构造器 | ||
ConstructorExample example2 = new ConstructorExample(1L,"test",20); | ||
//@NonNull注解的必须参数构造器 | ||
ConstructorExample example3 = ConstructorExample.of(1L); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
mall-tiny-lombok/src/main/java/com/macro/mall/tiny/example/DataExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.macro.mall.tiny.example; | ||
|
||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NonNull; | ||
|
||
/** | ||
* Created by macro on 2020/12/17. | ||
*/ | ||
@Data | ||
public class DataExample { | ||
@NonNull | ||
private Long id; | ||
@EqualsAndHashCode.Exclude | ||
private String name; | ||
@EqualsAndHashCode.Exclude | ||
private Integer age; | ||
|
||
public static void main(String[] args) { | ||
//@RequiredArgsConstructor已生效 | ||
DataExample example1 = new DataExample(1L); | ||
//@Getter @Setter已生效 | ||
example1.setName("test"); | ||
example1.setAge(20); | ||
//@ToString已生效 | ||
System.out.println(example1); | ||
DataExample example2 = new DataExample(1L); | ||
//@EqualsAndHashCode已生效 | ||
System.out.println(example1.equals(example2)); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
mall-tiny-lombok/src/main/java/com/macro/mall/tiny/example/EqualsAndHashCodeExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.macro.mall.tiny.example; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
/** | ||
* Created by macro on 2020/12/17. | ||
*/ | ||
@Getter | ||
@Setter | ||
@EqualsAndHashCode | ||
public class EqualsAndHashCodeExample { | ||
private Long id; | ||
@EqualsAndHashCode.Exclude | ||
private String name; | ||
@EqualsAndHashCode.Exclude | ||
private Integer age; | ||
|
||
public static void main(String[] args) { | ||
EqualsAndHashCodeExample example1 = new EqualsAndHashCodeExample(); | ||
example1.setId(1L); | ||
example1.setName("test"); | ||
example1.setAge(20); | ||
EqualsAndHashCodeExample example2 = new EqualsAndHashCodeExample(); | ||
example2.setId(1L); | ||
//equals方法只对比id,返回true | ||
System.out.println(example1.equals(example2)); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
mall-tiny-lombok/src/main/java/com/macro/mall/tiny/example/GetterLazyExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.macro.mall.tiny.example; | ||
|
||
import lombok.Getter; | ||
|
||
/** | ||
* Created by macro on 2020/12/17. | ||
*/ | ||
public class GetterLazyExample { | ||
@Getter(lazy = true) | ||
private final double[] cached = expensive(); | ||
|
||
private double[] expensive() { | ||
double[] result = new double[1000000]; | ||
for (int i = 0; i < result.length; i++) { | ||
result[i] = Math.asin(i); | ||
} | ||
return result; | ||
} | ||
|
||
public static void main(String[] args) { | ||
//使用Double Check Lock 样板代码对属性进行懒加载 | ||
GetterLazyExample example = new GetterLazyExample(); | ||
System.out.println(example.getCached().length); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
mall-tiny-lombok/src/main/java/com/macro/mall/tiny/example/GetterSetterExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.macro.mall.tiny.example; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
/** | ||
* Created by macro on 2020/12/17. | ||
*/ | ||
public class GetterSetterExample { | ||
@Getter | ||
@Setter | ||
private String name; | ||
@Getter | ||
@Setter(AccessLevel.PROTECTED) | ||
private Integer age; | ||
|
||
public static void main(String[] args) { | ||
GetterSetterExample example = new GetterSetterExample(); | ||
example.setName("test"); | ||
example.setAge(20); | ||
System.out.printf("name:%s age:%d",example.getName(),example.getAge()); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
mall-tiny-lombok/src/main/java/com/macro/mall/tiny/example/LogExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.macro.mall.tiny.example; | ||
|
||
import lombok.extern.java.Log; | ||
|
||
/** | ||
* Created by macro on 2020/12/17. | ||
*/ | ||
@Log | ||
public class LogExample { | ||
public static void main(String[] args) { | ||
log.info("level info"); | ||
log.warning("level warning"); | ||
log.severe("level severe"); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
mall-tiny-lombok/src/main/java/com/macro/mall/tiny/example/LogSlf4jExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.macro.mall.tiny.example; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* Created by macro on 2020/12/17. | ||
*/ | ||
@Slf4j | ||
public class LogSlf4jExample { | ||
public static void main(String[] args) { | ||
log.info("level:{}","info"); | ||
log.warn("level:{}","warn"); | ||
log.error("level:{}", "error"); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
mall-tiny-lombok/src/main/java/com/macro/mall/tiny/example/NonNullExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.macro.mall.tiny.example; | ||
|
||
import lombok.NonNull; | ||
|
||
/** | ||
* Created by macro on 2020/12/16. | ||
*/ | ||
public class NonNullExample { | ||
private String name; | ||
public NonNullExample(@NonNull String name){ | ||
this.name = name; | ||
} | ||
|
||
public static void main(String[] args) { | ||
new NonNullExample("test"); | ||
//会抛出NullPointerException | ||
new NonNullExample(null); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
mall-tiny-lombok/src/main/java/com/macro/mall/tiny/example/SneakyThrowsExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.macro.mall.tiny.example; | ||
|
||
import lombok.SneakyThrows; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
|
||
/** | ||
* Created by macro on 2020/12/17. | ||
*/ | ||
public class SneakyThrowsExample { | ||
|
||
//自动抛出异常,无需处理 | ||
@SneakyThrows(UnsupportedEncodingException.class) | ||
public static byte[] str2byte(String str){ | ||
return str.getBytes("UTF-8"); | ||
} | ||
|
||
public static void main(String[] args) { | ||
String str = "Hello World!"; | ||
System.out.println(str2byte(str).length); | ||
} | ||
} |
Oops, something went wrong.