12.@RequestMapping中的consumes属性和produces属性

请求头header中很重要的两个参数:
	Accept:text/html
		只在响应中存在,表示当前请求希望服务器将来返回的数据类型是text/html
	Content-Type:application/json
		既可以出现在请求中,也可以出现在响应中,例如
		响应中代表服务器响应的是什么数据类型
			响应中response.setContentType("text/html;charset=utf-8");
		请求中代表客户端所携带的参数是什么类型
consumes 指定处理请求的提交内容类型(消费)
produces 指定返回的内容类型(生产)

在这里插入图片描述

@RequestMapping("/request_header")
@Controller
public class RequestHeaderController {
	//consumes指代的就是请求头中Content-Type
	@RequestMapping(value="/test6",consumes= {"application/json"})//再不写Content-Type=...
	public String test6(){
		System.out.println("RequestHeaderController test6()...");
		return "test";
	}
	//produces指代的就是请求头中Accept
	@RequestMapping(value="/test7",produces= {"application/json"})//指代的就是Accept,*/*代表的是所以数据类型
	public String test7(){
		System.out.println("RequestHeaderController test7()...");
		return "test";
	}
	//客户端发送的数据是json数据,响应回来的也是json数据
	@RequestMapping(value="/test8",produces= {"application/json"},consumes= {"application/json"}) //模拟运行
	public String test8(){
		System.out.println("RequestHeaderController test8()...");
		return "test";
	}
}
*/*  代表所有类型
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值