访问url的时候报500转换错误
我查询出了数据,但是Controll返回值为什么不能是List,其他的String,Date,Int都可以,下面是错误的提示:
No converter found for return value of type: class java.util.ArrayList
我查询出了数据,但是Controll返回值为什么不能是List,其他的String,Date,Int都可以,下面是错误的提示:
No converter found for return value of type: class java.util.ArrayList
2017-11-05
List转json的时候要配置转换器;增加的配置类继承WebMvcConfigurerAdapter 再重写configureMessageConverters方法 下面是我写得;你试试看!
@Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { super.configureMessageConverters(converters); FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures( SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullStringAsEmpty ); fastConverter.setFastJsonConfig(fastJsonConfig); List<MediaType> supportedMediaTypes = new ArrayList<MediaType>(); supportedMediaTypes.add(MediaType.ALL); fastConverter.setSupportedMediaTypes(supportedMediaTypes); converters.add(fastConverter); }
这个是错误的提示:
2017-11-05 20:19:45.190 ERROR 8632 --- [nio-8000-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList] with root cause java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList
其他地方和作者基本都一样的
Controll类:
package com.example.helloboot.Controll; import com.example.helloboot.dao.UserRepository; import com.example.helloboot.entity.User; import com.example.helloboot.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List;
Repository接口:
package com.example.helloboot.dao; import com.example.helloboot.entity.User; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List;
Service类:
package com.example.helloboot.service; import com.example.helloboot.dao.UserRepository; import com.example.helloboot.entity.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List;
导入的包没问题的
举报