前言
今天在看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這個前綴了。
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态