回复的模块我的逻辑有问题嘛。怎么添加就一直报错,,,
package com.imooc.bbs.controller;
import com.imooc.bbs.entity.Comment;
import com.imooc.bbs.entity.Post;
import com.imooc.bbs.entity.User;
import com.imooc.bbs.service.CommentService;
import com.imooc.bbs.service.PostService;
import com.imooc.bbs.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
import java.util.Map;
@Controller("commentController")
@RequestMapping("/comment")
public class CommentController {
@Autowired
private PostService postService;
@Autowired
private CommentService commentService;
@Autowired
private UserService userService;
@RequestMapping(value = "/forPost",params = "id")
public String getForPost(Map<String,Object> map,Integer id){
map.put("commentLogin",commentService.selectByPostId(id));
map.put("postGetLogin",postService.get(id));
return "post_get_login";
}
/*
@RequestMapping(value = "/forUser",params = "cid")
public String getForUser(Map<String,Object> map,Integer cid){
commentService.selectByUserId(cid);
return "redirect:/user/user_posts";
}*/
@RequestMapping("/to_add")
public String to_add(Map<String,Object> map,Integer id){
Comment comment=new Comment();
Post post=postService.get(id);
comment.setUsername(post.getUsername());
comment.setUserId(post.getUser().getId());
map.put("commentAdd",comment);
return "post_get_login";
}
@RequestMapping("/add")
public String add(Comment comment){
commentService.add(comment);
return "redirect:forPost?id="+comment.getPostId();
}
}
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>慕课论坛</title>
<link rel="stylesheet" href="/static/css/all-df86af5803.css">
</head>
<body class="forum" data-page="forum">
<div class="header">
<nav class="navbar navbar-inverse navbar-fixed-top navbar-default">
<div class="container">
<div class="navbar-header" id="navbar-header">
<a href="index.html" class="navbar-brand"><img src="/images/logo.png"> </a>
</div>
<div id="main-nav-menu">
<ul class="nav navbar-nav">
<li><a href="/post/list_login"><i class="fa fa-home"></i> <span class="hidden-xs hidden-sm">首页</span></a>
</li>
<li class="hidden-sm hidden-xs active"><a href="thread.html"><i class="fa fa-comments-o"></i> 话题</a>
</li>
</ul>
</div>
<ul class="nav navbar-nav navbar-right">
<li class="nav-search hidden-xs hidden-sm">
<form method="GET" action="thread.html" accept-charset="UTF-8"
class="navbar-form form-search active" target="_blank">
<div class="form-group">
<input placeholder="搜索" class="form-control" name="q" type="search">
</div>
<i class="fa fa-search"></i>
</form>
</li>
<!-- 登录成功后显示的内容 -->
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
<!-- 此处显示登录成功后的用户名,如果被冻结也再次显示 -->
${postGetLogin.username}
<span class="caret"></span></a>
<button class="navbar-toggle" type="button" data-toggle="dropdown" role="button" aria-expanded="false">
<span class="sr-only">Toggle</span>
<i class="fa fa-reorder"></i>
</button>
<ul class="dropdown-menu" role="menu"><li class=""><a href="my.html">我的主页</a></li>
<li><div class='divider'></div></li>
<li><a href="my.html">个人设置</a></li>
<li><a href="score.html">我的积分</a></li>
<li class='divider'></li>
<li><a href="###" onclick=" return confirm('你确定要退出吗?')"><i class="fa fa-sign-out"></i> 退出
</a></li>
</ul>
</li>
</ul>
</div>
</nav>
</div>
<div id="main" class="main-container container">
<div class="row max-width">
<div class="col-xs-12">
<ul class="breadcrumb">
<li>
<a href="/post/list_login">首页</a>
</li>
<li>
<strong><!-- 此处显示帖子标题 -->${postGetLogin.title}</strong>
</li>
</ul>
</div>
</div>
<div class="col-md-9 threads-show main-col">
<!-- Thread Detial -->
<div class="thread panel panel-default">
<div class="infos panel-heading">
<div class="pull-right avatar">
<a href="my.html"> <img src="/images/avatar.jpg" class="media-object img-thumbnail avatar-64"/> </a>
</div>
<h1 class="panel-title thread-title"><!-- 此处显示帖子标题 -->${postGetLogin.title}</h1>
<div class="likes">
<a href="javascript:void(0);" data-action="like" data-type="Thread" data-url="#" title="赞"
class="fa fa-chevron-up likeable like" data-id="10"> 10</a> <a href="javascript:void(0);"
data-action="unlike"
data-type="Thread" data-url="#"
title="踩"
class="fa fa-chevron-down likeable like"
data-id="10"></a>
</div>
<div class="meta inline-block">
<a href="my.html"> <!-- 此处显示发帖人用户名 -->${postGetLogin.username} </a>
• 于 <abbr title="2016-06-10 02:28:36" class="timeago">2016-06-10 02:28:36</abbr>
回复 <a href="my.html"> memory </a> 于 <abbr title="2017-02-08 21:47:25"
class="timeago">2017-02-08 21:47:25</abbr> •
4050 阅读
</div>
<div class="clearfix"></div>
</div>
<div class="panel-body content-body">
<div class="markdown-body" id="emojify">
<ul>
<li><!-- 此处显示帖子内容 -->${postGetLogin.content}</li>
</ul>
</div>
</div>
<div class="panel-footer operate">
<div class="pull-left" style="font-size:15px;">
<a class=""
href="http://service.weibo.com/share/share.php?url=http%3A%2F%2Fimooc.com%2Fthread%2F10&type=3&pic=&title=imooc 接下来需要完善的功能"
target="_blank" title="分享到微博"> <i class="fa fa-weibo"></i> </a> <a
href="https://twitter.com/intent/tweet?url=http%3A%2F%2Fimooc.com%2Fthread%2F10&text=imooc 接下来需要完善的功能&via=imooc.com"
class="" target="_blank" title="分享到 Twitter"> <i class="fa fa-twitter"></i> </a> <a
href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fimooc.com%2Fthread%2F10" class=""
target="_blank" title="分享到 Facebook"> <i class="fa fa-facebook"></i> </a> <a
href="https://plus.google.com/share?url=http%3A%2F%2Fimooc.com%2Fthread%2F10" class=""
target="_blank" title="分享到 Google Plus"> <i class="fa fa-google-plus"></i> </a>
</div>
<div class="pull-right">
<span class="tag-list hidden-xs">
Tags:
<a href="tag.html"><span class="tag">imooc</span></a>
</span>
</div>
<div class="clearfix"></div>
</div>
<div class="modal fade" id="exampleModal" tabindex="-1" role="" aria-labelledby="exampleModalLabel">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">×</span></button>
<h4 class="modal-title" id="exampleModalLabel">备注内容</h4>
</div>
<form method="POST" action="" accept-charset="UTF-8">
<div class="modal-body">
<div class="alert alert-warning">
附加备注, 使用此功能的话, 会给所有参加过讨论的人发送通知.
</div>
<div class="form-group">
<textarea class="form-control" style="min-height:20px" placeholder="请使用Markdown撰写内容"
name="content" cols="50" rows="10"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
<button type="submit" class="btn btn-primary">提交</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- Reply List -->
<div class="replies panel panel-default list-panel replies-index">
<div class="panel-heading">
<div class="total">回复总数: <b>1</b></div>
</div>
<c:forEach items="${commentLogin}" var="c">
<div class="panel-body">
<ul class="list-group row">
<li class="list-group-item media " id="reply11">
<div class="avatar pull-left">
<a href="my.html"> <img class="media-object img-thumbnail avatar" alt="strdemo"
src="/images/avatar_small.jpg" style="width:48px;height:48px;"/>
</a>
</div>
<div class="infos">
<div class="media-heading meta">
<a href="my.html" title="strdemo" class="remove-padding-left author">${c.username}</a>
<abbr class="timeago" title="create_time">${c.createTime}</abbr> <a
name="reply1" class="anchor" href="#reply1" aria-hidden="true">#1</a>
</div>
<div class="media-body markdown-reply content-body">
${c.content}
</div>
</div>
</li>
</ul>
<!-- Pager -->
<div class="pull-right" style="padding-right:20px">
</div>
</div>
</c:forEach>
</div>
<!-- Reply Box -->
<div class="panel panel-default">
<div class="panel-heading">
发表回复
</div>
<div class="panel-body">
<div class="reply-box form">
<!-- 已经登录的情况 -->
<form:form modelAttribute="postGetLogin" action="/comment/add" accept-charset="UTF-8" id="thread_create_form" class="create_form">
<form:input type="hidden" path="id" value="${postGetLogin.id}"/>
<div class="form-group">
<form:textarea cssClass="post-editor form-control" rows="5" style="overflow:hidden" path="content" placeholder="请使用Markdown撰写内容" cols="50"></form:textarea>
</div>
<div class="form-group status-post-submit">
<input class="btn btn-primary col-xs-2" id="thread-create-submit" type="submit" value="回复">
</div>
</form:form>
</div>
</div>
</div>
</div>
<div class="col-md-3 side-bar">
<div class="panel panel-default corner-radius">
<div class="panel-heading">
<h3 class="panel-title">BBS</h3>
</div>
<!-- 已登录的情况 -->
<div class="panel-body text-center">
<a href="/post/to_add" class="btn btn-primary">
<i class="fa fa-user"> </i> 发帖
</a>
</div>
</div>
<div class="panel panel-default corner-radius">
<div class="panel-heading">
<h3 class="panel-title">小贴士</h3>
</div>
<div class="panel-body">
心若没有栖息的地方,到哪里都是在流浪!
</div>
</div>
<div class="panel panel-default corner-radius">
<div class="panel-heading">
<h3 class="panel-title">统计信息</h3>
</div>
<ul class="list-group">
<li class="list-group-item">社区会员: 747</li>
<li class="list-group-item">主题数: 95</li>
<li class="list-group-item">回帖数: 218</li>
</ul>
</div>
</div>
<div class="clearfix"></div>
</div>
<footer class="footer">
<div class="container">
<div class="copyright">
<blockquote class="pull-left">
<p>慕课论坛</p>
<p>Copyright © 2015-2016 <a href="index.html">imooc</a> 1.0.0-rc2 <span
class="pipe">|</span><span
class="pipe">|</span></p>
</blockquote>
</div>
<div class="pull-right hidden-sm hidden-xs">
<p>
<a href="###">关于我们</a> <span class="pipe">|</span> <a href="###">联系我们</a> <span class="pipe">|</span> <a
href="###">常见问题解答</a>
</p>
<p>
<a href="index.html" target="_blank"><img src="/images/imooc-logo.png" border="0" height="40"
data-toggle="tooltip" data-placement="top"
title="Powered by imooc"/></a>
</p>
</div>
</div>
</footer>
</body>
</html>
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.4//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.imooc.bbs.dao.CommentDao">
<resultMap id="comment" type="Comment">
<id property="id" column="id" javaType="Integer"></id>
<result property="userId" column="user_id" javaType="Integer"></result>
<result property="username" column="username" javaType="String"></result>
<result property="content" column="content" javaType="String"></result>
<result property="createTime" column="create_time" javaType="java.util.Date"></result>
<result property="postId" column="post_id" javaType="Integer"></result>
<association property="user" column="user_id" javaType="User">
<id property="id" column="cid" javaType="Integer"></id>
<result property="username" column="uusername" javaType="String"></result>
</association>
<association property="post" column="post_id" javaType="Post">
<id property="id" column="pid" javaType="Integer"></id>
<result property="content" column="pconetnt" javaType="String"></result>
</association>
</resultMap>
<insert id="insert" parameterType="Comment">
insert into comment(username,content,create_time,post_id) values(#{username},#{content},#{createTime},#{postId})
</insert>
<delete id="delete" parameterType="Integer">
delete from comment where id=#{id}
</delete>
<select id="select" parameterType="Integer" resultMap="comment">
select*from comment where id=#{id}
</select>
<select id="selectByPostId" resultMap="comment" parameterType="Integer">
select c.*,p.id pid,u.id uid,u.username uusername from comment c left join
post p on c.post_id=p.id left join user u on c.user_id=u.id
where c.post_id=#{pid}
</select>
<select id="selectByUserId" resultMap="comment" parameterType="Integer">
select c.*,p.id pid,u.id uid,u.username uusername from comment c left join
post p on c.post_id=p.id left join user u on c.user_id=u.id
where c.user_id=#{uid}
</select>
</mapper>
package com.imooc.bbs.dao;
import com.imooc.bbs.entity.Comment;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository("commentDao")
public interface CommentDao{
void insert(Comment comment);
List<Comment> selectByPostId(Integer pid);
List<Comment> selectByUserId(Integer uid);
Comment select(Integer id);
void delete(Integer id);
}
而且在回复页面的时候,form表单的
modelAttribute填写postGetLogin(贴子具体内容和回复的类一起)
就可以正常在网页显示。但当我填写commentAdd(添加回复的类)下面就不显示这是为什么
相关截图:
18
收起
正在回答
3回答
同学你好,同学是指不显示回复的内容吗?建议同学可以在代码中打上断点,查看是否有将回复的内容添加到map中,一起返回给前端页面。
祝学习愉快~
相似问题
登录后可查看更多问答,登录/注册
4. SSM到Spring Boot入门与综合实战
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星