Announcement Announcement Module
Collapse
No announcement yet.
passing an array of integers as a paramter to controller Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • passing an array of integers as a paramter to controller

    Hello. I have big project on spring 3.0.2 and want upgrade to spring 3.1.3. But there is little problem.

    Code:
    @Controller
    public class IndexController{
        @RequestMapping("index7")
        public ModelAndView index7(@RequestParam(value="arr", required=true) Integer[] arr){
            return new ModelAndView("index", "test", "arr="+Arrays.asList(arr));
        }
    }
    In spring 3.0.2 calling http://localhost:8080/pp/index7.htm?arr= gives arr=[null]. In spring 3.1.3 arr=[].
    Calling http://localhost:8080/pp/index7.htm?arr=&arr= and more arguments gives identically [null, null] in both versions
    Is it possible to configure spring 3.1.3 like 3.0.2 for this situation? or some binders? or something else?

  • #2
    Problem resolved by aspect

    Code:
    import org.aspectj.lang.ProceedingJoinPoint;
    import org.aspectj.lang.annotation.Around;
    import org.aspectj.lang.annotation.Aspect;
    import org.springframework.stereotype.Component;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @Component
    @Aspect
    public class RepairParametersAspect {
        
        @Around("execution(@org.springframework.web.bind.annotation.RequestMapping * *(..))")
        public Object callMethod(ProceedingJoinPoint pjp) throws Throwable{
            Object[] args = pjp.getArgs();
            for(int i=0;i<args.length;i++){
                if(args[i] instanceof Integer[] && ((Integer[])args[i]).length==0 ){
                    args[i] = new Integer[]{null};
                } else if(args[i] instanceof Double[] && ((Double[])args[i]).length==0 ){
                    args[i] = new Double[]{null};
                } else if(args[i] instanceof String[] && ((String[])args[i]).length==0 ){
                    args[i] = new String[]{null};
                }
            }
            return pjp.proceed(args);
        }
        
    }

    Comment


    • #3
      Originally posted by dianneazuma54
      I have question based on vb6 pragraming language?


      computer training videos
      I don't understand what do you mean

      Comment

      Working...
      X