SpringMVC 注解(四) pathVariable,ResponseStatus

版权声明:本文为博主原创文章,未经博主允许不得转载 https://blog.csdn.net/kzcming/article/details/80764179

@pathVariable

将uri模板中的参数映射到注解参数中,可以在设置动态请求映射

@RequestMapping("path/{type}")//可以配置动态路径  pathVariable 会自动将路径中的值绑定到方法参数上
	@ResponseBody
	public void testPathVaiavle(HttpServletRequest req,HttpServletResponse resp,@PathVariable(value="type") int type){
		System.out.println(type);
	}

@ResponseStatus

设置请求成功时的返回值,执行成功后,会返回设置的状态码返回给请求发送方

即使是请求成功,也可以设置返回码为Http状态码 返回404,500

猜你喜欢

转载自blog.csdn.net/kzcming/article/details/80764179