当前位置:网站首页>Kotlin's use of the no Arg compiler plug-in in gradle
Kotlin's use of the no Arg compiler plug-in in gradle
2022-07-03 11:09:00 【Lindroy】
1、 Preface
Recently in use Kotlin+Spring Boot Write a backend project , Entity classes habitually use Kotlin Medium data class, however Spring Requires a parameterless constructor , Otherwise you might throw it java.sql.SQLDataException. To make data class Can generate a parameterless constructor , There are two ways to do :
1. to data class Each parameter in the constructor of is assigned a default value . such as :
data class User(
@TableId(value = "id", type = IdType.AUTO)
var id: Int?=-1,
var userName: String?=null, // user name
var age: Int?=null, // Age
var password: String?=null, // password
var name: String?=null, // full name
var email: String?=null // mailbox
) : Serializable
2. Use the parameterless compiler plug-in no-arg. Let's take a look at this method .
2、 Specific steps
2.1 Add plug-in dependencies
First of all, it needs to be carried out at the beginning of the project build.gradle Add no-arg Plug in dependency , Version follows Kotlin Consistent versions of :
plugins {
……
id "org.jetbrains.kotlin.plugin.noarg" version "1.3.41"
}
I use it plugins In the form of , If you're using buildscript Blocks can be added in this way :
buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-noarg:1.3.41"
}
}
apply plugin: "kotlin-noarg"
2.2 Specify the nonparametric annotation list
Tell the truth , This step is not easy to understand when reading official documents , Here I only describe my experience after my own practice . First create an annotation class , We can define the class name as NoArg:
annotation class NoArg
Then the most critical step came , Back to engineering build.gradle file , Add a list of nonparametric comments :
noArg {
annotation("com.lindroid.projectname.annotation.NoArg")
}
annotation The path in is what we created NoArg The package directory where the annotation class is located . The path must be written well , Don't make mistakes ! At this point, the parameterless plug-in has been configured . We can do it in data class Add @NoArg annotation , In this way, the compiler can generate a parameterless constructor for it . An example is as follows :
@NoArg
data class User(
@TableId(value = "id", type = IdType.AUTO)
var id: Int?,
var userName: String?, // user name
var age: Int?, // Age
var password: String?, // password
var name: String?, // full name
var email: String? // mailbox
) : Serializable
2.3 kotlin-jpa Nonparametric annotation in
If you have added kotlin-jpa plug-in unit , Basically, there is no need to add a parameterless plug-in alone .kotlin-jpa The plug-in without parameters is packaged , When you use @Entity、@Embeddable And @MappedSuperclass These notes , By default, no Parameter annotation is supported .
3、 Reference article
边栏推荐
- 我,大厂测试员,降薪50%去国企,后悔了...
- Programming examples of stm32f1 and stm32subeide -tm1637 drives 4-bit 7-segment nixie tubes
- Definition and properties of summation symbols
- Basic usage of sqlmap
- 线性表的双链表
- Snownlp emotion analysis
- Qt:qss custom QSlider instance
- Matlab memory variable management command
- Google Earth Engine(GEE)——GHSL 全球人口网格数据集250米分辨率
- 软件测试必学基本理论知识——APP测试
猜你喜欢

我对测试工作的一些认识(资深测试人员总结)

Software testing redis database

Overview of testing theory

(二)进制

软件测试工程师的5年之痒,讲述两年突破瓶颈经验

Lecture 1 number field

可以写进简历的软件测试电商项目,不进来get一下?
![[true question of the Blue Bridge Cup trials 44] scratch eliminate the skeleton Legion children programming explanation of the true question of the Blue Bridge Cup trials](/img/e0/c2b1fbe99939d44201401abf1b5a72.png)
[true question of the Blue Bridge Cup trials 44] scratch eliminate the skeleton Legion children programming explanation of the true question of the Blue Bridge Cup trials

“测试人”,有哪些厉害之处?

Qt:qss custom qscrollbar instance
随机推荐
The highest monthly salary of 18K has a good "mentality and choice", and success is poor "seriousness and persistence"~
POI excel 单元格换行
历经一个月,终于拿到金蝶Offer!分享一下四面面经+复习资料
使用ML.NET+ONNX预训练模型整活B站经典《华强买瓜》
Comment réaliser des tests automatisés pour les tests logiciels embarqués?
使用onvif协议操作设备
值得关注的15种软件测试趋势
有些能力,是工作中学不来的,看看这篇超过90%同行
IIS修改配置信息后不生效
Solve the problem that pycharm Chinese input method does not follow
T5 attempt
Qt:qss custom qmenubar instance
After 8 years of industry thinking, the test director has a deeper understanding of test thinking
如何清理v$rman_backup_job_details视图 报错ORA-02030
"Core values of testing" and "super complete learning guide for 0 basic software testing" summarized by test engineers for 8 years
Some abilities can't be learned from work. Look at this article, more than 90% of peers
Win10系统下提示“系统组策略禁止安装此设备”的解决方案(家庭版无组策略)
Flink-- custom function
公司测试部门来了个00后卷王之王,老油条感叹真干不过,但是...
线性表顺序表综合应用题P18