当前位置:网站首页>Idea sets get and set templates to solve the naming problem of boolean type fields
Idea sets get and set templates to solve the naming problem of boolean type fields
2022-07-25 23:20:00 【weixin_ forty-four million nine hundred and fifty-three thousan】
Excerpt from 【 Alibaba Java Development Manual 】 A specification of
【 mandatory 】POJO Variable of boolean type in class , No more is Prefix , Otherwise, some framework parsing will cause serialization error .
Counter example : Defined as basic data type Boolean isDeleted Properties of , It's the same way isDeleted(),RPC When the framework is parsed in reverse ,“ mistook ” The corresponding property name is deleted, Property cannot be obtained , And throw an exception .
idea Of get、set Template problem
idea edition :IntelliJ IDEA 2020.3 (Ultimate Edition)
idea Automatic generation of get/set Method , For Boolean types, pay great attention to the generated get Method , Because the following problems will occur .
problem 1: The field type is Boolean type , If it is is At the beginning, then get、set Will be removed is
problem 2: The field type is boolean type , Whether or not is At the beginning of it get Methods are isXxx, If it is is At the beginning of his set The method will remove is
If this object involves reflection , Reflection will generally call the object by default get Method , For this is The situation of , Property cannot be obtained , It is possible to throw an exception .
In order to solve my problem, I have prepared two sets get、set The template of , Select a set to use .
Template I
MyGetter This is get Templates
#if($field.modifierStatic)
static ##
#end
$field.type ##
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($field.name))
get##
${name}() {
return $field.name;
}
MySetter This is set Templates
#set($paramName = $field.name)
#if($field.modifierStatic)
static ##
#end
void set$StringUtil.capitalizeWithJavaBeanConvention($field.name)($field.type $paramName) {
#if ($field.name == $paramName)
#if (!$field.modifierStatic)
this.##
#else
$classname.##
#end
#end
$field.name = $paramName;
}
Template II
GetterTemplate This is get Templates
#set($paramName = $helper.getParamName($field, $project))
#if($field.modifierStatic)
static ##
#end
$field.type ##
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project))))
#if ($field.name == $paramName)
get##
#else
getIs##
#end
${name}() {
return $field.name;
}
SetterTemplate This is set Templates
#set($paramName = $helper.getParamName($field, $project))
#if($field.modifierStatic)
static ##
#end
void ##
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project))))
#if ($field.name == $paramName)
set##
#else
setIs##
#end
${name}($field.type $paramName) {
#if (!$field.modifierStatic)
this.##
#else
$classname.##
#end
$field.name = $paramName;
}
How to add a template
The first step is to click get、set

Step 2 Click here to add a template

Step 3 Click + No

边栏推荐
- MVVM model
- How does PHP remove an element from an array based on the key value
- JS regular expression matches IP address (IP address regular expression verification)
- MES系统设备管理概述(下)
- [QNX hypervisor 2.2 user manual]9.6 GDB
- anaconda安装教程环境变量(如何配置环境变量)
- Simulink学习笔记(三)——Simulink自动代码生成(二)「建议收藏」
- Servlet overview
- POI special effects Market Research
- TS basic data type
猜你喜欢

Week 2: convolutional neural network

Data broker understanding

OASYS system of code audit

Dynamic memory management

XxE & XML external entity injection utilization and bypass

Take root downward, grow upward, and explore the "root" power of Huawei cloud AI

VisualBox启动虚拟机报错:The VM session was closed before any attempt to power it on.

The small icon of notification setting shows a small square

File contains vulnerability

Apple CMS V10 template /mxone Pro adaptive film and television website template
随机推荐
推荐系统——An Embedding Learning Framework for Numerical Features in CTR Prediction
Tencent map API request source is not authorized, this request source domain name
WordPress controls the minimum and maximum number of words of article comments
Redis expiration key deletion strategy [easy to understand]
Serialize common default values and column parameters
日期类的实现
Enterprise level inventory management system of code audit
模拟实现string类常用接口
Basic knowledge of radar
网格参数化Least Squares Conformal Maps实现(3D网格映射到2D平面)
How does Navicat modify the language (Chinese or English)?
Which securities firm is the best and safest for beginners to open an account
四旋翼飞行器的飞控实现「建议收藏」
MathType installation and solution cannot solve the problem of crtl+v
行云管家V6.5.1/2/3系列版本发布:数据库OpenAPI能力持续强化
Wechat official account, wechat payment development
Flight control implementation of four rotor aircraft "suggestions collection"
MathType安装和解决不能Crtl+V的问题
WordPress removes the website publishing time
AI chief architect 12 AICA industrial landing analysis under the industrial production process optimization scenario