Lomkob引入项目中经常使用bean,entity等类,绝大部分数据类类中都需要get、set、toString、equals和hashCode方法,虽然eclipse和idea开发环境下都有自动生成的快捷方式,但自动生成这些代码后,如果bean中的属性一旦有修改、删除或增加时,需要重新生成或删除get/set等方法,给代码维护增加负担。而使用了lombok则不一样,使用了lombok的注解(@Setter,@Getter,@ToString,@@RequiredArgsConstructor,@EqualsAndHashCode或@Data)之后,就不需要编写或生成get/set等方法,很大程度上减少了代码量,而且减少了代码维护的负担。故强烈建议项目中使用lombok,去掉bean中get、set、toString、equals和hashCode等方法的代码。
<!--[if !supportLists]-->一、 <!--[endif]-->下载lombok
<!--[if !supportLists]-->二、 <!--[endif]-->将Lombok.jar 放在eclipse安装目录下(与eclipse.ini文件平级)
<!--[if !supportLists]-->三、 <!--[endif]-->运行lombok.jar
<!--[if !supportLists]-->a) <!--[endif]-->运行后会弹框如下框,直接点确定
<!--[if gte vml 1]><v:shapetype
id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t"
path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f">
<v:stroke joinstyle="miter"/>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0"/>
<v:f eqn="sum @0 1 0"/>
<v:f eqn="sum 0 0 @1"/>
<v:f eqn="prod @2 1 2"/>
<v:f eqn="prod @3 21600 pixelWidth"/>
<v:f eqn="prod @3 21600 pixelHeight"/>
<v:f eqn="sum @0 0 1"/>
<v:f eqn="prod @6 1 2"/>
<v:f eqn="prod @7 21600 pixelWidth"/>
<v:f eqn="sum @8 21600 0"/>
<v:f eqn="prod @7 21600 pixelHeight"/>
<v:f eqn="sum @10 21600 0"/>
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
<o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="图片_x0020_1" o:spid="_x0000_i1048" type="#_x0000_t75"
style='width:415.5pt;height:240pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
<!--[if !supportLists]-->b) <!--[endif]-->点specify location 按钮,选择eclipse的安装目录,选择到eclipse层即可
<!--[if gte vml 1]><v:shape id="图片_x0020_2"
o:spid="_x0000_i1047" type="#_x0000_t75" style='width:414.75pt;height:176.25pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image003.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
<!--[if !supportLists]-->c) <!--[endif]-->点击Install/update按钮
<!--[if gte vml 1]><v:shape id="图片_x0020_4"
o:spid="_x0000_i1046" type="#_x0000_t75" style='width:415.5pt;height:240pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image005.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
<!--[if !supportLists]-->d) <!--[endif]-->查看eclipse.ini文件,如果在文件末端添加了-javaagent:D:\soft\eclipse\lombok.jar那么恭喜你安装成功了
<!--[if gte vml 1]><v:shape id="图片_x0020_5" o:spid="_x0000_i1045"
type="#_x0000_t75" style='width:414.75pt;height:189.75pt;visibility:visible;
mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image007.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
D:\soft\eclipse\lombok.jar为lombok所在路径
<!--[if !supportLists]-->四、 <!--[endif]-->重启Eclipse
<!--[if !supportLists]-->五、 <!--[endif]-->编写实体类(以下提供常用实体类比较)
<!--[if gte vml 1]><v:shape id="图片_x0020_6"
o:spid="_x0000_i1044" type="#_x0000_t75" style='width:415.5pt;height:181.5pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image009.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
等同于
<!--[if gte vml 1]><v:shape id="图片_x0020_8"
o:spid="_x0000_i1043" type="#_x0000_t75" style='width:318.75pt;height:493.5pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image011.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
<!--[if gte vml 1]><v:shape id="图片_x0020_9"
o:spid="_x0000_i1042" type="#_x0000_t75" style='width:224.25pt;height:208.5pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image012.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
等同于
<!--[if gte vml 1]><v:shape id="图片_x0020_10"
o:spid="_x0000_i1041" type="#_x0000_t75" style='width:415.5pt;height:518.25pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image013.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
<!--[if gte vml 1]><v:shape id="图片_x0020_12"
o:spid="_x0000_i1040" type="#_x0000_t75" style='width:268.5pt;height:215.25pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image015.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
等同于
<!--[if gte vml 1]><v:shape id="图片_x0020_11"
o:spid="_x0000_i1039" type="#_x0000_t75" style='width:414.75pt;height:491.25pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image016.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
<!--[if !supportLists]-->六、 <!--[endif]-->Lombok常用注解解释
a)、@NonNull
这个注解可以用在成员方法或者构造方法的参数前面,会自动产生一个关于此参数的非空检查,如果参数为空,则抛出一个空指针异常。举个例子看一下
<!--[if gte vml 1]><v:shape
id="图片_x0020_14" o:spid="_x0000_i1038" type="#_x0000_t75" style='width:188.25pt;
height:129.75pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image018.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
等同于
<!--[if gte vml 1]><v:shape
id="图片_x0020_15" o:spid="_x0000_i1037" type="#_x0000_t75" style='width:290.25pt;
height:167.25pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image019.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
@Cleanup
用在变量前面,可以保证此变量代表的资源会被自动关闭,默认是调用资源的close()方法,如果该资源有其它关闭方法,可使用@Cleanup(“methodName”)来指定要调用的方法。使用输入输出流举个例子
<!--[if gte vml 1]><v:shape id="图片_x0020_16"
o:spid="_x0000_i1036" type="#_x0000_t75" style='width:405pt;height:279pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image020.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
等同于
<!--[if gte vml 1]><v:shape id="图片_x0020_17"
o:spid="_x0000_i1035" type="#_x0000_t75" style='width:415.5pt;height:407.25pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image021.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
@Getter
用在变量前面,用于生成get方法,同时对相应方法进行修饰符配置
<!--[if gte vml 1]><v:shape id="图片_x0020_18"
o:spid="_x0000_i1034" type="#_x0000_t75" style='width:278.25pt;height:147pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image023.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
等同于
<!--[if gte vml 1]><v:shape id="图片_x0020_19"
o:spid="_x0000_i1033" type="#_x0000_t75" style='width:321.75pt;height:173.25pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image024.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
@Setter
用在变量前面,用于生成set方法,同时对相应方法进行修饰符配置
@ToString
用在类前面,用于生成toString方法
<!--[if gte vml 1]><v:shape id="图片_x0020_20"
o:spid="_x0000_i1032" type="#_x0000_t75" style='width:245.25pt;height:130.5pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image025.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
等同于
<!--[if gte vml 1]><v:shape id="图片_x0020_21"
o:spid="_x0000_i1031" type="#_x0000_t75" style='width:260.25pt;height:137.25pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image026.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
@EqualsAndHashCode
用于类前面,生成类的equals以及hashCode方法
<!--[if gte vml 1]><v:shape id="图片_x0020_23"
o:spid="_x0000_i1030" type="#_x0000_t75" style='width:300.75pt;height:136.5pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image027.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
等同于
<!--[if gte vml 1]><v:shape id="图片_x0020_22"
o:spid="_x0000_i1029" type="#_x0000_t75" style='width:291.75pt;height:180.75pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image028.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
@NoArgsConstructor
参考五、编写实体类(以下提供常用实体类比较)
@AllArgsConstructor
参考五、编写实体类(以下提供常用实体类比较)
@Data
参考五、编写实体类(以下提供常用实体类比较)
@SneakyThrows
用在方法上,可以将方法中的代码用try-catch语句包裹起来,捕获异常并在catch中用Lombok.sneakyThrow(e)把异常抛出,可以使用@SneakyThrows(Exception.class)的形式指定抛出哪种异常
<!--[if gte vml 1]><v:shape id="图片_x0020_24"
o:spid="_x0000_i1028" type="#_x0000_t75" style='width:415.5pt;height:231.75pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image029.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
等同于
<!--[if gte vml 1]><v:shape id="图片_x0020_25"
o:spid="_x0000_i1027" type="#_x0000_t75" style='width:348pt;height:283.5pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image031.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
@Synchronized
用在类方法或者实例方法上,效果和synchronized关键字相同
@Log
用在类上,可以省去从日志工厂生成日志对象这一步,直接进行日志记录,具体注解根据日志工具的不同而不同,同时,可以在注解中使用topic来指定生成log对象时的类名。
<!--[if gte vml 1]><v:shape id="图片_x0020_27" o:spid="_x0000_i1026"
type="#_x0000_t75" style='width:408.75pt;height:156.75pt;visibility:visible;
mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image032.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
等同于
<!--[if gte vml 1]><v:shape id="图片_x0020_28" o:spid="_x0000_i1025"
type="#_x0000_t75" style='width:415.5pt;height:219pt;visibility:visible;
mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\db.xie\AppData\Local\Temp\msohtmlclip1\01\clip_image033.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
由于日志工具的不同,所等价的代码也不尽相同,一下列举常用日志工具的对比
@CommonsLog =
privatestaticfinal org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(LogExample.class);
@JBossLog =
privatestaticfinal org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LogExample.class);
@Log =
privatestaticfinal java.util.logging.Logger log = java.util.logging.Logger.getLogger(LogExample.class.getName());
@Log4j =
privatestaticfinal org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(LogExample.class);
@Log4j2 =
privatestaticfinal org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager.getLogger(LogExample.class);
@Slf4j =
privatestaticfinal org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LogExample.class);
@XSlf4j =
privatestaticfinal org.slf4j.ext.XLogger log = org.slf4j.ext.XLoggerFactory.getXLogger(LogExample.class);
相关推荐
一款基于机器学习的Web日志统计分析与异常检测命令行工具_hy4
基于RBAC权限控制的资产管理系统_hy5
318 Series Hardened Access Points 370 Series Outdoor Access Points 310 Series Campus Access Points IAP-315 IAP-314
最强PMP备考计划、知识整理、试题,并以本系统来展示_hy5
【官方】计算机职业英语一级考试样卷.pdf 【官方】全国机等级考试二级笔试样卷:存取(Access)数据库程序设计.pdf 【官方】全国计算机等级考试二级笔试样卷:C++语言程序设计.pdf 【官方】全国计算机等级考试二级笔试样卷:C语言程序设计.pdf 【官方】全国机等级考试二级笔试样卷:德尔菲(Delphi)语言程序设计.pdf 【官方】全国机等级考试二级笔试样卷:Java语言程序设计.pdf 【官方】全国机等级考试二级笔试样卷:视觉基础语言程序设计.pdf 【官方】全国机等级考试二级笔试样卷:视讯FoxPro数据库程序设计.pdf 【官方】全国计算机等级考试三级笔试样卷:PC技术,pdf 【官方】全国计算机等级考试三级笔试样卷:网络技术.pdf 【官方】全国计算机等级考试三级笔试样卷:信息管理技术,pdf 【官方】全国计算机等级考试四级笔试样卷:软件测试工程师.pdf 【官方】全国计算机等级考试四级笔试样卷:数据库工程师,pdf 【官方】全国计算机等级考试四级笔试样卷:数据库技术,pdf 【官方】全国计算机等级考试四级笔试样卷:网络工程师.pdf
SpringBoot网上商城#java#毕业设计#网上商城#springboot#课程设计#编程#thymeleaf_hy4
1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
360 Series Outdoor Access Points 303 Series Campus Access Points 303H Series Hospitality Access Points 300 Series Campus Access Points
肽质量指纹图谱提取区域检测系统源码分享[一条龙教学YOLOV8标注好的数据集一键训练_70+全套改进创新点发刊_Web前端展示]
分布式事务实战_hy4
python网络爬虫按月爬cctv新闻30分的视频_hy4
【golang】企业微信群机器人接口Golang封装
1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。
mumu-activemq是一个对老牌mq消息中间件的学习和测试项目,本人通过这个项目来熟悉activemq的消息发送流_hy4
【Python+HTML】基于flask的rbac学生权限管理系统,redis存储session_pgj
一步一步学springboot2:微服务项目实战(第二版)_hy5
1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。
新建 DOC 文档.doc