我想将kotlin的对象用作dto
@ResponseBody
fun getBindCar(coachId: Long): List<Any> {
val coach = coachRepository.findById(coachId).get()
var result = mutableListOf<Any>()
coach?.cars.forEach { it ->
var o = object : Serializable {
var id: Long = 0L
var licenceNum = ""
}
o.id = it.id
o.licenceNum = it.licenceNum
result.add(o)
}
return result
}
返回时抛出异常
2018:04:106:18:35:36.936 [http-nio-8080-exec-4] WARN oswsmmaExceptionHandlerExceptionResolver - 由Handler执行引起的已解决异常:java.lang.ClassCastException:org.appsugar.archetypes.web。 controller.oa.CoachController $ getBindCar $ 1 $ o $ 1无法强制转换为org.springframework.core.io.support.ResourceRegion 2018:04:106:18:35:36.950 [http-nio-8080-exec-4] ERROR oaccC [。[。[。[dispatcherServlet] - servlet [dispatcherServlet]的Servlet.service()与path []的上下文抛出异常[请求处理失败;嵌套异常是java.lang.IllegalStateException:已根据原因为此响应调用了getOutputStream() java.lang.IllegalStateException:已为此响应调用了getOutputStream()
答案 0 :(得分:0)
当我将返回类型从List<Any>
更新为Any
时,它可以正常工作