Lombok

一些好用的idea插件(一直用一直爽)-持续更新

為{幸葍}努か 提交于 2019-11-30 18:07:13
lombok:很好用的插件,简化实体类,不再写get/set方法还能快速的实现builder模式,以及链式调用方法 <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> idea 需要 安装 lombok 插件 2.MyBatis Log Plugin:打印完整的sql idea 安装 MyBatis Log Plugin 安装后 启动项目 打开 tools 3.Mybatis plugin :在mapper接口中和mapper的xml文件中来回跳转,就像接口跳到实现类那样简单。 idea安装Mybatis plugin 4.swagger—— SosoApi 接口測試,文檔工具 <!-- swagger --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.8.0</version> </dependency> <!-- swagger-ui --> <dependency> <groupId>io.springfox</groupId>

springboot系列之04-提高开发效率必备工具lombok

南笙酒味 提交于 2019-11-30 18:03:36
未经允许,不得转载 原作者: 字母哥博客 本文完整系列出自: springboot深入浅出系列 一、前置说明 本节大纲 使用lombok插件的好处 如何安装lombok插件 使用lombok提高开发效率 二、使用lombok插件的好处 我们在java开发过程中,经常会有一些常规性的,重复性的工作。比如: 根据成员变量生成get和set方法 根据成员变量生成类的构造函数 重写toString()和hashCode方法 引入日志框架logFactory,用来打印日志 以上都是一些重复动作,模板代码。每次都手动生成既浪费时间,又增加了大量的冗余代码。我们可以使用lombok插件来解决这个问题。使我们的编码效率得到大幅度的提高! 三、如何安装lombok插件 笔者以InelliJ IDEA为例,安装lombok插件。打开 IDEA 的 File->Settings 面板,并选择 Plugins 选项,然后点击 “Browse repositories”。在搜索框输入”lombok”,结果中找到lombok点击install,然后重启 IDEA。 我们还要在pom.xml里面加上如下依赖,插件生效。 <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true<

4、Spring注解开发,第四天

无人久伴 提交于 2019-11-30 18:01:45
第四天:Spring annotation开发 目录:1、bean的生命周期-初始化和销毁方法 2、@Value赋值 3、@PropertySource加载外部配置文件 4、@Profile根据外部环境注册 一、bean的生命周期-初始化和销毁方法 构造(对象创建) 单实例:在容器启动的时候创建对象 多实例:在每次获取的时候创建对象 初始化: 对象创建完成,病赋值好,调用初始化方法 init-method PostConstruct 销毁: 单实例:容器关闭的时候 多实例:容器不会管理这个bean,容器不会调用销毁方法 destroy-method preDestroy 方式: 1、@Bean(initMethod="xxx",destroyMethod="yyy") 2、通过bean implements InitialzingBean(定义初始化逻辑) 通过bean implements DisposableBean(定义销毁逻辑) 3、@PostConstruct @PreDestroy 4、BeanPostProcessor[interface]:bean的后置处理器-----[针对容器中的所有bean] 在bean初始化前后进行一些处理工作: postProcessBeforeInitialization(..)初始化之前处理

What does the syntax `@__()` mean in Lombok?

谁都会走 提交于 2019-11-30 17:31:57
I have been working with and actively using Lombok for 2 months. With Java I'm a little more familiar. But, for the first time, I was faced with the following syntax structure in the language: @RequiredArgsController(onController = @__(@Autowired)) ^^^ What does that mean, and how does it get compiled? OrangeDog This is an experimental Lombok syntax, created to support a layer of indirection when referencing multiple annotations, rather than use a Class<?>[] . The syntax is a little strange; to use any of the 3 onX features, you must wrap the annotations to be applied to the constructor /

Unable to use Lombok with Java 11

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 17:00:52
We upgraded the Java version from 8 to 11 but I got compile errors of getter/setter methods where I implemented the POJO classes with Lombok's Getter and Setter Annotations. Is there a way to use Lombok's @Data annotation which provides getter and setter without implementing them at Java 11? Currently, I am facing the error: unable to find getStoreName() where storeName was declared as a global variable in the class with @Data Lombok annotation above the class. TL;DR Upgrade Lombok as a dependency and as a IDE plugin ( IntelliJ , NetBeans , Eclipse ) and enable Annotation Processing in IDEs

Spring Boot 2.x基础教程:构建RESTful API与单元测试

