We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
假设我有一个VO对象,它有一个属性为private List<OrderDetail> orderDetailList;,如果我不对它赋初值,那么返回给前端,前端会收到orderDetailList: null。但是我又和前端约定好,即使orderDetailList里面没有数据也至少要返回一个空数组。要满足这个需求,我就不得不为这个属性赋一个初值private List<OrderDetail> orderDetailList = new ArrayList<>();。因此我觉得规约1.4.9不太合理,应去掉。
private List<OrderDetail> orderDetailList;
orderDetailList: null
private List<OrderDetail> orderDetailList = new ArrayList<>();
The text was updated successfully, but these errors were encountered:
@yangguanbao 帮忙看一下
Sorry, something went wrong.
我觉得你提的这个是不合理的,无逻辑的模型自带了初始化逻辑,本身就说不通的,这和在模型中声明int ..等基数据类型并无本质的区别。这个问题只是只要配置一下json的序列化就好了。
。但是我又和前端约定好,即使orderDetailList里面没有数据也至少要返回一个空数组。
—— 约好,可以重新约定一下。
另外,默认值不予设定,是因为默认值往往在数据库更新,或者数据传输时没有赋值,导致保存到数据库或者数据接收方取到默认值。
同意你的说法,既然是和前端约定好的,如果是JSON序列化的,就可以在JSON序列化方案中去配置。如果是其他方案的话,就应该在返回前set一个你和前端约定好的值进去。这样直接写的初始值会给排错造成难度。
No branches or pull requests
假设我有一个VO对象,它有一个属性为
private List<OrderDetail> orderDetailList;
,如果我不对它赋初值,那么返回给前端,前端会收到orderDetailList: null
。但是我又和前端约定好,即使orderDetailList里面没有数据也至少要返回一个空数组。要满足这个需求,我就不得不为这个属性赋一个初值private List<OrderDetail> orderDetailList = new ArrayList<>();
。因此我觉得规约1.4.9不太合理,应去掉。The text was updated successfully, but these errors were encountered: