1功能要求

功能包括:查询贴子、发表帖子、更新帖子点击量、查询某贴子详细信息(包含该贴的评论信息)、对某帖子发表评论等
详细描述:点击“正式进入”后可以查看所有已经发表的帖子,点击“某一条贴吧标题”后可进行详细信息查看,此时该条帖子的点击量要求增加1,今后每请求一次都会增加1,并能查看该条贴吧的所有信息(包含该贴吧的标题、作者、发表时间、点击量、以及对该贴的所有评论)。如点击图-2中标题为“牛妹”的贴吧后显示界面,输入评论信息(含评论作者、评论内容),点击“发表评论”,将数据存入数据库后,需跳转显示该条贴吧的所有最新信息(包含刚刚发表的新评论,评论按照评论时间进行降序排序,此时注意浏览量要增加1)

2数据库设计


3界面设计

in.jsp:

<html>
<head><title>Title</title>
</head>
<body><h2>欢迎进入尚学堂贴吧</h2><br/><a href="main.jsp">正式进入</a>
</body>
</html>

main.jsp:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<head><title>Title</title><script type="text/javascript" src="js/jquery-1.12.3.min.js"></script><script type="text/javascript">$(function () {/* $("#but").click(function () {alert("aaaa");})*///alert("aaaa");$.ajax({url:"selAllTopic",type:"post",success:function (data) {var list = eval(data);var str = "";for(var i=0;i<list.length;i++){str += '<tr>'+'<td><a href="selDetail?tid='+list[i].tid+'">'+list[i].title+'</a></td>'+'<td>'+list[i].author+'</td>'+'<td>'+list[i].cdate+'</td>'+'<td>'+list[i].clicknum+'</td>'+'</tr>';}$("#tbody").html(str);}})})</script>
</head>
<body><a href="addTopic.jsp">我要发帖</a><br/><br/><br/><table><thead><tr><th>标题</th><th>发帖人</th><th>发帖时间</th><th>浏览量</th></tr></thead><tbody id="tbody"></tbody></table>
<%--<input type="button" value="测试" id="but">--%>
</body>
</html>

addTopic.jsp:

<html>
<head><title>Title</title>
</head>
<body><form action="addTopic" method="post"><p>标题:<input type="text" name="title" value=""/></p><p>发帖人:<input type="text" name="author" value=""/></p><p>内容:<textarea rows="20" cols="50" name="content"></textarea></p><p><input type="submit"  value="提交"/></p></form>
${mes}
</body>
</html>

detail.jsp:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head><title>Title</title>
</head>
<body>
<h4>${topic.title}${topic.author}<fmt:formatDate value="${topic.cdate}" type="both"/>共浏览过${topic.clicknum}</h4>
<span> ${topic.content}</span><hr/><span style="color: red;font-size: 20px;">以下是评论区</span>
<c:forEach items="${repList}" var="reply"><h4>${reply.author}<fmt:formatDate value="${reply.cdate}" type="both"/></h4><span> ${reply.content}</span><br /><span>================================</span>
</c:forEach><hr/><form action="addReply" method="post"><input type="hidden" name="tid" value="${topic.tid}"/><p>昵称:<input type="text" name="author" value=""/></p><p>评论:<textarea rows="10" cols="30" name="content"></textarea></p><p><input type="submit" value="发表评论"/></p></form>
</body>
</html>

4代码实现

配置文件(主要配置):

 <bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource"><property name="driverClassName" value="com.mysql.jdbc.Driver"></property><property name="url" value="jdbc:mysql://localhost:3306/zhang"></property><property name="username" value="root"></property><property name="password" value="root"></property></bean><bean id="factory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="ds"></property><property name="typeAliasesPackage" value="an.sz.pojo"></property></bean><bean id="mapper" class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="sqlSessionFactoryBeanName" value="factory"></property><property name="basePackage" value="an.sz.mapper"></property></bean>
 <context:component-scan base-package="an.sz.service.impl"></context:component-scan>
 <context:component-scan base-package="an.sz.controller"></context:component-scan><mvc:annotation-driven></mvc:annotation-driven><!--静态资源资源放行--><mvc:resources mapping="/js/**" location="/js/"></mvc:resources>
<context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext-*.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><servlet><servlet-name>mvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:springmvc.xml</param-value></init-param></servlet><servlet-mapping><servlet-name>mvc</servlet-name><url-pattern>/</url-pattern></servlet-mapping>

实体类的代码在此不做赘述
数据访问层的映射文件的编写:

<mapper namespace="an.sz.mapper.ReplyMapper"><select id="selAllReply" resultType="reply">select * from t_reply where tid=#{0} order by cdate desc</select><insert id="addReply" parameterType="reply">insert into t_reply values(default,#{tid},#{author},#{content},#{cdate})</insert>
</mapper>
<mapper namespace="an.sz.mapper.TopicMapper"><insert id="addTopic" parameterType="topic">insert into t_topic values(default,#{title},#{content},#{author},#{cdate},default)</insert><select id="selAllTopic" resultType="topic">select * from t_topic order by cdate desc</select><select id="selOneTopic" parameterType="int" resultType="topic">select * from t_topic where tid=#{0}</select><update id="updateNum">update t_topic set clicknum = #{1} where tid=#{0}</update>
</mapper>

业务层的代码编写:

@Service
public class TopicServiceImpl implements TopicService {@AutowiredTopicMapper tMapper;@AutowiredReplyMapper rMapper;@Overridepublic int addTopic(Topic topic) {return tMapper.addTopic(topic);}@Overridepublic List<Topic> selAllTopic() {List<Topic> list = tMapper.selAllTopic();return list;}@Overridepublic Topic selOneTopic(int tid) {Topic topic = tMapper.selOneTopic(tid);return topic;}@Overridepublic List<Reply> selAllReply(int tid) {List<Reply> list = rMapper.selAllReply(tid);return list;}@Overridepublic int updateNum(int tid, int clicknum) {return tMapper.updateNum(tid, clicknum);}@Overridepublic int addReply(Reply reply) {return rMapper.addReply(reply);}
}

控制层的代码编写:

@Controller
public class MyController {@AutowiredTopicService ts;//@RequestMapping(value = "ajax2",produces = "application/json;charset=UTF-8")//@RequestMapping(value="addTopic",produces = "text/html;charset=utf-8")@RequestMapping("addTopic")public String addTopic(String title, String author, String content, HttpServletRequest req,HttpServletResponse resp) throws UnsupportedEncodingException {System.out.println(title+"---"+content+"---"+author);Date cdate = new Date();//System.out.println(cdate);Topic topic = new Topic(title,content,author,cdate);int num = ts.addTopic(topic);if(num>0){return "redirect:/main.jsp";}else{req.setAttribute("mes","发表帖子失败");return "forward:/addTopic.jsp";}}@RequestMapping("selAllTopic")@ResponseBodypublic void selAllTopic(HttpServletResponse resp) throws IOException {List<Topic> list = ts.selAllTopic();//System.out.println(list);Gson json = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();resp.getWriter().println(json.toJson(list));}@RequestMapping("selDetail")public String selOneTopic(int tid,HttpServletRequest req){//根据tid查询topic信息Topic top = ts.selOneTopic(tid);int clicknum = top.getClicknum();clicknum = clicknum+1;ts.updateNum(tid,clicknum);Topic topic = ts.selOneTopic(tid);req.setAttribute("topic",topic);//根据tid查询所有的reply信息List<Reply> repList = ts.selAllReply(tid);req.setAttribute("repList",repList);return "forward:/detail.jsp";}@RequestMapping("addReply")public String addReply(int tid,String author,String content){Date cdate = new Date();Reply reply = new Reply(tid,author,content,cdate);int num = ts.addReply(reply);return "forward:/selDetail?tid="+tid;}}

基于SSM的贴吧案例相关推荐

  1. Java Web 程序设计----基于SSM框架(正在更新中)

    Java Web 程序设计----基于SSM框架 提示:主要用于个人学习.复习.查阅等. 文章目录 Java Web 程序设计----基于SSM框架 一.网页前端开发基础 HTML文档结构 提示:以下 ...

  2. ssm框架验证码图片加载不出_基于SSM框架的文件图片上传/下载功能实现

    前一段时间很多做毕业设计的同学问:如何写图片和文件的上传下载功能,今天正好有时间,所以就做了一个案例,详细的讲解这个功能. 框架结构: 对于很多做过开发的而言,上传功能肯定都用过,而且用到的场景很多, ...

  3. 基于ssm整合的网上书城

    基于ssm整合的网上书城 采用当前最流行的框架Spring-SpringMVC-MyBatis设计,分为前后台,前台用户可以购买书籍,后台管理员可以对书籍进行分类,增删改查 注意:本系统不支持jdk1 ...

  4. java基于ssm+jsp的抑郁症心理健康科普交流网站

    SpringMVC是MVC的改改,它也属于Spring框架,可以零配置的进行开发,缩减了开发的时间,当用户通过浏览器发送Request请求时,在配置文件里通过DispatcherServlet前端进行 ...

  5. 基于SSM的创意商城动态网站【毕设-附源码】

    基于SSM的创意商城动态网站 目 录 1 引言 1 1.1 课题背景 1 1.2 目的和意义 1 1.3系统开发技术的特色 1 1.4 论文结构安排 2 2 创意商城的需求分析 3 2.1 系统可行性 ...

  6. [Shiro教程] Shiro 教程基于SSM(SpringMVC + Spring + Mybatis)EHCache版本

    一.Shiro简介 Apache Shiro 是 Java  的一个安全框架.我们经常看到它被拿来和 Spring  的 Security  来对比.大部分人认为 Shiro  比 Security  ...

  7. [Shiro教程] Shiro 教程基于SSM(SpringMVC + Spring + Mybatis)

    一.Shiro简介 Apache Shiro 是 Java  的一个安全框架.我们经常看到它被拿来和 Spring  的 Security  来对比.大部分人认为 Shiro  比 Security  ...

  8. 基于SSM技术的医院在线预约诊疗系统设计与实现毕业设计源码011130

    医院在线预约诊疗系统的设计与实现 摘 要 随着互联网趋势的到来,各行各业都在考虑利用互联网将自己推广出去,最好方式就是建立自己的互联网系统,并对其进行维护和管理.在现实运用中,应用软件的工作规则和开发 ...

  9. 基于SSM技术的医院在线预约诊疗系统设计与实现 毕业设计-附源码011130

    医院在线预约诊疗系统的设计与实现 摘 要 随着互联网趋势的到来,各行各业都在考虑利用互联网将自己推广出去,最好方式就是建立自己的互联网系统,并对其进行维护和管理.在现实运用中,应用软件的工作规则和开发 ...

最新文章

  1. python开发教程视频教程_金牌大神讲师Alex带你学Python 153节课带你轻松学透Python开发视频教程_IT教程网...
  2. python读取第二行_从CSV文件读取第二行到Python
  3. pcie总线连接两台电脑_基于PCIE总线多主互连系统的设计与实现
  4. 自定义SharePoint Webservice
  5. 蜡染印花的跟踪印花与二次整纬
  6. UVA11526 H(n)【数学】
  7. php mysql网页象棋源码_Android项目源码安卓联网中国象棋源码
  8. 并联串联混合的电压和电流_电子电路基础,教你看懂电子电路,简单的串并联...
  9. win11提示windows许可证即将过期
  10. python怎么编辑浏览器_怎样修改anaconda默认浏览器
  11. 如何优雅地重启go程序--endless篇
  12. 二维数字图像相关算法软件Ncorr的使用心得
  13. php 2038,php在2038年后datetime类也无法获得当前日期的解决
  14. 同济高数第七版上册54页例1详细证明过程
  15. 清除file类型的input值
  16. redhat linux光盘4,技巧:把3张Redhat Linux 9的安装光盘刻录到一张DVD光盘中
  17. 淘宝无线端店铺权重提升方法技巧步骤
  18. web应用测试的具体流程(等保测评相关)
  19. 天涯明月刀7月5号服务器维护,天涯明月刀8月5日维护内容_天涯明月刀8月5日维护结束时间、8月5日维护公告_牛游戏网...
  20. 众安在线:提出保险通证化,力推10余个区块链应用产品 |追击上市公司

热门文章

  1. MongoTemplate的使用
  2. 下列哪项不属于以太网交换机的特点_下列关于以太网二层交换机特点的描述,正确的是( )...
  3. java 显示文本框_java计算器文本框显示
  4. bzoj 1862 [Zjoi2006]GameZ游戏排名系统
  5. 未来企业IT技术关注点及IT架构变革探讨
  6. 模拟linux内核异常,Linux内核态缺页会发生什么 - 玩转Exception fixup表
  7. 1.智能健身项目复盘
  8. UE的RRC状态切换
  9. C#-创建txt文本
  10. 开始菜单跑到左边去了_win10下面菜单栏到左边了怎么办