Lombok

JAVA中使用Log4j2日志和Lombok引入日志的方法

北城余情 提交于 2020-02-26 23:08:46
一、简述   我们项目中既要使用lombok,又要使用log4j2时,使用日志将会更简单。 二、解决   1、引入依赖 <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> <version>2.11.0</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.16.22</version> </dependency> 2、在resources中引入log4j2.xml,内容如下: <?xml version="1.0" encoding="UTF-8"?> <configuration status="INFO"> <appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> </Console> <RollingFile name="RollingFile

Lombok 的 @EqualsAndHashCode(callSuper = false) 的使用

夙愿已清 提交于 2020-02-26 18:16:56
官方文档:@EqualsAndHashCode 原文中提到的大致有以下几点: 1. 此注解会生成equals(Object other) 和 hashCode()方法。 2. 它默认使用非静态,非瞬态的属性 3. 可通过参数exclude排除一些属性 4. 可通过参数of指定仅使用哪些属性 5. 它默认仅使用该类中定义的属性且不调用父类的方法 6. 可通过callSuper=true解决上一点问题。让其生成的方法中调用父类的方法。 另:@Data相当于 @Getter @Setter @RequiredArgsConstructor @ToString @EqualsAndHashCode这5个注解的合集。 通过官方文档,可以得知,当使用@Data注解时,则有了@EqualsAndHashCode注解,那么就会在此类中存在equals(Object other) 和 hashCode()方法,且不会使用父类的属性,这就导致了可能的问题。 比如,有多个类有相同的部分属性,把它们定义到父类中,恰好id(数据库主键)也在父类中,那么就会存在部分对象在比较时,它们并不相等,却因为lombok自动生成的equals(Object other) 和 hashCode()方法判定为相等,从而导致出错。 修复此问题的方法很简单: 1. 使用@Getter @Setter @ToString代替

【微信小程序】使用Java后端语言发送订阅(模板)消息

独自空忆成欢 提交于 2020-02-26 15:01:23
代码所需JAR 需要安装lombok插件哦 <!-- hutool --> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>4.5.13</version> </dependency> <!-- Lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.8</version> </dependency> <!-- fastjson --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.59</version> </dependency> 官方文档必须看一下哈 https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/subscribe-message.html 步骤一:获取模板 ID 在微信公众平台手动配置获取模板 ID: 登录 https://mp.weixin.qq.com 获取模板

SpringBoot实战:SpringBoot之本地配置(二)

久未见 提交于 2020-02-26 09:12:15
SpringBoot不单单只支持@value的形式读取配置,还可以同过spring管理的bean上添加@ConfigurationProperties来获取。接下来我们看看如何使用@ConfigurationProperties读取配置值的。 在application.properties文件中添加以下配置,当然在application-dev.properties文件中添加也是可以的。 #应用id spring.application.id=spring-boot-wusy-demo #应用名称 spring.application.name=spring-boot-wusy-demo #编码设置 server.tomcat.uri-encoding=UTF-8 spring.http.encoding.charset=UTF-8 spring.http.encoding.force=true spring.http.encoding.enabled=true spring.messages.encoding=UTF-8 # tomcat 配置 server.tomcat.accept-count=1000 server.tomcat.max-threads=500 # session超时时间,单位是秒 server.servlet.session.timeout=1800

Builder一个对象

纵饮孤独 提交于 2020-02-26 06:20:25
一般新建对象我们都是直接new一下 public class GirlFriend { private String name; private int age; // 省略 getter & setter ... public static void main(String[] args) { GirlFriend myGirlFriend = new GirlFriend(); myGirlFriend.setName("小美"); myGirlFriend.setAge(18); } } 没问题,老铁!但如果对象的属性太多,咋办? public class GirlFriend { private String name; private int age; private int bust; private int waist; private int hips; private List<String> hobby; // 等等等等 ... // 省略 getter & setter ... public static void main(String[] args) { GirlFriend myGirlFriend = new GirlFriend(); myGirlFriend.setName("小美"); myGirlFriend.setAge(18);

快速开发平台之使用代码生成器分享

妖精的绣舞 提交于 2020-02-26 01:22:22
快速开发平台 是开发人员将各种需要的功能以目前流行的多种web技术,包括springboot, JPA,Druid, Activiti,Lombok,swagger,poi,WebSocket,Jquery,BootStrap, maven,Jenkins 等等 )为基础封装在不同的层中,给大家调用,而大家在调用时不需要清楚这些方法里面是如果实现的,只需要关注输出的结果是否是自己想要的就可以了。 XJR快速开发平台的代码生成器已经把常用的开发场景做成开发模板,按照开发向导一步步走,在遇到有复杂业务逻辑的地方稍作修改就可以。当然XJR快速开发平台提供了源代码,您的开发水平比较高的话可以做深层次的扩展。 快速开发平台可以实现各种业务系统如OA、ERP、MIS、HIS、WMS、CRM、电商平台、app软件开发、工作流引擎等系统开发。一起来看看实例分享。 先来看看自定义开发模板 1、点开菜单快速开发→代码生成器→自定义开发模板 2、选择工作流数据表单,设置表单。 3、调整布局 点击图中的“下一步”进入表单开发界面,可以随意,如图 4、界面设计 调整好整体布局后就可以将左侧的控件直接拖入前面设计好的布局中,然后设置好。完全可视化,拖拽设置就可以实现,操作简单,这里就不详细说明了。 5、设置查询配置 6、设置列表配置 7、设置合计配置 8、输出配置 9、绑定菜单

Json 与 对象 之间的互相转换

不想你离开。 提交于 2020-02-26 00:34:07
本文主要记录如何实现 Json 与 对象 之间的互转操作,使用了 fastjson-1.2.39.jar 包实现: 1、pom 文件: <!--fastjson--> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.39</version> </dependency> 2、实体类: import lombok.Data; import java.util.Date; @Data public class Staff { private String name; private Integer age; private String sex; private Date birthday; } 3、启动类: import com.alibaba.fastjson.JSON; public class test { public static void main(String[] args) { /** * json字符串转化为对象 */ String jsonString = "{name:'Antony','aGe':'12',sex:'male',telePhone:'88888',birthday:123}"; Staff staff = JSON

0216 aop和打印数据库执行日志

扶醉桌前 提交于 2020-02-25 20:34:29
需求 maven依赖 <dependency> <groupId>p6spy</groupId> <artifactId>p6spy</artifactId> <version>3.8.7</version> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>28.2-jre</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> <

How to implements Lombok @Builder for Abstract class

做~自己de王妃 提交于 2020-02-24 04:37:32
问题 I have classes that extend an abstract class and I don't want to put @Builder on top of the all child classes. Is there any way to implement Lombok @Builder for an abstract class? 回答1: Not possible at all. The builder is generated into the super class during compiling and it can not have any knowledge of the possible sub classes that will eventually implement it. For example, the sub class could have constructors that have to be used for the instance to have a valid state and Lombok can not

Jackson deserialization circumventing final fields

删除回忆录丶 提交于 2020-02-23 09:07:12
问题 Here's the code import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.Data; import lombok.ToString; public class Main { public static void main(String[] args) throws Exception { Fields f1 = new Fields(1); System.out.println(f1); ObjectMapper mapper = new ObjectMapper(); String str = mapper.writeValueAsString(f1); System.out.println(str); Fields f2 = mapper.readValue(str, Fields.class); System.out.println(f2); } @Data @ToString