大佬教程收集整理的这篇文章主要介绍了Micronaut BeanIntrospection 获取记录属性值,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在java中有以下记录。
@Introspected
public record Productviewmodel
(
String ID,@NotBlank(message = ConstantValues.TAG_required)
String title
)
在记录上执行 BeanIntrospection.geTintrospection
后,我可以访问所有 POJO 属性,如下所示
final BeanIntrospection<Productviewmodel> introspection = BeanIntrospection.geTintrospection(Productviewmodel.class);
String[] productviewmodel = introspection.getPropertynames();
productviewmodel
持有记录的所有属性
现在我想为键构造 Multipartbody 作为记录属性,例如
Arrays.stream(productviewmodel).forEach(item -> {
requestbody.addPart(
item,'value');
});
上面的代码将所有的属性名称作为key添加到requestbody中,如何设置从这个API端点接收到的值。 以下是完整代码。
public Maybe<httpResponse<?>> post(Publisher<CompletedfileUpload> files,Productviewmodel model) {
final BeanIntrospection<Productviewmodel> introspection = BeanIntrospection.geTintrospection(Productviewmodel.class);
String[] productviewmodel = introspection.getPropertynames();
return Flowable.frompublisher(files)
.collect(Multipartbody::builder,(requestbody,filE) -> {
requestbody
.addPart("file",file.getfilename(),MediaType.MulTIPART_FORM_DATA_TYPE,file.getBytes());
})
.flatMapMaybe(requestbody -> {
Arrays.stream(productviewmodel).forEach(item -> {
requestbody.addPart(
item,Optional.ofNullable(introspection.getValue(item)).orElse(null).toString());
});
return iProductClIEnt.post(requestbody.build());
});
}
这些值在模型中 post 方法的参数中。现在如何放置值
Arrays.stream(productviewmodel).forEach()
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的Micronaut BeanIntrospection 获取记录属性值全部内容,希望文章能够帮你解决Micronaut BeanIntrospection 获取记录属性值所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。