疑惑 get可用,post出现405--The method received in the request-line is known by the origin server but not supported by the target resource.
package com.noma.springmvc.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; /** * @Author:wenjie * @Version:1.0 * @Date:2022/2/23-22:37 * @Since:jdk1.8 * @Description: */ //使我们这个controller可以接收,处理多个请求,并且可以定义多个方法 @Controller public class MyController { @RequestMapping("/aaa") public ModelAndView hello(){ ModelAndView modelAndView = new ModelAndView(); modelAndView.addObject("msg","优化springmvc"); modelAndView.setViewName("success"); return modelAndView; } @RequestMapping("/bbb") public ModelAndView bbbRequest(){ ModelAndView modelAndView = new ModelAndView(); modelAndView.addObject("msg","优化springmvc!!!!!"); modelAndView.setViewName("success"); return modelAndView; } @RequestMapping(value = "/get",method = RequestMethod.GET) public ModelAndView getRequest(){ ModelAndView modelAndView = new ModelAndView(); modelAndView.addObject("msg","优化springmvc!!!!!"); modelAndView.setViewName("success"); return modelAndView; } @RequestMapping(value = "/post",method=RequestMethod.POST) public ModelAndView postRequest(){ ModelAndView modelAndView = new ModelAndView(); modelAndView.addObject("msg","post请求"); modelAndView.setViewName("success"); return modelAndView; } }
jsp
<%-- Created by IntelliJ IDEA. User: Administrator Date: 2022/2/23 Time: 10:18 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <h1 style="background-color: aqua">我是成功页面~~~~~~</h1> ${msg} </body> </html>
解决方案:
???