我正在尝试将我的员工实体发送到视图,但是我不断收到堆栈溢出错误。
这是我通过员工模型的控制器。
public String ToShowDashboard(Model model, HttpServletRequest request) throws IOException {
Employee employee = (Employee) this.cookieService.getStoredObject("branded", request);
model.addAttribute("employee", employee );
if (employee.getPosition().equals(Employee.POSITION.ADMIN)) {
return "designers/dashboard";
}else {return "designers/dashboard2";}
}
这是EmployeeEnity类
@Entity
public class Employee extends DefaultEntity {
public enum POSITION {ADMIN, NON_ADMIN}
private String firstName;
private String lastName;
@Email
private String email;
private String password;
private boolean activated = false;
@Enumerated(EnumType.STRING)
private POSITION position;
@ManyToOne
@JoinColumn(name = "fashion_brand_id")
private FashionBrand fashionBrand;
@OneToMany(mappedBy = "employee", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<Task> tasks;
private double rating;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public FashionBrand getFashionBrand() {
return fashionBrand;
}
public void setFashionBrand(FashionBrand fashionBrand) {
this.fashionBrand = fashionBrand;
}
public double getRating() {
return rating;
}
public void setRating(double rating) {
this.rating = rating;
}
public List<Task> getTasks() {
return tasks;
}
public void setTasks(List<Task> tasks) {
this.tasks = tasks;
}
public POSITION getPosition() {
return position;
}
public void setPosition(POSITION position) {
this.position = position;
}
public boolean isActivated() {
return activated;
}
public void setActivated(boolean activated) {
this.activated = activated;
}
}
这是我不断得到的错误
Exception
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.StackOverflowError
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:986)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.springframework.session.web.http.SessionRepositoryFilter.doFilterInternal(SessionRepositoryFilter.java:167)
org.springframework.session.web.http.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:80)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
Root Cause
java.lang.StackOverflowError
sun.reflect.misc.ReflectUtil.checkPackageAccess(ReflectUtil.java:164)
sun.reflect.misc.ReflectUtil.isPackageAccessible(ReflectUtil.java:195)
java.beans.Introspector.getBeanInfo(Introspector.java:164)
org.thymeleaf.util.JavaScriptUtils.printObject(JavaScriptUtils.java:353)
org.thymeleaf.util.JavaScriptUtils.print(JavaScriptUtils.java:184)
org.thymeleaf.util.JavaScriptUtils.printKeyValue(JavaScriptUtils.java:346)
org.thymeleaf.util.JavaScriptUtils.printMap(JavaScriptUtils.java:337)
org.thymeleaf.util.JavaScriptUtils.printObject(JavaScriptUtils.java:365)
org.thymeleaf.util.JavaScriptUtils.print(JavaScriptUtils.java:184)
org.thymeleaf.util.JavaScriptUtils.printCollection(JavaScriptUtils.java:322)
org.thymeleaf.util.JavaScriptUtils.print(JavaScriptUtils.java:173)
org.thymeleaf.util.JavaScriptUtils.printKeyValue(JavaScriptUtils.java:346)
org.thymeleaf.util.JavaScriptUtils.printMap(JavaScriptUtils.java:337)
org.thymeleaf.util.JavaScriptUtils.printObject(JavaScriptUtils.java:365)
org.thymeleaf.util.JavaScriptUtils.print(JavaScriptUtils.java:184)
org.thymeleaf.util.JavaScriptUtils.printKeyValue(JavaScriptUtils.java:346)
org.thymeleaf.util.JavaScriptUtils.printMap(JavaScriptUtils.java:337)
org.thymeleaf.util.JavaScriptUtils.printObject(JavaScriptUtils.java:365)
org.thymeleaf.util.JavaScriptUtils.print(JavaScriptUtils.java:184)
org.thymeleaf.util.JavaScriptUtils.printCollection(JavaScriptUtils.java:322)
org.thymeleaf.util.JavaScriptUtils.print(JavaScriptUtils.java:173)
org.thymeleaf.util.JavaScriptUtils.printKeyValue(JavaScriptUtils.java:346)
org.thymeleaf.util.JavaScriptUtils.printMap(JavaScriptUtils.java:337)
org.thymeleaf.util.JavaScriptUtils.printObject(JavaScriptUtils.java:365)
org.thymeleaf.util.JavaScriptUtils.print(JavaScriptUtils.java:184)
org.thymeleaf.util.JavaScriptUtils.printKeyValue(JavaScriptUtils.java:346)
org.thymeleaf.util.JavaScriptUtils.printMap(JavaScriptUtils.java:337)
org.thymeleaf.util.JavaScriptUtils.printObject(JavaScriptUtils.java:365)
请解决此问题的可能原因,因为错误消息不够详细。
最后这是我的百里香模板:
<!DOCTYPE html>
<html lang="en" class="full-height" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"></meta>
<meta http-equiv="x-ua-compatible" content="ie=edge"></meta>
<title>Material Design Bootstrap</title>
<!-- Font Awesome -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"></link>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="../css/bootstrap.min.css"></link>
<!-- Material Design Bootstrap -->
</head>
<body>
<div id="main">
<div class="container-fluid pt-4">
<div class="fixed-action-btn" style="bottom: 45px; right: 24px;">
<a class="btn-floating btn-lg red">
<i class="fa fa-pencil"></i>
</a>
<ul class="list-unstyled">
<li><a class="btn-floating green" onclick="showAddEmployeeModal()"><i class="fa fa-user-plus"></i></a></li>
<li><a class="btn-floating blue" onclick="showViewEmployeeModal()"><i class="fa fa-users"></i></a></li>
</ul>
</div>
<!-- SCRIPTS -->
<!-- JQuery -->
<script src="../js/jquery-3.2.1.min.js"></script>
<!-- Bootstrap tooltips -->
<script type="text/javascript" src="../js/popper.min.js"></script>
<!-- Bootstrap core JavaScript -->
<script type="text/javascript" src="../js/vendor/knockout/knockout-3.4.2.js"></script>
<script type="text/javascript" src="../js/vendor/datatables/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../js/vendor/datatables/js/dataTables.bootstrap4.min.js"></script>
<script type="text/javascript" src="../js/vendor/branded/model/Designer/DesignerDashboardModel.js"></script>
<script type="text/javascript" th:inline="javascript">
$(document).ready(function() {
/*<![CDATA[*/
var Object = {};
console.log(/*[[${employee}]]*/);
Object.employee = /*[[${employee}]]*/ 'default';
Object.fashionBrand = /*[[${fashionBrand}]]*/ 'default';
ko.applyBindings(new designerDashboardModel(Object));
/*]]>*/
});
</script>
</body>
</html>