- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个表单,其中我有
<form:form method="post" commandName="post" htmlEscape="false">
<form:input cssClass="input-field" path="postTitle" placeholder="Post title"/>
<form:textarea id="editor" placeholder="Post" path="postBody"/>
<input type="hidden" id="tagQuery" type="text" placeholder="tags" class="input-field"/><br>
<ul id="mytags"></ul><br><br>
<form:select style="visibility : hidden;" id="tags" path="tags">
</form:select>
<input type="submit" value="Save Post"/>
</form:form>
我使用 tagit lib 获取标签,正如我配置的那样
select = document.querySelector("select[name='tags']");
jQuery(document).ready(function() {
jQuery("#mytags").tagit({
singleField: true,
singleFieldNode: $('#tagQuery'),
allowSpaces: true,
minLength: 2,
removeConfirmation: true,
tagSource: function( request, response ) {
//console.log("1");
$.getJSON("/app/getTags", request, function(result) {
response($.map(result, function(item) {
return {
// following property gets displayed in drop down
label: item.tagTitle,
// following property gets entered in the textbox
value: item.tagTitle,
// following property is added for our own use
tag_url: "http://" + window.location.host + "/" + item.tagId + "/" + item.tagTitle
}
}));
});
},
afterTagAdded : function(event, ui) {
var option = document.createElement("option");
console.log(ui);
console.log(idValue);
option.value = ui.tagLabel;
option.text = ui.tagLabel;
option.selected = 'selected';
select.appendChild(option);
},
afterTagRemoved : function(event, ui) {
select.removeChild(select.querySelector('[value="'+ui.tagLabel+'"]'));
}
});
});
最后我有了 Controller 的东西作为
public class PostController {
@Autowired
private BlogService serviceImplementation;
@ModelAttribute("post")
public Post constructPost() {
return new Post();
}
@ModelAttribute("tag")
public Tag constructTag() {
return new Tag();
}
@InitBinder
public void initBinderOne(WebDataBinder binder) {
binder.registerCustomEditor(Tag.class,
new PropertyEditorSupport() {
@Override
public void setAsText(String text) {
Tag tag = serviceImplementation.getTagById(Long
.parseLong(text));
setValue(tag);
}
});
}
@RequestMapping(value = "/new", method = RequestMethod.GET)
public String createPost(Model model) {
return "new-post";
}
@RequestMapping(value = "/new", method = RequestMethod.POST)
public String savePost(Model model, @ModelAttribute("post") Post post) {
serviceImplementation.savePost(post);
return "redirect:/";
}
}
保存帖子时出现错误
the request sent by the client was syntactically incorrect
我想通了,每当我保存它发送标签的帖子时,就会发生这种情况
option.value = ui.tagLabel;
option.text = ui.tagLabel;
option.selected = 'selected';
select.appendChild(option);
这将假定值设置为 ui.tagLabel
,如
<option value="Android">Android</option>
我在改变
select = document.querySelector("select[name='tags']");
var idValue; //HERE I ADDED var to get
jQuery(document).ready(function() {
jQuery("#mytags").tagit({
singleField: true,
singleFieldNode: $('#tagQuery'),
allowSpaces: true,
minLength: 2,
removeConfirmation: true,
tagSource: function( request, response ) {
//console.log("1");
$.getJSON("/app/getTags", request, function(result) {
response($.map(result, function(item) {
idValue = item.tagId; // HERE I ADDED var to get id to set as value in option *
return {
// following property gets displayed in drop down
label: item.tagTitle,
// following property gets entered in the textbox
value: item.tagTitle,
// following property is added for our own use
tag_url: "http://" + window.location.host + "/" + item.tagId + "/" + item.tagTitle
}
}));
});
},
afterTagAdded : function(event, ui) {
var option = document.createElement("option");
console.log(ui);
console.log(idValue);
option.value = idValue;//HERE When I add idValue to option I always get the id of last tag, let say there are 6 tags in ajax response, idValue is always 6.
option.text = ui.tagLabel;
option.selected = 'selected';
select.appendChild(option);
},
afterTagRemoved : function(event, ui) {
select.removeChild(select.querySelector('[value="'+ui.tagLabel+'"]'));
}
});
});
然后将 ajax 响应设置设置为先前的脚本
option.value = ui.tagLabel;
option.text = ui.tagLabel;
option.selected = 'selected';
select.appendChild(option);
我更改了 initBinder()
@InitBinder
public void initBinderOne(WebDataBinder binder) {
binder.registerCustomEditor(Tag.class,
new PropertyEditorSupport() {
@Override
public void setAsText(String text) {
Tag tag = serviceImplementation.getTagByName(text);
setValue(tag);
}
});
}
和
public Tag getTagByName(String tagTitle) {
// TODO Auto-generated method stub
return em.createQuery("from Tag t where t.tagTitle = :tagTitle", Tag.class)
.setParameter("tagTitle", tagTitle).getSingleResult();
}
在这一点上,我得到了一个无穷无尽的堆栈跟踪,有些行是......
HTTP Status 500 - Handler processing failed; nested exception is java.lang.StackOverflowError
type Exception report
message Handler processing failed; nested exception is java.lang.StackOverflowError
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.StackOverflowError
org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1303)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:977)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.StackOverflowError
java.nio.CharBuffer.<init>(Unknown Source)
java.nio.HeapCharBuffer.<init>(Unknown Source)
java.nio.CharBuffer.wrap(Unknown Source)
sun.nio.cs.StreamEncoder.implWrite(Unknown Source)
sun.nio.cs.StreamEncoder.write(Unknown Source)
java.io.OutputStreamWriter.write(Unknown Source)
java.io.BufferedWriter.flushBuffer(Unknown Source)
java.io.PrintStream.write(Unknown Source)
java.io.PrintStream.print(Unknown Source)
java.io.PrintStream.println(Unknown Source)
org.apache.tomcat.util.log.SystemLogHandler.println(SystemLogHandler.java:264)
org.hibernate.engine.jdbc.spi.SqlStatementLogger.logStatement(SqlStatementLogger.java:111)
org.hibernate.engine.jdbc.spi.SqlStatementLogger.logStatement(SqlStatementLogger.java:94)
org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:181)
org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:160)
org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.prepareQueryStatement(AbstractLoadPlanBasedLoader.java:257)
org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeQueryStatement(AbstractLoadPlanBasedLoader.java:201)
org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:137)
org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:102)
org.hibernate.loader.collection.plan.AbstractLoadPlanBasedCollectionInitializer.initialize(AbstractLoadPlanBasedCollectionInitializer.java:100)
org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:693)
org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:92)
org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1897)
org.hibernate.collection.internal.AbstractPersistentCollection$4.doWork(AbstractPersistentCollection.java:558)
org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:260)
org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:554)
org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:142)
org.hibernate.collection.internal.PersistentSet.hashCode(PersistentSet.java:447)
com.rhcloud.app.entity.Tag.hashCode(Tag.java:77)
java.util.HashMap.put(Unknown Source)
java.util.HashSet.add(Unknown Source)
java.util.AbstractCollection.addAll(Unknown Source)
org.hibernate.collection.internal.PersistentSet.endRead(PersistentSet.java:344)
org.hibernate.engine.loading.internal.CollectionLoadContext.endLoadingCollection(CollectionLoadContext.java:251)
org.hibernate.engine.loading.internal.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:238)
org.hibernate.engine.loading.internal.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:211)
org.hibernate.loader.plan.exec.process.internal.CollectionReferenceInitializerImpl.endLoading(CollectionReferenceInitializerImpl.java:168)
org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.finishLoadingCollections(AbstractRowReader.java:255)
org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.finishUp(AbstractRowReader.java:218)
org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:140)
org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:138)
org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:102)
org.hibernate.loader.collection.plan.AbstractLoadPlanBasedCollectionInitializer.initialize(AbstractLoadPlanBasedCollectionInitializer.java:100)
org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:693)
org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:92)
org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1897)
org.hibernate.collection.internal.AbstractPersistentCollection$4.doWork(AbstractPersistentCollection.java:558)
org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:260)
org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:554)
org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:142)
org.hibernate.collection.internal.PersistentSet.hashCode(PersistentSet.java:447)
com.rhcloud.app.entity.Post.hashCode(Post.java:92)
java.util.HashMap.put(Unknown Source)
java.util.HashSet.add(Unknown Source)
java.util.AbstractCollection.addAll(Unknown Source)
org.hibernate.collection.internal.PersistentSet.endRead(PersistentSet.java:344)
org.hibernate.engine.loading.internal.CollectionLoadContext.endLoadingCollection(CollectionLoadContext.java:251)
org.hibernate.engine.loading.internal.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:238)
org.hibernate.engine.loading.internal.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:211)
org.hibernate.loader.plan.exec.process.internal.CollectionReferenceInitializerImpl.endLoading(CollectionReferenceInitializerImpl.java:168)
org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.finishLoadingCollections(AbstractRowReader.java:255)
org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.finishUp(AbstractRowReader.java:218)
org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:140)
org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:138)
org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:102)
org.hibernate.loader.collection.plan.AbstractLoadPlanBasedCollectionInitializer.initialize(AbstractLoadPlanBasedCollectionInitializer.java:100)
org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:693)
org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:92)
org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1897)
org.hibernate.collection.internal.AbstractPersistentCollection$4.doWork(AbstractPersistentCollection.java:558)
org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:260)
org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:554)
org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:142)
I want to figure out why this hashCode() causes java.lang.StackOverflowError in my Spring Web App Post hashCode() is
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((postBody == null) ? 0 : postBody.hashCode());
result = prime * result + ((postId == null) ? 0 : postId.hashCode());
result = prime * result
+ ((postTitle == null) ? 0 : postTitle.hashCode());
result = prime * result + ((tags == null) ? 0 : tags.hashCode());
return result;
}
标签 hashCode() 是
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((posts == null) ? 0 : posts.hashCode());
result = prime * result
+ ((tagDescription == null) ? 0 : tagDescription.hashCode());
result = prime * result + ((tagId == null) ? 0 : tagId.hashCode());
result = prime * result
+ ((tagTitle == null) ? 0 : tagTitle.hashCode());
return result;
}
最佳答案
posts.hashCode()
调用 tags.hashCode()
,后者调用 posts.hashCode()
,等等....
你似乎在那里有一个无限循环。
关于java - hashCode() 导致 java.lang.StackOverflowError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34749224/
class UserScoring implements Comparable { User user; int score; UserScoring(
当重写 Java 中的 equals() 和 hashcode() 方法时,为什么不经常使用它: public int hashCode() { return (int) this.hashC
给定java Object#hashCode文档快照: As much as is reasonably practical, the hashCode method defined by class
下面的代码(sign.hashCode())是给我签名的hashCode还是内存中对象的hash? try { PackageInfo packageInfo = getPackageMana
考虑: String[] segments = {"asdf", "qwerty", "blahblah", "alongerstring", "w349fe3434"}; String fullSt
在审查大型代码库时,我经常遇到这样的情况: @Override public int hashCode() { return someFieldValue.hashCode(); } 程序员不
在以下情况下,与下面的函数发生 HashCode 冲突的可能性有多大。 key[0]、key[1]、key[2]、key[3] 的随机整数值 使用具有以下约束的随机键值 键[0] <1,000,000
从 Java 7 开始,我们有了 o.hashCode(); Objects.hashCode(o); Objects.hash(o); 前两个与空检查大致相同,但最后一个是什么? When a si
这个问题已经有答案了: Objects.hash() vs Objects.hashCode(), clarification needed (3 个回答) 已关闭 6 年前。 一个简单、简短的问题:
我是否需要使用super.hashcode()来计算this.hashcode()? IDE(例如 IntelliJ Idea)可以生成 equals 和 hashcode。它可以使用 java.ut
class A { } class B extends A { void m1(){ System.out.println(this.hashCode());
我查看了Arrays.hashCode(char[] c)的源代码 我不太确定它适用的算法是否在所有情况下都能正常工作。 public static int hashCode(int a[])
我有两个表具有一对一的关系,如下所示: @Entity @Data @NoArgsConstructor @AllArgsConstructor public class Book { @Id
为什么stringObject的hashcode是我提供的字符串? String s = new String(); // here the hascode is 0. 但是当我获得我创建的某个对象的
public abstract class HolidayPackageVariant { private HolidayPackage holidayPackage; private String
这两个代码片段有什么区别? 片段 1: Object o = new Object(); int i = Objects.hashCode(o); 片段 2: Object o = new Objec
在 Java 8 中有一个类 java.util.Objects,其中包含 hashCode() 方法。同时 Google Guava 19 包含 com.google.common.base.Obj
我的一个类(class)中有以下方法。它只是 HashMap 的公共(public)包装器(名为 teamOfPlayer,具有 Player 对象的键和 Integer 对象的值),仅此而已。 pu
我在这里做错了什么? @Override public int hashCode() { HashCodeBuilder has
我有以下程序。 Employee employee1 = new Employee("Raghav1", 101); Employee employee2 = new Employee("Raghav
我是一名优秀的程序员,十分优秀!