@PathVariable(value = "userName") String userName 这东西怎么用啊 为什么我每次用都
java.lang.IllegalStateException: Could not find @PathVariable [userName] in @RequestMapping

解决方案 »

  1.   

    他是作为方法的参数的注解,你不能放在RequestMapping注解中。
      

  2.   

    @RequestMapping()
           public String register(@PathVariable(value = "userName") String userName) {
    ModelAndView mav = new ModelAndView();
    return "user/createSuccess";
    }
      

  3.   

    @PathVariable 会将url中的参数解析到对应的方法参数上,需要在@RequestMapping()指定匹配模式
    @RequestMapping("somepath/{userName}")
    这时你访问地址"somepath/Tom"就能把"Tom"解析到方法参数userName上
      

  4.   

     @RequestMapping("/somepath/{userName}")
        public String register(@PathVariable(value = "userName") String userName) {
            //Todo somesing
            return "/simigoods";
        }
      

  5.   

        private static final Logger log = Logger.getLogger(Control.class);
        @Autowired
        private Service service;
        @RequestMapping(value = "/simigoods", method = RequestMethod.GET)
        public ModelAndView getSimigoods(){
            List<Model> simigoodsList = service.getData();
            ModelAndView view = new ModelAndView();
            view.setViewName("manage");
            view.addObject("simigoodsList", simigoodsList);
            view.addObject("simigoodsname", "Simigoods");
            log.info("Simigoods执行了");
            return view;
        }
        @RequestMapping(value = "/json", method = RequestMethod.GET)
        @ResponseBody
        //String hello(@RequestParam(value = "userid") int id),这样会把地址栏参数名为userid的值赋给参数id,如果用地址栏上的参数名为id,则接收不到
        public String aaa(@RequestParam(value = "id",required=false,defaultValue = "") String id,@RequestParam(value = "callback",required=false,defaultValue = "") String callback){        return "hello word"+id+callback;
        }
        @RequestMapping("/somepath/{userName}")
        public String register(@PathVariable(value = "userName") String userName) {
            ModelAndView mav = new ModelAndView();
            mav.setViewName("manage");
            //Todo somesing
            return "/simigoods";
        }
      

  6.   

    @RequestMapping(url/{id})
    public void method01(@PathVariable Integer id){
    ...
    }