[英]unlimited outputs while trying to access restful web service in spring mvc
i am using spring DAO and spring mvc in my project, once i try to access below url i'm getting huge no of json and that won't stop untill i stop the program.i cant figure this out can some one explain what's happening here. 我在我的项目中使用spring DAO和spring mvc,一旦我尝试在url下访问,我会收到大量的json,并且直到我停止该程序后才会停止。我无法弄清楚这一点可以解释一下发生了什么这里。
url :- //http://localhost:8080/plans/11/more
//controller
@ResponseBody
@RequestMapping(value="plans/{pid}/more",method=RequestMethod.GET)
public Travel showMore(@PathVariable int pid ){
Travel travel = travelRep.findOne(pid);
return travel;
}
model class 模型类
public class Travel implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
private Integer idtravel;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "idtravel")
private Set<Travellocation> travellocationSet;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "idtravel")
private Set<Transactions> transactionsSet;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "idtravel")
private Set<Travelmode> travelmodeSet;
}
//assume that there are getters and setters for the properties in the model class. //假设模型类中的属性有getter和setter方法。
travellocationSet
and idLocation
seem to have a reference to eachother. travellocationSet
和idLocation
似乎idLocation
引用。 Spring will go through all the getters so something like this will happen: 春天将经历所有吸气剂,因此将发生以下情况:
idLocation = travellocationSet->getIdLocation();
travellocationSet = idLocation->getTravellocationSet();
idLocation = travellocationSet->getIdLocation();
travellocationSet = idLocation->getTravellocationSet();
// This will continue forever
A solution can be to use the Data Transfer Object pattern. 解决方案可以是使用数据传输对象模式。 Basically you would copy your data to a new object, which can be used for your viewing part.
基本上,您会将数据复制到新对象,该对象可用于查看零件。
Stream content into a separate file (Dump File) Can you try streaming the data into a file provided you have enough memory to understand how huge the data you are going to download 将内容流式传输到单独的文件(转储文件)中,如果您有足够的内存来理解将要下载的数据量,可以尝试将数据流式传输到文件中吗
Basically you have to go ahead and create a dump file, parse through the dump file and filter out the necessary data. 基本上,您必须继续创建转储文件,解析转储文件并过滤出必要的数据。
I wouldn't advise on DTO pattern as you are not sure how large the size is and moreover if it exceeds the heap size you would receive OOM Exception. 我不建议使用DTO模式,因为您不确定大小是多少,而且如果它超过堆大小,您将收到OOM异常。
I suggest to go through the link https://www.airpair.com/java/posts/spring-streams-memory-efficiency 我建议通过链接https://www.airpair.com/java/posts/spring-streams-memory-efficiency
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.