首页 > 移动平台 > 详细

Ambiguous mapping. Cannot map 'appController' method

时间:2019-09-21 11:34:26      阅读:185      评论:0      收藏:0      [点我收藏+]

笔者最初的一套代码模板

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

 

Ambiguous mapping. Cannot map 'appController' method

原文:https://www.cnblogs.com/passedbylove/p/11561326.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!