枚举 ContentType
- java.lang.Object
-
- java.lang.Enum<ContentType>
-
- xyz.xiezc.ioc.starter.starter.web.common.ContentType
-
- 所有已实现的接口:
Serializable,Comparable<ContentType>
public enum ContentType extends Enum<ContentType>
常用Content-Type类型枚举- 从以下版本开始:
- 4.0.11
- 作者:
- looly
-
-
枚举常量概要
枚举常量 枚举常量 说明 DefaultFORM_URLENCODED标准表单编码,当action为get时候,浏览器用x-www-form-urlencoded的编码方式把form数据转换成一个字串(name1=value1&name2=value2…)JSONRest请求JSON编码MULTIPART文件上传编码,浏览器会把整个表单以控件为单位分割,并为每个部分加上Content-Disposition,并加上分割符(boundary)TEXT_HTMLtext/html编码TEXT_PLAINtext/plain编码TEXT_XMLRest请求text/xml编码XMLRest请求XML编码
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 static Stringbuild(String contentType, Charset charset)输出Content-Type字符串,附带编码信息static ContentTypeget(String body)从请求参数的body中判断请求的Content-Type类型,支持的类型有:static ContentTypegetByValue(String value)根据枚举的value中获取枚举的对象StringgetValue()获取value值static booleanisDefault(String contentType)是否为默认Content-Type,默认包括null和application/x-www-form-urlencodedstatic booleanisFormUrlEncode(String contentType)是否为application/x-www-form-urlencodedStringtoString()StringtoString(Charset charset)输出Content-Type字符串,附带编码信息static ContentTypevalueOf(String name)返回带有指定名称的该类型的枚举常量。static ContentType[]values()按照声明该枚举类型的常量的顺序, 返回 包含这些常量的数组。
-
-
-
枚举常量详细资料
-
Default
public static final ContentType Default
-
FORM_URLENCODED
public static final ContentType FORM_URLENCODED
标准表单编码,当action为get时候,浏览器用x-www-form-urlencoded的编码方式把form数据转换成一个字串(name1=value1&name2=value2…)
-
MULTIPART
public static final ContentType MULTIPART
文件上传编码,浏览器会把整个表单以控件为单位分割,并为每个部分加上Content-Disposition,并加上分割符(boundary)
-
JSON
public static final ContentType JSON
Rest请求JSON编码
-
XML
public static final ContentType XML
Rest请求XML编码
-
TEXT_PLAIN
public static final ContentType TEXT_PLAIN
text/plain编码
-
TEXT_XML
public static final ContentType TEXT_XML
Rest请求text/xml编码
-
TEXT_HTML
public static final ContentType TEXT_HTML
text/html编码
-
-
方法详细资料
-
values
public static ContentType[] values()
按照声明该枚举类型的常量的顺序, 返回 包含这些常量的数组。该方法可用于迭代 常量, 如下所示:for (ContentType c : ContentType.values()) System.out.println(c);
- 返回:
- 按照声明该枚举类型的常量的顺序返回的包含这些常量的数组
-
valueOf
public static ContentType valueOf(String name)
返回带有指定名称的该类型的枚举常量。 字符串必须与用于声明该类型的枚举常量的 标识符完全匹配。(不允许有多余 的空格字符。)- 参数:
name- 要返回的枚举常量的名称。- 返回:
- 返回带有指定名称的枚举常量
- 抛出:
IllegalArgumentException- 如果该枚举类型没有带有指定名称的常量NullPointerException- 如果参数为空值
-
getByValue
public static ContentType getByValue(String value)
根据枚举的value中获取枚举的对象- 参数:
value-- 返回:
-
getValue
public String getValue()
获取value值- 返回:
- value值
- 从以下版本开始:
- 5.2.6
-
toString
public String toString()
- 覆盖:
toString在类中Enum<ContentType>
-
toString
public String toString(Charset charset)
输出Content-Type字符串,附带编码信息- 参数:
charset- 编码- 返回:
- Content-Type字符串
-
isDefault
public static boolean isDefault(String contentType)
是否为默认Content-Type,默认包括null和application/x-www-form-urlencoded- 参数:
contentType- 内容类型- 返回:
- 是否为默认Content-Type
- 从以下版本开始:
- 4.1.5
-
isFormUrlEncode
public static boolean isFormUrlEncode(String contentType)
是否为application/x-www-form-urlencoded- 参数:
contentType- 内容类型- 返回:
- 是否为application/x-www-form-urlencoded
-
get
public static ContentType get(String body)
从请求参数的body中判断请求的Content-Type类型,支持的类型有:1. application/json 1. application/xml
- 参数:
body- 请求参数体- 返回:
- Content-Type类型,如果无法判断返回null
-
-