unable to bind data using spring data functionality

后端 未结 1 1365
孤城傲影
孤城傲影 2021-01-16 00:41

Thread is in continuation of sending-data-back-to-controller-spring-mvc

I am working on a product detail page where I need to show user some options and user will se

相关标签:
1条回答
  • 2021-01-16 01:24

    the LazyMap factory has to return a LazyList.

    the given factory FactoryUtils.instantiateFactory(PrsCDData.class) creates a new PrsCDData object rather than a List of PrsCDData.

    prsCDData['Forced'] -> if exists then return it else create instance of PrsCDData.class
    

    should be

    prsCDData['Forced'] -> if exists then return it else create instance of LazyList<PrsCDData>
    

    use LazyList since you immediately want to access index '0' what leads to a ArrayIndexOutOfBoundsExecption otherwise

    EDIT: Simple example

    public class Test {
    
    @SuppressWarnings("unchecked")
    public static void main(String[] args) throws UnsupportedEncodingException {
    
        Map<String, List<SimpleBean>> map = MapUtils.lazyMap(new HashMap<String,List<Object>>(),new Factory() {
    
            public Object create() {
                return LazyList.decorate(new ArrayList<SimpleBean>(), FactoryUtils.instantiateFactory(SimpleBean.class));
            }
        });
    
        System.out.println(map.get("test").get(0));
    }
    
    public static class SimpleBean {
        private String name;
    }
    
    }
    
    0 讨论(0)
提交回复
热议问题