• Ambiguous mapping. Cannot map 'appController' method


    笔者最初的一套代码模板

    import lombok.extern.slf4j.Slf4j;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    import java.util.Map;
    
    @Controller
    @Slf4j
    @RequestMapping("app/*")
    public class AppController {
    
        @RequestMapping("list")
        public String list(Model model)
        {
            return "open/app/list";
        }
    
        @RequestMapping(name = "list", method = RequestMethod.POST)
        public String list(Model model, String keyword)
        {
            return "open/app/list";
        }
    
        @RequestMapping("create")
        public String create(Model model)
        {
            return "open/app/editor";
        }
    
        @RequestMapping(name = "view")
        public String view(Model model,Integer id)
        {
            return "open/app/editor";
        }
    
        @RequestMapping(name = "save", method = RequestMethod.POST)
        @ResponseBody
        public Map<String,Object> saveApp()
        {
            return null;
        }
    
    
        @RequestMapping(name = "update" ,method = RequestMethod.POST)
        @ResponseBody
        public Map<String,Object> update()
        {
            return null;
        }
    }

    注意标红加粗的地方。

    然后又把这个文件复制了一遍重命名,为OrderController,然后就报错了。

    最终发现原因是把@RequestMapping里面的参数填写错误,把name改成value

    正确代码如下

    import lombok.extern.slf4j.Slf4j;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    import java.util.Map;
    
    @Controller
    @Slf4j
    @RequestMapping("app/*")
    public class AppController {
    
        @RequestMapping("list")
        public String list(Model model)
        {
            return "open/app/list";
        }
    
        @RequestMapping(value = "list", method = RequestMethod.POST)
        public String list(Model model, String keyword)
        {
            return "open/app/list";
        }
    
        @RequestMapping("create")
        public String create(Model model)
        {
            return "open/app/editor";
        }
    
        @RequestMapping(value = "view")
        public String view(Model model,Integer id)
        {
            return "open/app/editor";
        }
    
        @RequestMapping(value = "save", method = RequestMethod.POST)
        @ResponseBody
        public Map<String,Object> saveApp()
        {
            return null;
        }
    
    
        @RequestMapping(value = "update" ,method = RequestMethod.POST)
        @ResponseBody
        public Map<String,Object> update()
        {
            return null;
        }
    }
  • 相关阅读:
    js中null " "的区别
    简略的地图API应用
    JSON的一个例子(代码来源于网上)
    浅谈Event Flow、Process、Method及其Applications
    JS中object与constructor的分析
    浅谈for...in与for....of
    浅谈语言的过去与未来
    正则表达式的四个小应用
    BOM详细
    BOM
  • 原文地址:https://www.cnblogs.com/passedbylove/p/11561326.html
Copyright © 2020-2023  润新知