access control allow origin,accessors 作用_@Accessors介紹配置getter和setter

 2023-10-04 阅读 28 评论 0

摘要:前言今天在看GitHub某大神寫的代碼的時候看到一個標簽并沒有使用過,所有百度了一下使用方法在此記錄一下。@AccessorsAccessor的中文含義是存取器,@Accessors用于配置getter和setter方法的生成結果。源代碼:access control allow origin?@T

前言

今天在看GitHub某大神寫的代碼的時候看到一個標簽并沒有使用過,所有百度了一下使用方法在此記錄一下。

@Accessors

Accessor的中文含義是存取器,@Accessors用于配置getter和setter方法的生成結果。

源代碼:

access control allow origin?@Target({ElementType.TYPE, ElementType.FIELD})

@Retention(RetentionPolicy.SOURCE)

public @interface Accessors {

/**

* If true, accessors will be named after the field and not include a {@code get} or {@code set}

* prefix. If true and {@code chain} is omitted, {@code chain} defaults to {@code true}.

accesscontrolalloworigin 區別?* default: false

*

* @return Whether or not to make fluent methods (named {@code fieldName()}, not for example {@code setFieldName}).

*/

boolean fluent() default false;

/**

getter和setter方法,* If true, setters return {@code this} instead of {@code void}.

* default: false, unless {@code fluent=true}, then default: true

*

* @return Whether or not setters should return themselves (chaining) or {@code void} (no chaining).

*/

boolean chain() default false;

access control allow origin 配置、/**

* If present, only fields with any of the stated prefixes are given the getter/setter treatment.

* Note that a prefix only counts if the next character is NOT a lowercase character or the last

* letter of the prefix is not a letter (for instance an underscore). If multiple fields

* all turn into the same name when the prefix is stripped, an error will be generated.

*

Mysql、* @return If you are in the habit of prefixing your fields (for example, you name them {@code fFieldName}, specify such prefixes here).

*/

String[] prefix() default {};

}

此注解可以使用在方法上還有類上。

可以看到一共有3個屬性,下面單獨記錄一下各個屬性區別。

string、chain

chain的中文含義是鏈式的,設置為true,則setter方法返回當前對象.

fluent

fluent的時候:getter和setter方法的方法名都是基礎屬性名,且setter方法返回當前對象。生成的方法沒有get/set名字。

prefix

生成getter和setter方法的字段名會忽視指定前綴。可以看到生產的方法中沒有job這個前綴了。

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/113048.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息