Results 1 to 3 of 3

Thread: passing an array of integers as a paramter to controller

  1. #1
    Join Date
    Nov 2012
    Posts
    4

    Default 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. #2
    Join Date
    Nov 2012
    Posts
    4

    Default

    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);
        }
        
    }

  3. #3
    Join Date
    Nov 2012
    Posts
    4

    Default

    Quote Originally Posted by dianneazuma54 View Post
    I have question based on vb6 pragraming language?


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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •