mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-06 09:26:48 +08:00
上传文件返回格式为application/json
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.xboe.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
@@ -8,9 +7,11 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.cbor.MappingJackson2CborHttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.util.List;
|
||||
@@ -20,6 +21,15 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(WebConfig.class);
|
||||
|
||||
@Override
|
||||
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
|
||||
configurer.favorParameter(true)
|
||||
.defaultContentType(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML)
|
||||
.parameterName("mediaType")
|
||||
.mediaType("json", MediaType.APPLICATION_JSON)
|
||||
.mediaType("xml", MediaType.APPLICATION_XML);
|
||||
}
|
||||
|
||||
//结果处理器
|
||||
@Bean
|
||||
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter(ObjectMapper objectMapper) {
|
||||
@@ -30,9 +40,10 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
public ObjectMapper objectMapper() {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY,true);
|
||||
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
||||
return mapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在默认的消息转换器基础上添加或移除某些转换器
|
||||
* 保证StringHttpMessageConverter在FastJsonHttpMessageConverter前被调用
|
||||
|
||||
@@ -283,7 +283,7 @@ public class XFileBaseApi extends ApiBaseController{
|
||||
}
|
||||
|
||||
@ApiAccess(path="xfile.file.upload")
|
||||
@RequestMapping(value="/file/upload", method={RequestMethod.POST},produces = "application/json")
|
||||
@RequestMapping(value="/file/upload", method={RequestMethod.POST})
|
||||
public JsonResponse<ListViewItem> fileUpload(HttpServletRequest request,String folderId) {
|
||||
if(StringUtils.isBlank(folderId)) {
|
||||
folderId="0";
|
||||
|
||||
Reference in New Issue
Block a user