实现时主要问题在于怎么将所有@对象给找出来,替换成@user.name 的形式。
&#64;Overridepublic void save(Comment comment, long topicId) throws UnsupportedEncodingException {comment.setTopic(topicService.findById(topicId));User user &#61; userService.findByName("sunhuwh");if(user&#61;&#61;null){User user2 &#61; new User();user2.setName("sunhuwh");userService.save(user2);comment.setUser(user2);}else{comment.setUser(user);}String content &#61; comment.getContent();LinkedList atArr &#61; Lists.newLinkedList();LinkedList allMark &#61; Lists.newLinkedList();char[] contents &#61; content.toCharArray();Pattern p &#61; Pattern.compile("[\\&#43;-/*()^~!&#64;#$%&_&#61;|\&#39;\":;<>,.》《&#xff1f;、&#xff0c;&#xff1a;&#xff1b;”’}{】【——&#xff09;&#xff08;……&#xffe5;&#xff01;·?/ ]&#43;");Pattern p2 &#61; Pattern.compile("&#64;");for(int i &#61; 0;i nameList &#61; Lists.newArrayList();String newContent&#61;"";int m &#61; 0;for(int i &#61; 0 ;i"&#43;name.replace("&#64;","")&#43;"");m&#43;&#43;;break;}}}for(String name:nameList){String newName &#61; "af134256427sabear83199876543210041125>"&#43;name&#43;"";String newName2&#61;"&#64;"&#43;name;User newUser &#61; userService.findByName(name);if(newUser!&#61;null){newName2&#61;"&#64;"&#43;newUser.getName()&#43;" ";}newContent &#61; newContent.replaceFirst(newName, newName2);}if(atArr.size()&#61;&#61;0){newContent &#61; content;}comment.setContent(newContent);comment.setTopic(topicService.findById(topicId));save(comment);}
js
function addComment(parentId,commentId,userName){var topicId &#61; $("#topicId").val();if($("#addCommentId"&#43;commentId).css(&#39;display&#39;)&#61;&#61;"none"){$("#addCommentId"&#43;commentId).css(&#39;display&#39;,&#39;block&#39;);}else{$("#addCommentId"&#43;commentId).css(&#39;display&#39;,&#39;none&#39;); }$.get("comment/getComments?parentId&#61;"&#43;parentId&#43;"&topicId&#61;"&#43;topicId,function(data){var appendButton &#61;"";var append &#61; "";if(data!&#61;""){var arr &#61; data.split("$");var allTr&#61;"";for(var i &#61; 0;i"&#43;content&#43;" "&#43;time&#43;" ";appendButton &#61; appendButton&#43;content&#43;"回复 ";}}$("#addCommentId"&#43;commentId).html(appendButton&#43;" "&#43;"发表 ");})
}//form替换掉
function replaceFrom(commentId2,parentId2,name2){var topicId &#61; $("#topicId").val();alert(topicId&#43;"...."&#43;parentId2&#43;"...."&#43;commentId2);$("#commentsId").html("
发表 jsp&#xff1a;
comment.id是第一处位置的comment的id。
上面那处js代码是为了实现下面出现的&#xff0c;要理解好思路&#xff0c;先是所有回复主题的回复显示出来&#xff0c;再然后点击第一处时是将回复此回复的所有数据找出来&#xff0c;并有form。
如果点击了第二处时&#xff0c;就需要换个form。我也试过不换form&#xff0c;但是最后不知道怎么回事&#xff0c;form总是不变。总是原来的。
More than one row with the given identifier was found。
hibernate不是一对一一对多多对一没有配置好。
比如一个user本该有多个课程。而配置时却一对一了。