宇筱博客

  • 解决办法
  • 学无止境
  • 记录时光
  • 百宝箱
宇筱博客
点滴记忆,汇聚成海。
  1. 首页
  2. 解决办法
  3. 正文

Ambiguous mapping. Cannot map 'appController' method

2021年1月2日 49点热度 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;
    }
}

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

Post Views: 104
标签: 暂无
最后更新:2021年1月2日

小渔民

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2023 渔人码头. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

豫ICP备15017825号-2