gpt4 book ai didi

java - Lombok @Data 注释将字段名称从 isood 更改为 good

转载 作者:行者123 更新时间:2023-12-02 02:31:26 24 4
gpt4 key购买 nike

我有这个 DTO,它使用 lombok@Data 注释来生成 getterssetters:

@Data
public class SomeDto {

protected boolean isGood;
}

奇怪的是,现在我的 getter 已从 getisGood() 重命名为 isGood() 并且 setter 的名称为 setGood() code> 而不是 setIsGood()。示例:

SomeDto somedto = new SomeDto()
somedto.setGood(false) //sets the value to false - should have been setIsGood
somedto.isGood() //return false - should have been getIsGood

此外,当我在 JSON 返回中使用此 DTO 的端点上发出请求时:

{"good": false}

而应该是:

{"isGood": false}

有人知道问题出在哪里吗?我怀疑 isGood 开头的“is”可能会给 lombok 带来困惑。感谢您提供的任何帮助。

最佳答案

我猜约定是对于 boolean 值,getter 称为 isGood,而 setter 称为 setGood。因此,您的 boolean 值预计将被称为“good”。

Here is one discussion

也在文档中:)

 lombok.getter.noIsPrefix = [true | false] (default: false)
If set to true, getters generated for boolean fields will use the get prefix instead of the defaultis prefix, and any generated code that calls getters, such as @ToString, will also use get instead of is

Docs

关于java - Lombok @Data 注释将字段名称从 isood 更改为 good,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64982580/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com