Lombok

IDEA安装lombok使用注解

两盒软妹~` 提交于 2019-12-06 12:24:15
在pom.xml加入lombok依赖 更新maven <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> 将lombok插件安装到idea内 将这个lombok插件安装的idea内 安装完成后重启idea Lombok 注解在线帮助文档 http://projectlombok.org/features/index . 常用的 lombok 注解 @Data :注解在类上;提供类所有属性的 getting 和 setting 方法,此外还提供了equals、canEqual、hashCode、toString 方法 @Setter:注解在属性上;为属性提供 setting 方法 @Getter:注解在属性上;为属性提供 getting 方法 @Log4j :注解在类上;为类提供一个 属性名为log 的 log4j 日志对象 @NoArgsConstructor:注解在类上;为类提供一个无参的构造方法 @AllArgsConstructor:注解在类上;为类提供一个全参的构造方法 来源: https://my.oschina.net/zlhblogs/blog/3137412

Bean使用链式调用,使你的代码高大尚

ε祈祈猫儿з 提交于 2019-12-06 11:43:31
Bean使用链式调用,使你的代码高大尚: 1、原理,直接上代码: /** * 链式调用测试 */ public class ChainVo { private Integer id; private String name; public ChainVo setId(Integer id) { this.id = id; return this; } public ChainVo setName(String name) { this.name = name; return this; } public Integer getId() { return id; } public String getName() { return name; } } 2、测试: @Test public void test() { ChainVo chainVo = new ChainVo().setId(1).setName("test"); System.out.println(chainVo.getId()); } 3、简化版链式调用: 1)、引入lombok jar包 <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.6</version> <

崛起于Springboot2.X + Mybatis-plus(62)

柔情痞子 提交于 2019-12-06 08:01:47
《SpringBoot2.X心法总纲》 项目Git地址: https://gitee.com/mdxl/blog.git 1、项目结构 2、pom依赖 勾选web、jdbc、mysql、lombok依赖,然后添加其他依赖 <!--mybatis-plus配置依赖--> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.2.0</version> </dependency> <!--mybatis-plus 代码生成器--> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-generator</artifactId> <version>3.2.0</version> </dependency> <!--辅助 mybatis-plus 代码生成器前端模版引擎插件--> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>2.3.29</version> </dependency> 3、配置类

使用线程池+队列实现异步处理业务问题

跟風遠走 提交于 2019-12-06 06:50:22
背景 当系统中的业务存在大量的相同任务(比如发送大量邮件),并且每个任务花费的时间也比较长,前段需要较快 的响应,针对这种需求,我们可以采用消息队列进行异步通知,同时也可以采用线程池+内存队列实现异步通知,处理业务问题。 代码实现 以下采用发送邮件作为demo 邮箱实体类 @Data public class Email implements Serializable { private static final long serialVersionUID = 1L; /** * 自增主键 */ private Long id; /** * 接收人邮箱(多个逗号分开) */ private String receiveEmail; /** * 主题 */ private String subject; /** * 发送内容 */ private String content; /** * 模板 */ private String template; /** * 发送时间 */ private Timestamp sendTime; } 邮件队列 public class MailQueue { //队列大小 static final int QUEUE_MAX_SIZE = 1000; static BlockingQueue<Email> blockingQueue = new

Spring Data REST: “no String-argument constructor/factory method to deserialize from String value”

允我心安 提交于 2019-12-06 04:40:51
问题 When I use Lombok in my Spring Data REST application to define complex types like: @NoArgsConstructor @AllArgsConstructor @Data @Entity @Table(name = "BOOK") public class Book { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(nullable = false) private Long id; private String title; @ManyToOne(cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.REFRESH}) private Person author; // ... } with a Spring Data REST controllers like: @RepositoryRestController public class

Use Maven Compiler Plugin with Eclipse Compiler and Lombok

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 04:27:02
问题 Is there a way to compile lomboked code in ECJ without setting lombok as javaaagent for the maven process? The snippet below only works if I run mvn with lombok as agent <profile> <id>ecj</id> <build> <pluginManagement> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <compilerId>eclipse</compilerId> </configuration> <dependencies> <dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-compiler-eclipse</artifactId> <version>2.8-SNAPSHOT<

Parceler and Lombok not working together?

試著忘記壹切 提交于 2019-12-06 03:23:21
For my android app I use the parceler library and the lombok library. These are the annotations of my class: @Table @ToString @Getter @NoArgsConstructor @Parcel public class MyClass { However, during gradle build, Parceler complains that there is no default empty constructor. So does this mean it doesn't recognize the @NoArgsConstructor annotation and these two simply won't work together? Because e.g. SugarORM has no probs with it. Or am I just missing something? This gets into how Lombok adds code to your class. Lombok uses a known trick in the Java annotation processor to add code to your

多线程售票

断了今生、忘了曾经 提交于 2019-12-06 00:25:56
多线程售票 多线程操作资源类 创建启动线程的写法 public Thread(Runnable target, String name).start() 线程的 6 种状态,线程调用 start 方法后不会立即执行,而是要等待空闲 CPU 的调度 使用 ReentrantLock 保证资源类的安全 package com.zbiti.juc; import lombok.extern.slf4j.Slf4j; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; //多线程操作资源类 3个售票员 操作 50张票 public class SaleTicket { public static void main(String[] args) throws InterruptedException { Ticket ticket = new Ticket(); new Thread(()->{ for(int i=0;i<40;i++){ ticket.sale(); } },"AA").start(); new Thread(()->{ for(int i=0;i<40;i++){

崛起于Springboot2.X + 多模块整合 + 一个启动类 + jar、war打包运行(60)

和自甴很熟 提交于 2019-12-05 20:04:47
《SpringBoot2.X心法总纲》 博客概要:Springboot多模块项目搭建 + 打包jar运行 + 打包war运行 1、创建父工程 勾选SpringWeb和lombok 如图所示 然后删除src文件夹,如图: 然后修改pom文件,添加一行打包类型 <packaging>pom</packaging> 2、创建子模块 创建3个子模块,分别为sun1、sun2、web,不勾选任何依赖。因为我们所用的依赖都在父工程的pom文件中。 创建好三个模块之后,在父工程pom.xml添加依赖 <modules> <module>sun1</module> <module>sun2</module> <module>web</module> </modules> 因为我们目前用的是Springboot多模块一个启动类,所以删除sun1和sun2的启动类,然后sun1存放实体类,因为需要使用lombok插件,所以sun1项目引入父工程pom.xml,在sun1的pom.xml中更换 <parent> <groupId>com.osc</groupId> <artifactId>father</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> 然后打包加上 <packaging>jar</packaging> 因为继承父工程

How to make QueryDSL and Lombok work together

谁都会走 提交于 2019-12-05 18:23:48
问题 When a method or variable is annotated with Lombok annotation, the maven plugin will complain by processing the source generation for JPA. I get this kind of failure in the console logs: symbol: class __ location: class ServiceBaseMessage C:\workspaces\[...]\service\ServiceBaseMessage.java:44: error: cannot find symbol @Getter(onMethod = @__({ @JsonProperty("TYPE") })) How to make the apt-maven-plugin and queryDSL processor for JPA annotations work together with lombok annotations ? 回答1: This