为了账号安全,请及时绑定邮箱和手机立即绑定

访问url的时候报500转换错误

我查询出了数据,但是Controll返回值为什么不能是List,其他的String,Date,Int都可以,下面是错误的提示:

No converter found for return value of type: class java.util.ArrayList

正在回答

6 回答

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);
}


1 回复 有任何疑惑可以回复我~
#1

小小骚年郎 提问者

非常感谢!
2017-11-18 回复 有任何疑惑可以回复我~

不知道具体搜什么,能否提供一个wiki,对相关内容进行一个简要说明&lt;textareaclass="form-control"rows="3"resize="none"&gt;&lt;/textarea&gt;

0 回复 有任何疑惑可以回复我~

代码奉上

Controll:

http://img1.sycdn.imooc.com//59ff03e40001be9a09200376.jpg

Repository:

http://img1.sycdn.imooc.com//59ff03e50001fa6b06140204.jpg

User实体类:

http://img1.sycdn.imooc.com//59ff03e60001297b07310604.jpg

application.yml:

http://img1.sycdn.imooc.com//59ff03e60001ab4d04920291.jpg

Service:

http://img1.sycdn.imooc.com//59ff03e700013b3204600373.jpg

求大佬解答啊!!!

0 回复 有任何疑惑可以回复我~

这个是错误的提示:

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

其他地方和作者基本都一样的

0 回复 有任何疑惑可以回复我~

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;

导入的包没问题的

0 回复 有任何疑惑可以回复我~

包引入错了包,你在导入ArrayList包时,导入的不是 java.util 下的包吧


0 回复 有任何疑惑可以回复我~
#1

小小骚年郎 提问者

包没问题
2017-11-05 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
2小时学会Spring Boot
  • 参与学习       151652    人
  • 解答问题       1079    个

Spring Boot入门视频教程,你将学会使用Spring Boot快速构建应用程序

进入课程

访问url的时候报500转换错误

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信