为了账号安全,请及时绑定邮箱和手机立即绑定

从不使用带有 @RequestMapping 的类

从不使用带有 @RequestMapping 的类

守候你守候我 2021-12-18 15:16:03
我正在尝试使用此视频示例(小心,俄语语音)编写 REST 服务器。在示例中,当讲师在控制器类上方编写 @RequestMapping 时,类将被使用。但在我的情况下,控制器类“从未使用过”,当我用我的控制器启动 tomcat 服务器并进入页面http://localhost:8000/app/remind/get 时,我收到这个错误:没有映射 GET /应用程序/提醒/获取这是我的控制器代码:@Controller@RequestMapping("/reminder")public class ReminderController {    @RequestMapping(value = "/get", method = RequestMethod.GET)    @ResponseBody    public String getReminder(){        return "my reminder";    }}这是我的 WebConfig.java@Configuration @EnableWebMvc@ComponentScan("com.fillooow.remindme.server")public class WebConfig extends WebMvcConfigurerAdapter {}那么,你能解释一下,为什么我的课程“从未使用过”,我错过了什么?编辑 我的问题是配置文件中的错误上下文(“/”而不是“/app”)
查看完整描述

2 回答

?
富国沪深

TA贡献1790条经验 获得超9个赞

建议:试试@GetMapping; 确保您使用的是正确的 URL:


@Controller

@RequestMapping("/reminder")

public class ReminderController {


    @GetMapping(value = "/get")

    @ResponseBody

    public String getReminder(){

        return "my reminder";

    }

}

... 和 ...


http://localhost:8000/app/reminder/get

另外:我不确定您的上下文根(“应用程序”)或您的端口(“8000”与“8080”)。


可能的选择:


http://localhost:8080/reminder/get

附加建议:启用调试


logging.level.org.springframework=DEBUG


查看完整回答
反对 回复 2021-12-18
?
慕运维8079593

TA贡献1876条经验 获得超5个赞

尝试如下端点

 http://localhost:8000/reminder/get


查看完整回答
反对 回复 2021-12-18
  • 2 回答
  • 0 关注
  • 208 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号