进行查询的陷入了无限死循环,原因是问题类中包含了回答,回答类中包含了问题,进入了无限死循环

解决方法:在回答类中的问题类属性上加注解:@JsonBackReference

问题中有回答的set集合,回答中有问题类:

问题类:

package com.wazn.learn.entity.teachclass;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set; import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table; import com.wazn.learn.entity.sys.User; /**
*
* 提问表
*
*/
@Entity
@Table(name="teach_questions")
public class Questions {
private Integer id;//id
private User userid;//学生id
private TeachClass cid;//课程id
private String question;//提问
private Date twtime;//提问时间
private String title;
private Set<Answer> answer; @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
} @Column(nullable=false) public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
@ManyToOne
@JoinColumn(name="c_id",nullable=false,insertable=true)
public TeachClass getCid() {
return cid;
}
public void setCid(TeachClass cid) {
this.cid = cid;
}
@ManyToOne
@JoinColumn(name="user_id",nullable=false,insertable=true)
public User getUserid() {
return userid;
}
public void setUserid(User userid) {
this.userid = userid;
}
public Date getTwtime() {
return twtime;
}
public void setTwtime(Date twtime) {
this.twtime = twtime;
} @OneToMany(cascade = { CascadeType.REFRESH, CascadeType.PERSIST,CascadeType.MERGE, CascadeType.REMOVE },mappedBy ="question")
public Set<Answer> getAnswer() {
return answer;
}
public void setAnswer(Set<Answer> answer) {
this.answer = answer;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}

回答类:

package com.wazn.learn.entity.teachclass;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table; import com.fasterxml.jackson.annotation.JsonBackReference;
import com.wazn.learn.entity.sys.User;
@Entity
@Table(name="teach_answer")
public class Answer { private Integer id;
private String content;
private Date hftime;
private User userid;//教师id
private Questions question; @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
} @Column(nullable=false)
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
} public Date getHftime() {
return hftime;
}
public void setHftime(Date hftime) {
this.hftime = hftime;
}
@ManyToOne
@JoinColumn(name="u_id",nullable=false,insertable=true)
public User getUserid() {
return userid;
}
public void setUserid(User userid) {
this.userid = userid;
} @ManyToOne
@JoinColumn(name="q_id",nullable=false,insertable=true)
@JsonBackReference
public Questions getQuestion() {
return question;
}
@JsonBackReference
public void setQuestion(Questions question) {
this.question = question;
}
@Override
public String toString() {
return "Answer [id=" + id + ", content=" + content + ", hftime=" + hftime + ", userid=" + userid + ", question="
+ question + "]";
} }

spring mvc报错,数据库查询无限死循环的更多相关文章

  1. Spring mvc 报错:No qualifying bean of type [java.lang.String] found for dependency:

    具体错误: No qualifying bean of type [java.lang.String] found for dependency: expected at least 1 bean w ...

  2. SpringBoot、Spring MVC报错:Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

    出现问题的原因: jdbc配置不正确 解决方案: 1.检查是否已添加数据库驱动jar包 2.检查数据库服务是否启动 3.检查数据库配置文件 主要为:dialect,driver_class,url,u ...

  3. Spring MVC报错:The request sent by the client was syntactically incorrect ()

    原因: 1.参数名称不一致 2.参数类型不一致

  4. 解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element

    解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element 'beans'.Referenced file conta ...

  5. Spring Boot报错 MultipartException The temporary upload...

    Spring Boot报错:尤其是在处理Ribbon这类接口调用型的负载均衡组件,常见问题 ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.se ...

  6. iis 7上发布mvc报错:403.14-Forbidden Web 服务器被配置为不列出此目录的内容

    iis 7上发布mvc报错:403.14-Forbidden Web 服务器被配置为不列出此目录的内容 提示里面的解决方法是: 如果不希望启用目录浏览,请确保配置了默认文档并且该文件存在. 使用 II ...

  7. Spring Boot 报错记录

    Spring Boot 报错记录 由于新建的项目没有配置数据库连接启动报错,可以通过取消自动数据源自动配置来解决 解决方案1: @SpringBootApplication(exclude = Dat ...

  8. Spring.之.报错:Caused by: java.lang.IllegalArgumentException: No Spring Session store is configured: set the 'spring.session.store-type' property

    Spring.之.报错 No Spring Session store is configured springboot在启动的时候报如下错误: Error starting ApplicationC ...

  9. 【spring mvc】后台API查询接口,get请求,后台Date字段接收前台String类型的时间,报错default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'createDate';

    后台API查询接口,get请求,后台Date字段接收前台String类型的时间筛选条件 后台接口接收 使用的实体 而createDate字段在后台实体中是Date类型 报错信息: org.spring ...

随机推荐

  1. 最简单的optparse模块的用法

    optparse模块是python自带的模块,可用于处理命令行 #!/usr/bin/env python # -*- coding: utf-8 -*- """ __a ...

  2. kali 2017更新源

    #阿里云deb http://mirrors.aliyun.com/kali kali-rolling main non-free contribdeb-src http://mirrors.aliy ...

  3. 自理一遍android 高级知识

    之后按目录得复习巩固 目录: 客卓高级知识整理 1 移动架构 1.1 素养与基础 1.1.1 主流设计模式 创建型 行为型 结构型 1.1.2 UML 1.1.3 设计原则 1.1.4 AOP架构 1 ...

  4. Nuxt框架实践

    前言 今天抽空过了遍nuxt文档,写了个实践demo,关于nuxt我已经断断续续看了好几遍了,自我感觉也算是入门了吧,从开发到上线心里都有底.后期打算在项目用起来的是nuxt框架,一些函数工具库,比如 ...

  5. SQL---约束---add constraint方法添加约束

    1.主键约束: 格式为:alter table 表格名称 add constraint 约束名称 增加的约束类型 (列名) 例子:alter table emp add constraint ppp ...

  6. css一些简单的例子

    1.http协议 一:HTTP协议:hypertext transport protocol(超文本传输协议) 特点: 1.请求与响应 2.无状态的协议 请求协议: 请求首行: 请求头信息: Acce ...

  7. ##6.1 Neutron控制节点-- openstack pike

    ##6.1 Neutron控制节点 openstack pike 安装 目录汇总 http://www.cnblogs.com/elvi/p/7613861.html ##6.1 Neutron控制节 ...

  8. 天梯赛 L3-013 非常弹的球 找规律

    L3-013. 非常弹的球 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 俞勇(上海交通大学) 刚上高一的森森为了学好物理,买了一个 ...

  9. Mysql 的 IF 判断

    mysql自带很多判断逻辑,今天说一说IF的判断语句,正好今天做项目的时候也用到了 1. IF 判断 IF判断和我们代码里面写的有略微的差别,举个例子 IF('表达式','结果1','结果2')  如 ...

  10. CORS预检请求详谈

    引言 最近在项目中因前后端部署不同地方,前端在请求后端api时发生了跨域请求,我们采用CORS(跨域资源共享)来解决跨域请求,这需要前后端的配合来完成.在这一过程中,后端支持了CORS跨域请求后,前端 ...