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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • async/await 的理解和用法

    async/await 的理解和用法async/await是什么async/await是ES7提出的基于Promise的解决异步的最终方案。asyncasync是一个加在函数前的修饰符,被async定义的函数会默认返回一个Promise对象resolve的值。因此对async函数可以直接then,返回值就是then方法传入的函数。//async基础语法asyncfunctionfun0(){console.log(1);return1;}fun0().then(val=>{conso

    2022年7月12日
  • idea/ pycharm全局搜索快捷键不可用

    idea/ pycharm全局搜索快捷键不可用搜狗设置,系统快捷键设置,去掉繁体切换快捷键就ok了

    2022年5月31日
  • Spring Security身份认证之UserDetailsService[通俗易懂]

    Spring Security身份认证之UserDetailsService[通俗易懂]        之前我们采用了配置文件的方式从数据库中读取用户进行登录。虽然该方式的灵活性相较于静态账号密码的方式灵活了许多,但是将数据库的结构暴露在明显的位置上,绝对不是一个明智的做法。本文通过Java代码实现UserDetailsService接口来实现身份认证。  1.1UserDetailsService在身份认证中的作用  SpringSecurity中进行身份验证的是Aut…

    2022年10月30日
  • java date当前时间_JAVA中获取当前系统时间

    java date当前时间_JAVA中获取当前系统时间一.获取当前系统时间和日期并格式化输出:importjava.util.Date;importjava.text.SimpleDateFormat;publicclassNowString{publicstaticvoidmain(String[]args){SimpleDateFormatdf=newSimpleDateFormat(“yyyy-MM-ddHH:m…

    2022年10月18日
  • win7下php7.1运行getenv(‘REMOTE_ADDR’)fastcgi停止运行

    win7下php7.1运行getenv(‘REMOTE_ADDR’)fastcgi停止运行

    2021年10月27日
  • java变量设置_如何正确的配置JAVA环境变量

    java变量设置_如何正确的配置JAVA环境变量原创:YiKiA2Data什么是环境变量?环境变量是在操作系统中一个具有特定名字的对象,它包含了一个或者多个应用程序所将使用到的信息。为什么要配置环境变量?为了方便在控制台编译和运行java程序,不必进入到java的程序目录里面去运行。这样你放在任何目录下的java程序文件都可以编译运行,而不是必须把这个程序文件放在java.exe和javac.exe所在的目录下。什么是JAVA_HOME…

    2022年7月7日

发表回复

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

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