当前位置:网站首页>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
边栏推荐
- Google Earth Engine(GEE)——GHSL 全球人口网格数据集250米分辨率
- The role and necessity of implementing serializable interface
- [proteus simulation] 16 channel water lamp composed of 74hc154 four wire to 12 wire decoder
- sqlmap基本使用方法
- one hot 独热码
- What experience is there only one test in the company? Listen to what they say
- Clion debug
- Summary of the history of Mathematics
- 最高月薪18K 拥有好的“心态和选择”, 成功就差“认真和坚持”~
- Qt:qss custom qheaderview instance
猜你喜欢

Error installing the specified version of pilot

你真的需要自动化测试吗?

Lecture 1 number field

游戏测试相关 测试一个英雄的技能(春招被问比较多的一道题)

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

snownlp情感分析

Expandablelistview that can expand and shrink (imitating the list page of professional selection of Zhilian recruitment)

QT: QSS custom qtreeview instance

那些一门心思研究自动化测试的人,后来怎样了?

What kind of living condition is a tester with a monthly salary of more than 10000?
随机推荐
BI技巧丨权限轴
Do you really need automated testing?
11. Provider service registration of Nacos service registration source code analysis
Programming examples of stm32f1 and stm32subeide -tm1637 drives 4-bit 7-segment nixie tubes
Solutions of n-ary linear equations and their criteria
Is pinduogai's sales safe in 2022?
测试Leader应该做哪些事
Qt:qss custom qgroupbox instance
TypeScript学习总结
QT: QSS custom qtreeview instance
snownlp情感分析
搭建ADG后,实例2无法启动 ORA-29760: instance_number parameter not specified
现在零基础转行软件测试还OK吗?
What happened to those who focused on automated testing?
IIS修改配置信息后不生效
硬 货 | 一改测试步骤代码就全写?为什么不试试用 Yaml实现数据驱动?
Qt:qss custom QSlider instance
"Core values of testing" and "super complete learning guide for 0 basic software testing" summarized by test engineers for 8 years
数据库增量备份 - DB INCR DB FULL
QT: QSS custom qtableview instance