Java动态地将参数包装到对象中?
在Java中,尤其是在Spring中,如何动态创建对象实例?
String fld = "objAList[4].objB.objCList[5].name";
String fld1 = "objAList[3].objB.objCList[4].name";
String fld2 = "objAList[4].objB.objCList[4].name";
String fld3 = "name";
String fld4 = "objDList[4].name";
String fld5 = "objDList[4].objB.objCList[6].name";
将其视为二维数组,objAList 的第一列,最大索引为 4,那么我们需要为该数组创建 4 个实例。对于 objAList[4].objB,objCList 最大索引为 5,因此为数组创建 5 个实例。
主要用于将http请求参数包装成一个对象。类似于 Struts 动态表单 Bean。
怎么做呢?我们有现有的库吗?
In Java, especially in Spring, how to dynamically create an object instance?
String fld = "objAList[4].objB.objCList[5].name";
String fld1 = "objAList[3].objB.objCList[4].name";
String fld2 = "objAList[4].objB.objCList[4].name";
String fld3 = "name";
String fld4 = "objDList[4].name";
String fld5 = "objDList[4].objB.objCList[6].name";
Think about it as two dimension array, the first column for objAList, the maxium index is 4, then we need to create 4 instances to that array. For objeAList[4].objB, the objCList max index is 5, so create 5 instances to the array.
It is mainly for wrapping the http request parameters into an object. Similar to Struts Dynamic Form Beans.
How to do it? Do we have any existing library for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能 JSON-XStream 可能是一个好的开始......
May JSON-XStream could be an good start....