Giter Site home page Giter Site logo

BeanUtil toBean 转换错误 about hutool HOT 6 CLOSED

iszhangsc avatar iszhangsc commented on July 18, 2024
BeanUtil toBean 转换错误

from hutool.

Comments (6)

kissthisrain avatar kissthisrain commented on July 18, 2024

把isUserFollowing字段的get方法名改成isUserFollowing()就可以了,hutool的copy方法的get方法匹配is开头的布尔值字段时,是使用下面这几种格式匹配的
image

from hutool.

iszhangsc avatar iszhangsc commented on July 18, 2024

这个方法名称是使用IDEA自动生成的。 按照你的这个解决办法 我如果后面使用到了 boolean 类型 全都需要自己手动添加 get set 方法?

from hutool.

kissthisrain avatar kissthisrain commented on July 18, 2024

这个方法名称是使用IDEA自动生成的。按照你的这个解决办法 我如果后面使用到了 boolean 类型 全都需要自己手动添加 get set 方法?


首先,是不太建议使用is开头去命名布尔型变量,其次IDEA自动生成的get方法是可以调整模板的
image

from hutool.

iszhangsc avatar iszhangsc commented on July 18, 2024

这样的话,团队的所有人都去进行修改,为什么不按照流行的 spring 这类框架来进行拷贝呢? 是代码历史原因,还是出于什么原因呢?

from hutool.

kissthisrain avatar kissthisrain commented on July 18, 2024

这样的话,团队的所有人都去进行修改,为什么不按照流行的 spring 这类框架来进行拷贝呢? 是代码历史原因,还是出于什么原因呢?


主要是is开头的布尔型变量本身就是不太规范的写法,JSON 序列化也可能会出现问题

from hutool.

looly avatar looly commented on July 18, 2024

@iszhangsc 这里不匹配是因为Hutool存在一个字段和getter匹配检查的功能,这个Spring没有。

在Spring中,只读取getter和setter方法,而不去判断字段,你可以试下,isUserFollowing换成任意名字,Spring也是照样可以的。

image

如果只判断方法而不去匹配字段,就存在误判问题。比如你自定义了一个方法,叫做getXXXX,但是并没有对应字段,那这个方法要不要读取呢?Hutool的策略是不读取。

Spring的方法存在第二个问题,就是假设你有两个字段:isUserFollowinguserFollowing那你的getter方法该如何定义呢?因此,为了解决这些问题,Hutool专门做了字段匹配功能,来避免这些问题。

欢迎进一步讨论。

from hutool.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.