1、新建一个maven工程和数据库
1.1maven web工程:
1.2数据库:
帖子表:
评论表:
2、新建相关工程目录:
3.在pom.xml中放入相关依赖包
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-oxm -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-aop -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.1.2.RELEASE</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/jstl/jstl -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.53</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.codehaus.jackson/jackson-mapper-asl -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.mchange/c3p0 -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.6.0</version>
</dependency>
<dependency> <groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version> </dependency>
4、配置相关核心配置:
(这里按照文件顺序来吧)
(注意:如果修改了包名,请修改相应的地方)
4.1TopicController:
package com.lemonsun.controller;
import com.lemonsun.pojo.Reply;
import com.lemonsun.pojo.Topic;
import com.lemonsun.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
@Controller
public class TopicController{
@Autowired
private TopicService topicService;
//查询所有帖子
@RequestMapping("/topicListService.do")
public String topicListService(Model model) {
//去数据库查找所有帖子信息
List<Topic> list = topicService.topicListService();
//返回model层
model.addAttribute("list", list);
//返回帖子信息展示页面
return "homepage";
}
//添加帖子
@RequestMapping("/addTopicInf.do")
public String addTopicInf(HttpServletRequest request) throws UnsupportedEncodingException {
Topic topic = new Topic();
topic.setTitle(new String(request.getParameter("title").getBytes("iso-8859-1"), "utf-8"));
topic.setAuthor(new String(request.getParameter("author").getBytes("iso-8859-1"), "utf-8"));
topic.setContent(new String(request.getParameter("context").getBytes("iso-8859-1"), "utf-8"));
topic.setCretime(new Timestamp(new Date().getTime()));
topicService.addTopicInf(topic);
return "addSuccess";
}
//查看某个帖子信息
@RequestMapping("/findAllTopicbyId.do")
public String findAllTopicbyId(Integer id, Model model) {
//点击量加一
topicService.add_click_amount_byId(id);
//获取帖子信息
Topic topic = topicService.findAllTopicbyId(id);
System.out.println("topic:"+topic);
model.addAttribute("topic", topic);
//获取评论信息
List<Topic> replylist = topicService.findAllReplyId(id);
model.addAttribute("replylist", replylist);
//传入帖子id
model.addAttribute("topicId", id);
//返回客户信息展示页面
return "showTopic";
}
//添加评论
@RequestMapping("/addReplyInf.do")
public String addReplyInf(HttpServletRequest request,Model model) throws UnsupportedEncodingException {
Reply reply = new Reply();
//测试是否获取到该帖子的id
String id = request.getParameter("topicid");
//因为转码的问题
reply.setAuthon(new String(request.getParameter("reply_author").getBytes("iso-8859-1"), "utf-8"));
reply.setContent(new String(request.getParameter("reply_context").getBytes("iso-8859-1"), "utf-8"));
reply.setT_id(new Integer(request.getParameter("topicid")));
//设置当前时间
reply.setCretime(new Timestamp(new Date().getTime()));
//返回给方法 去数据库添加
topicService.addReplyInf(reply);
//添加成功 到成功界面
return "addSuccessReply";
}
}
4.2CustomerDao
(dao层实现与数据库的交互,具体实现在.xml里)
package com.lemonsun.dao;
import com.lemonsun.pojo.Reply;
import com.lemonsun.pojo.Topic;
import java.util.List;
/**
* Customer接口文件
*/
public interface CustomerDao {
//查询所有帖子
List<Topic> topicListService();
//添加帖子
int addTopicInf(Topic topic);
//查看某个帖子信息
Topic findAllTopicbyId(Integer id);
//点击量自增
int add_click_amount_byId(Integer id);
//查看某个帖子评论信息
List<Topic> findAllReplyId(Integer id);
//添加评论
int addReplyInf(Reply reply);
}
4.3Reply
(评论实体类,注意创建实体时,尽量与数据库对应的名字一样)
package com.lemonsun.pojo;
import java.sql.Timestamp;
/*
*评论
*/
public class Reply {
//评论id
private int reply_id;
//被评论的帖子id
private int topic_id;
//评论者
private String author;
//评论时间
private Timestamp cretime;
//评论内容
private String content;
public Reply() {
}
public Reply(int r_id, int t_id, String author, Timestamp cretime, String content) {
this.reply_id = r_id;
this.topic_id = t_id;
this.author = author;
this.cretime = cretime;
this.content = content;
}
public int getR_id() {
return reply_id;
}
public void setR_id(int r_id) {
this.reply_id = r_id;
}
public int getT_id() {
return topic_id;
}
public void setT_id(int t_id) {
this.topic_id = t_id;
}
public String getAuthon() {
return author;
}
public void setAuthon(String authon) {
this.author = authon;
}
public Timestamp getCretime() {
return cretime;
}
public void setCretime(Timestamp cretime) {
this.cretime = cretime;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
@Override
public String toString() {
return "Reply{" +
"r_id=" + reply_id +
", t_id=" + topic_id +
", authon='" + author + '\'' +
", cretime=" + cretime +
", content='" + content + '\'' +
'}';
}
}
4.4Topic
(帖子实体类)
package com.lemonsun.pojo;
import java.sql.Timestamp;
/*
*贴子表
*/
public class Topic {
//帖子编号
private Integer id;
//标题
private String title;
//内容
private String content;
//作者
private String author;
//发帖时间
private Timestamp create_time;
//点击量
private int click_amount;
//评论
private Reply reply;
public Topic() {
}
public Topic(String title, String author, Timestamp cretime, int amount) {
this.title = title;
this.author = author;
this.create_time = cretime;
this.click_amount = amount;
}
public Topic(Integer id, String title, String content, String author, Timestamp cretime, int amount) {
this.id = id;
this.title = title;
this.content = content;
this.author = author;
this.create_time = cretime;
this.click_amount = amount;
}
public Topic(Integer id, String title, String content, String author, Timestamp cretime, int amount, Reply reply) {
this.id = id;
this.title = title;
this.content = content;
this.author = author;
this.create_time = cretime;
this.click_amount = amount;
this.reply = reply;
}
public Reply getReply() {
return reply;
}
public void setReply(Reply reply) {
this.reply = reply;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public Timestamp getCretime() {
return create_time;
}
public void setCretime( Timestamp cretime) {
this.create_time = cretime;
}
public int getAmount() {
return click_amount;
}
public void setAmount(int amount) {
this.click_amount = amount;
}
@Override
public String toString() {
return "Topic{" +
"id=" + id +
", title='" + title + '\'' +
", content='" + content + '\'' +
", author='" + author + '\'' +
", cretime=" + create_time +
", amount=" + click_amount +
'}';
}
}
4.5TopicService
package com.lemonsun.service;
import com.lemonsun.pojo.Reply;
import com.lemonsun.pojo.Topic;
import java.util.List;
/*
*服务层接口
*/
public interface TopicService {
//查询所有帖子
List<Topic> topicListService();
//发表帖子
int addTopicInf(Topic topic);
//查看某个帖子信息
Topic findAllTopicbyId(Integer id);
//点击量自增
int add_click_amount_byId(Integer id);
//查看某个帖子评论信息
List<Topic> findAllReplyId(Integer id);
//添加评论
int addReplyInf(Reply reply);
}
4.6TopicServiceImpl
package com.lemonsun.service.impl;
import com.lemonsun.dao.CustomerDao;
import com.lemonsun.pojo.Reply;
import com.lemonsun.pojo.Topic;
import com.lemonsun.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/*
*业务层
*/
@Service
@Transactional
public class TopicServiceImpl implements TopicService {
//注解注入CustomerDao
@Autowired
private CustomerDao customerDao;
//查询所有帖子信息
@Override
public List <Topic> topicListService() {
//调用dao
return customerDao.topicListService();
}
//发表帖子
@Override
public int addTopicInf(Topic topic) {
return customerDao.addTopicInf(topic);
}
//查看某个帖子信息
@Override
public Topic findAllTopicbyId(Integer id) {
return customerDao.findAllTopicbyId(id);
}
//点击量
@Override
public int add_click_amount_byId(Integer id) {
return customerDao.add_click_amount_byId(id);
}
//查看某个帖子评论信息
@Override
public List<Topic> findAllReplyId(Integer id) {
return customerDao.findAllReplyId(id);
}
//添加评论
@Override
public int addReplyInf(Reply reply) {
return customerDao.addReplyInf(reply);
}
}
4.7CustomerDao.xml
(customer dao层的具体实现)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lemonsun.dao.CustomerDao">
<!--查询帖子信息-->
<select id="findAllTopicbyId" parameterType="Integer" resultType="Topic">
select * from t_topic where topic_id = #{id}
</select>
<!--查询所有帖子-->
<resultMap id="topicall" type="com.lemonsun.pojo.Topic">
<id property="id" column="topic_id"/>
<result property="title" column="title"/>
<result property="author" column="author"/>
<result property="content" column="content"/>
<result property="click_amount" column="click_amount"/>
<result property="create_time" column="create_time"/>
</resultMap>
<select id="topicListService" resultMap="topicall">
select topic_id,title,author,content,click_amount,create_time from t_topic order by create_time desc
</select>
<!--发帖-->
<insert id="addTopicInf" parameterType="com.lemonsun.pojo.Topic" useGeneratedKeys="true" keyProperty="user_id">
insert into t_topic(topic_id,title,content,author,create_time,click_amount)
values(#{id}, #{title}, #{content},#{author}, #{cretime}, #{amount});
</insert>
<!--点击量自增-->
<update id="add_click_amount_byId" parameterType="Integer">
update t_topic set click_amount =click_amount+1 where topic_id = #{id};
</update>
<!--查询所有评论-->
<select id="findAllReplyId"
resultType="com.lemonsun.pojo.Topic" parameterType="Integer" >
select * from t_reply where topic_id = #{id} order by create_time desc;
</select>
<!--评论-->
<insert id="addReplyInf" parameterType="com.lemonsun.pojo.Reply" useGeneratedKeys="true" keyProperty="user_id">
insert into t_reply(topic_id,author,content,create_time)
values(#{topic_id}, #{author}, #{content},#{cretime});
</insert>
</mapper>
4.8mybatis-cofing.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 别名定义 -->
<typeAliases>
<package name="com.lemonsun.pojo" />
</typeAliases>
</configuration>
4.9applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
<!-- 读取db.properties -->
<context:property-placeholder location="classpath:db.properties"/>
<!-- 配置数据源 -->
<bean id="dataSource"
class="org.apache.commons.dbcp2.BasicDataSource">
<!--数据库驱动 -->
<property name="driverClassName" value="${jdbc.driver}" />
<!--连接数据库的url -->
<property name="url" value="${jdbc.url}" />
<!--连接数据库的用户名 -->
<property name="username" value="${jdbc.username}" />
<!--连接数据库的密码 -->
<property name="password" value="${jdbc.password}" />
<!--最大连接数 -->
<property name="maxTotal" value="${jdbc.maxTotal}" />
<!--最大空闲连接 -->
<property name="maxIdle" value="${jdbc.maxIdle}" />
<!--初始化连接数 -->
<property name="initialSize" value="${jdbc.initialSize}" />
</bean>
<!-- 事务管理器,依赖于数据源 -->
<bean id="transactionManager" class=
"org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 开启事务注解 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- 配置MyBatis工厂SqlSessionFactory -->
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<!--注入数据源 -->
<property name="dataSource" ref="dataSource" />
<!--指定核MyBatis心配置文件位置 -->
<property name="configLocation" value="classpath:mybatis/mybatis-cofing.xml" />
<!-- 添加mapper文件映射 -->
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
</bean>
<!-- 配置mapper扫描器 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.lemonsun.dao"/>
</bean>
<!-- 扫描Service -->
<context:component-scan base-package="com.lemonsun.service" />
</beans>
4.10spring-confing.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<!-- 配置包扫描器,扫描@Controller注解的类 -->
<context:component-scan base-package="com.lemonsun.controller" />
<!-- 加载注解驱动 -->
<mvc:annotation-driven />
<!-- 配置视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 前缀 -->
<property name="prefix" value="/" />
<!-- 后缀 -->
<property name="suffix" value=".jsp" />
</bean>
</beans>
4.11db.properties
(我这里数据库的账号:root ,密码:password,数据库名:123)
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3307/123?characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false
jdbc.username=root
jdbc.password=password
jdbc.maxTotal=30
jdbc.maxIdle=10
jdbc.initialSize=5
4.12log4j.properties
(日志)
# Global logging configuration
log4j.rootLogger=ERROR, stdout
# MyBatis logging configuration...
log4j.logger.com.lemonsun=DEBUG
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
4.13Bootstrap (前端框架)
下载地址:https://v3.bootcss.com/getting-started/#download
我提供的百度网盘:链接:https://pan.baidu.com/s/1gMHirtkHto0xCKwYe03dGQ
提取码:jet1
在webapp文件夹下新建static 加入下载好的bootstrap-3.3.7-dist,新建js文件夹加入jquery-3.3.1.min.js
4.14addSuccess.jsp
(发帖成功页面)
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2019/1/1 0001
Time: 22:28
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>添加成功</title>
<%--引用jquery--%>
<script type="text/javascript" src="static/js/jquery-3.3.1.min.js"></script>
<%--引入Jquery--%>
<%--引入样式--%>
<link href="static/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
<script src="static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
</head>
<body>
<form action="makePost.jsp">
<BUTTON href="makePost" class="btn btn-success">继续发帖</BUTTON>
</form>
<form action="/topicListService.do">
<BUTTON class="btn btn-success">返回主页</BUTTON>
</form>
</body>
</html>
4.15addSuccessReply.jsp
(评论成功界面)
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2019/1/5 0005
Time: 19:05
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>评论</title>
<%--引用jquery--%>
<script type="text/javascript" src="static/js/jquery-3.3.1.min.js"></script>
<%--引入Jquery--%>
<%--引入样式--%>
<link href="static/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
<script src="static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
</head>
<body>
<form action="/topicListService.do">
<BUTTON class="btn btn-success">返回主页</BUTTON>
</form>
</body>
</html>
4.16homepage.jsp
<显示所有帖子界面>
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2018/12/30 0030
Time: 12:24
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@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>
<%--引用jquery--%>
<script type="text/javascript" src="static/js/jquery-3.3.1.min.js"></script>
<%--引入Jquery--%>
<%--引入样式--%>
<link href="static/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
<script src="static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
</head>
<body>
<a href="makePost.jsp"><h3>我要发帖...</h3></a> <br>
<div class="container">
<table class="table">
<thead>
<tr class="info" style="font-weight:bold;" >
<th>标题</th>
<th>发帖人</th>
<th> 发帖时间</th>
<th>浏览量</th>
</tr>
</thead>
<tbody>
<c:forEach items="${list}" var="each">
<tr class="danger" id="dataTopic">
<td><a href="/findAllTopicbyId.do?id=${each.id}">${each.title}</a></td>
<td>${each.author}</td>
<td><fmt:formatDate value="${each.cretime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
<td>${each.amount}</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</body>
</html>
4.17index.jsp
(欢迎界面)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<title>夙愿贴吧</title>
<%--引用jquery--%>
<script type="text/javascript" src="static/js/jquery-3.3.1.min.js"></script>
<%--引入Jquery--%>
<%--引入样式--%>
<link href="static/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
<script src="static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<body>
<h2><string><p class="text-center">欢迎来到夙愿贴吧</p></string></h2>
<div >
<a href="/topicListService.do" class="text-success col-md-3 col-md-offset-3">点击进入...</a>
</div>
</body>
</html>
4.18makePost.jsp
(发帖界面)
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2018/12/30 0030
Time: 13:22
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>夙愿贴吧</title>
<%--引用jquery--%>
<script type="text/javascript" src="static/js/jquery-3.3.1.min.js"></script>
<%--引入Jquery--%>
<%--引入样式--%>
<link href="static/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
<script src="static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
</head>
<body>
<h2><string><p class="text-center">欢迎发帖</p></string></h2>
<form action="/addTopicInf.do" method="post" >
<p class="text-primary">作者:<input type="text" name="author" style="height: 50px; width: 315px" ></p>
<p class="text-primary">标题:<input type="text" name="title" style="height: 50px; width: 315px"></p><br>
<p class="text-primary">内容: <textarea name="context" class="form-control" rows="3" style="margin: 0px 1031px 0px 0px; height: 300px; width: 360px; resize: none"></textarea></p>
<BUTTON class="btn btn-success col-md-2 " >发帖</BUTTON> <br>
</form>
</form> <form action="/topicListService.do">
<BUTTON class="btn btn-primary col-md-2">返回主页</BUTTON>
</form>
</body>
</html>
4.19showTopic.jsp
(查看某个帖子界面)
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2018/12/30 0030
Time: 12:24
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@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>
<%--引用jquery--%>
<script type="text/javascript" src="static/js/jquery-3.3.1.min.js"></script>
<%--引入Jquery--%>
<%--引入样式--%>
<link href="static/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
<script src="static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
</head>
<body>
<form action="makePost.jsp">
<BUTTON class="btn btn-success">我要发帖</BUTTON>
</form>
<form action="/topicListService.do">
<BUTTON class="btn btn-success">返回主页</BUTTON>
</form>
<div class="container">
<table class="table">
<thead>
<tr class="info" style="font-weight:bold;" >
<th>标题</th>
<th>发帖人</th>
<th>内容</th>
<th>发帖时间</th>
<th>浏览量</th>
</tr>
</thead>
<tbody>
<tr class="danger">
<td>${topic.title}</td>
<td>${topic.author}</td>
<td>${topic.content}</td>
<td><fmt:formatDate value="${topic.cretime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
<td>${topic.amount}</td>
</tr>
</tbody>
</table>
</div>
<div class="container">
<table class="table">
<thead>
<tr class="info" style="font-weight:bold;" >
<th>昵称</th>
<th>评论时间</th>
<th>内容</th>
</tr>
</thead>
<tbody>
<c:forEach items="${replylist}" var="replys">
<tr class="danger" id="dataTopic">
<td>${replys.author}</td>
<td><fmt:formatDate value="${replys.cretime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
<td>${replys.content}</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
<div>
<form action="/addReplyInf.do" method="post" >
<input type="hidden" name="topicid" value="${topicId}" >
<p class="text-primary">昵称:<input type="text" name="reply_author" style="height: 50px; width: 315px" ></p><br>
<p class="text-primary">内容: <textarea name="reply_context" class="form-control" rows="3" style="margin: 0px 1031px 0px 0px; height: 300px; width: 360px; resize: none"></textarea></p>
<BUTTON class="btn btn-success col-md-2 " >评论</BUTTON>
</form>
</div>
</body>
</html>
5相关界面
5.1欢迎界面:
5.2主界面:
5.3发帖界面
5.4查看某个帖子界面和发帖界面
到此一个简单的贴吧项目就完成了 。
该项目为本人第一个项目,仅供参考,学习ssm的使用基础,内有不足,欢迎评论!!!