java mediatype utf-8_Java MediaType.APPLICATION_JSON_UTF8屬性代碼示例

java mediatype utf-8_Java MediaType.APPLICATION_JSON_UTF8屬性代碼示例/***Searches{@linkorg.springframework.web.bind.annotation.RequestMappingRequestMapping}*annotationonthegivenmethodargumentandextracts*IfRequestMappingannotationisnotfound,NoRequestM…

大家好,又见面了,我是你们的朋友全栈君。

/**

* Searches {@link org.springframework.web.bind.annotation.RequestMapping RequestMapping}

* annotation on the given method argument and extracts

* If RequestMapping annotation is not found, NoRequestMappingFoundException is thrown.

* {@link org.springframework.http.HttpMethod HttpMethod} type equivalent to

* {@link org.springframework.web.bind.annotation.RequestMethod RequestMethod} type

*

* @param element AnnotatedElement object to be examined.

* @return Mapping object

*/

Mapping extractMapping(AnnotatedElement element) {

Annotation annotation = findMappingAnnotation(element);

String[] urls;

RequestMethod requestMethod;

String consumes;

if (annotation instanceof RequestMapping) {

RequestMapping requestMapping = (RequestMapping) annotation;

requestMethod = requestMapping.method().length == 0

? RequestMethod.GET : requestMapping.method()[0];

urls = requestMapping.value();

consumes = StringHelper.getFirstOrEmpty(requestMapping.consumes());

} else if (annotation instanceof GetMapping) {

requestMethod = RequestMethod.GET;

urls = ((GetMapping) annotation).value();

consumes = StringHelper.getFirstOrEmpty(((GetMapping) annotation).consumes());

} else if (annotation instanceof PostMapping) {

requestMethod = RequestMethod.POST;

urls = ((PostMapping) annotation).value();

consumes = StringHelper.getFirstOrEmpty(((PostMapping) annotation).consumes());

} else if (annotation instanceof PutMapping) {

requestMethod = RequestMethod.PUT;

urls = ((PutMapping) annotation).value();

consumes = StringHelper.getFirstOrEmpty(((PutMapping) annotation).consumes());

} else if (annotation instanceof DeleteMapping) {

requestMethod = RequestMethod.DELETE;

urls = ((DeleteMapping) annotation).value();

consumes = StringHelper.getFirstOrEmpty(((DeleteMapping) annotation).consumes());

} else if (annotation instanceof PatchMapping) {

requestMethod = RequestMethod.PATCH;

urls = ((PatchMapping) annotation).value();

consumes = StringHelper.getFirstOrEmpty(((PatchMapping) annotation).consumes());

} else {

throw new NoRequestMappingFoundException(element);

}

HttpMethod httpMethod = HttpMethod.resolve(requestMethod.name());

String url = StringHelper.getFirstOrEmpty(urls);

MediaType mediaType;

try {

mediaType = MediaType.valueOf(consumes);

} catch (InvalidMediaTypeException exception) {

mediaType = MediaType.APPLICATION_JSON_UTF8;

}

return new Mapping(httpMethod, url, mediaType);

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/144984.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 警告:Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA

    警告:Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA问题:安装TensorFlow(CPU版本),使用pipinstalltensorflow安装,安装一切顺利,但是在跑一个简单的程序时,遇到如下情况:大概意思是:你的CPU支持AVX扩展,但是你安装的TensorFlow版本无法编译使用。原因:除了通常的算术和逻辑,现代CPU提供了许多低级指令,称为扩展,例如,SSE2,SSE4,AVX等来自维基百科:高级矢量扩…

    2022年5月30日
    35
  • 如何设置自动切换ip地址

    如何设置自动切换ip地址

    2021年9月18日
    165
  • 常见电容的种类_电容工作原理

    常见电容的种类_电容工作原理一、瓷介电容器(CC)1.结构用陶瓷材料作介质,在陶瓷表面涂覆一层金属(银)薄膜,再经高温烧结后作为电极而成。瓷介电容器又分1类电介质(NPO、CCG));2类电介质(X7R、2X1)和3类电介质(Y5V、2F4)瓷介电容器。2.特点1类瓷介电容器具有温度系数小、稳定性高、损耗低、耐压高等优点。最大容量不超过1000pF,常用的有CC1、CC2、CC18A、CC11、…

    2022年8月22日
    5
  • 软件开发入门自学指南[通俗易懂]

    软件开发入门自学指南[通俗易懂]每天都看到很多对编程感兴趣的人在问是不是可以自学软件开发,或者应该怎么自学编程才能入门。在这篇文章里,我将尝试重现一个初学者在学习计算机编程时可能会碰到的问题,并尽量提供相应的解决思路,希望对初学者有所帮助。如果你在看完这篇文章后还是有些疑惑,欢迎点击这里咨询我。目录编程可以自学吗?学习编程需要什么基础?什么是编程语言?什么是程序?我应该学习哪种编程语言?编程的核心思维是什…

    2022年4月19日
    51
  • matplotlib颜色代码_matplotlib color

    matplotlib颜色代码_matplotlib color命令形如:plt.plot(x,y,linewidth=’1′,label=”test”,color=’red’,linestyle=’:’,marker=’|’)plt.legend(loc=’upperleft’)plt.show()线条形式(linestyle):’-‘solidlinestyle’–‘dashedli…

    2022年10月15日
    0
  • zabbix监控elasticsearch集群「建议收藏」

    zabbix监控elasticsearch集群「建议收藏」今天同事负责的es集群发生了脑裂,具体原因还有待查看日志。顺便分享一套zabbix监控es集群的脚本。生产改进与建议:所有监控统一status值,比如0是ok的,1是警告,2是error因为es集群会自己维护整个集群的元数据,因此数据收集不是按节点来的而是整个集群现在的配置是从salt的pillar中获取端口(或者说集群名)然后渲染下面的脚本,然后再自动发现集群下面的节点。建议集群也使…

    2022年5月29日
    82

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号