…衆ロ難τιáo~ 提交于 2019-11-30 16:59:27
首先,回顾并详细说明一下在 快速入门 中使用的 @Controller 、 @RestController 、 @RequestMapping 注解。如果您对Spring MVC不熟悉并且还没有尝试过快速入门案例,建议先看一下 快速入门 的内容。 @Controller :修饰class,用来创建处理http请求的对象 @RestController :Spring4之后加入的注解,原来在 @Controller 中返回json需要 @ResponseBody 来配合,如果直接用 @RestController 替代 @Controller 就不需要再配置 @ResponseBody ,默认返回json格式 @RequestMapping :配置url映射。现在更多的也会直接用以Http Method直接关联的映射注解来定义,比如: GetMapping 、 PostMapping 、 DeleteMapping 、 PutMapping 等 下面我们通过使用Spring MVC来实现一组对User对象操作的RESTful API,配合注释详细说明在Spring MVC中如何映射HTTP请求、如何传参、如何编写单元测试。 ** RESTful API具体设计如下:** 定义User实体 @Data public class User { private Long id;

实体类中省略Get 和set 方法

我的未来我决定 提交于 2019-11-30 14:38:38
1. 实体类上面加注解: import lombok.Data; @Data public class Merchant { private String merId; private String merName; } 2. pom.xml 文件添加 <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.16.18</version> <scope>provided</scope> </dependency> 3.查看eclipse 下是否有 lombok.jar 如果没有到maven 私服目录下面点击lombok.jar 回自动添加到Eclipse 下面 弹出如下面的图,点击红色标注 4. 重新启动Eclipse 就可以使用 其他知识引入: @Data :注解在类上;提供类所有属性的 getting 和 setting 方法,此外还提供了equals、canEqual、hashCode、toString 方法 @Setter:注解在属性上;为属性提供 setting 方法 @Getter:注解在属性上;为属性提供 getting 方法 @Log4j :注解在类上;为类提供一个 属性名为log 的 log4j 日志对象

Spring Boot 的单元测试和集成测试

做~自己de王妃 提交于 2019-11-30 14:22:07
学习如何使用本教程中提供的工具,并在 Spring Boot 环境中编写单元测试和集成测试。 1. 概览 本文中,我们将了解如何编写单元测试并将其集成在 Spring Boot 环境中。你可在网上找到大量关于这个主题的教程,但很难在一个页面中找到你需要的所有信息。我经常注意到初级开发人员混淆了单元测试和集成测试的概念,特别是在谈到 Spring 生态系统时。我将尝试讲清楚不同注解在不同上下文中的用法。 2. 单元测试 vs. 集成测试 维基百科是这么说 单元测试 的: > 在计算机编程中,单元测试是一种软件测试方法,用以测试源代码的单个单元、一个或多个计算机程序模块的集合以及相关的控制数据、使用过程和操作过程,以确定它们是否适合使用。 集成测试 : > “集成测试(有时也称集成和测试,缩写为 I&T)是软件测试的一个阶段,在这个阶段中,各个软件模块被组合在一起来进行测试。” 简而言之,当我们在做单元测试时,只是测试了一个代码单元,每次只测试一个方法,不包括与正测试组件相交互的其他所有组件。 另一方面,在集成测试中,我们测试各组件之间的集成。**由于单元测试,我们可知这些组件行为与所需一致,但不清楚它们是如何在一起工作的。**这就是集成测试的职责。 3. Java 单元测试 所有 Java 开发者都知道 JUnit 是执行单元测试的主要框架。它提供了许多注解来对期望进行断言。

Maven build cannot find symbol when accessing project lombok annotated methods,

喜你入骨 提交于 2019-11-30 10:52:32
I'm using project lombok for the first time and I have problems compiling the project via maven when I run the build I receive errors where methods annotated with project lombok annotations are called. This is the annotated parameter: private @Getter @Setter String paymentNonce = null; and in this line for example the maven breaks the build: if (!StringUtilities.isNullOrEmpty(getPaymentNonce())) { this is my maven dependency <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.16.4</version> </dependency> the maven error: [INFO] Compiling 158 source

Optional in Lombok

跟風遠走 提交于 2019-11-30 10:46:27
I have a class called Address which looks like this: @Value class Address { @NotNull String userId; @NotNull String line1; String line2; private Address(Builder b) { // copy everything from builder } // override getter for line2 so that it returns Optional<String> public Optional<String> getLine2() { return Optional.ofNullable(this.line2); } // and a Builder public static class Builder { // builder methods } } Here I am forced to write Builder and a Getter because, if I want to return an Optional while using Lombok, I will have to declare line2 as Optional<String> . And that will generate a