Browse Source

调整fastjson异常终止

master
xyiege 3 years ago
parent
commit
1c5e8441fe
  1. 22
      src/main/java/cn/chjyj/szwh/configure/ChWebMvcConfigurer.java
  2. 3
      src/main/java/cn/chjyj/szwh/utils/ApiGoodsUtils.java

22
src/main/java/cn/chjyj/szwh/configure/ChWebMvcConfigurer.java

@ -1,13 +1,21 @@
package cn.chjyj.szwh.configure;
import cn.chjyj.szwh.Interceptor.ChInterceptor;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.Arrays;
/**
* 配置基础信息
*/
@ -30,4 +38,18 @@ public class ChWebMvcConfigurer implements WebMvcConfigurer {
registry.addMapping("/**")
.allowedMethods("POST","GET");
}
/**
* fast json 字符串转义
* @return
*/
@Bean
public HttpMessageConverter fastConvert(){
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
FastJsonConfig config = new FastJsonConfig();
config.setSerializerFeatures(SerializerFeature.WriteSlashAsSpecial);
converter.setFastJsonConfig(config);
converter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON));
return converter;
}
}

3
src/main/java/cn/chjyj/szwh/utils/ApiGoodsUtils.java

@ -82,8 +82,7 @@ public class ApiGoodsUtils {
GoodsDetail goodsDetail = new GoodsDetail();
goodsDetail.setGoodsName(json.getString("titleName"));
//goodsDetail.setGoodsImage(json.getString("cover"));
goodsDetail.setGoodsImage(""); //待获取
goodsDetail.setGoodsImage(json.getString("cover"));
goodsDetail.setPrice(new BigDecimal(sprice));
// 商品类型
int igtype = "文化资源数据".equalsIgnoreCase("collectionType")?1:2;

Loading…
Cancel
Save