HTTP Status 405 - JSPs only permit GET POST or HEAD

这两天在看springmvc视频并且手动敲代码时遇见了如下问题,以下是我的代码截图:

package com.wildpointer.springmvc.handlers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloWorld {
	
	private static final String SUCCESS = "success";
	
	
	@RequestMapping(value="/testRest/{id}",method=RequestMethod.PUT)
	public String testRestPut(@PathVariable Integer id){
		System.out.println("testRest Put: "+id);
		return SUCCESS;
	}
	
	
	@RequestMapping(value="/testRest/{id}",method=RequestMethod.DELETE)
	public String testRestDelete(@PathVariable Integer id){
		System.out.println("testRest Delete: "+id);
		return SUCCESS;
	}
	
	@RequestMapping(value="/testRest",method=RequestMethod.POST)
	public String testRest(){
		System.out.println("testRest POST: ");
		return SUCCESS;
	}
	
	@RequestMapping(value="/testRest/{id}",method=RequestMethod.GET)
	public String testRest(@PathVariable Integer id){
		System.out.println("testRest GET: "+id);
		return SUCCESS;
	}
	
	@RequestMapping("/testPathVariable/{id}")
	public String testPathVariable(@PathVariable("id") Integer id ){
		System.out.println("testPathVariable: "+ id);
		return SUCCESS;
	}
	
	@RequestMapping(value="/helloworld")
	public String hello(){
		System.out.println("helloWorld");
		return "success";
	}
}

	
		hiddenHttpMethodFilter
		org.springframework.web.filter.HiddenHttpMethodFilter
	


	
		hiddenHttpMethodFilter
		/*
	




	
		springDispatcherServlet
		org.springframework.web.servlet.DispatcherServlet
		
			contextConfigLocation
			classpath:springmvc.xml
		
		1
	


	
		springDispatcherServlet
		/
	
解决办法:
加入@Responsebody注解即可
@ResponseBody
	@RequestMapping(value="/testRest/{id}",method=RequestMethod.DELETE)
	public String testRestDelete(@PathVariable Integer id){
		System.out.println("testRest Delete: "+id);
		return SUCCESS;
	}

你可能感兴趣的:(spring)