目录
摘要
一、系统开发环境
二、数据库设计
三、实现的功能
四、详细设计
五、效果展示
摘要
- 游客可以浏览新闻,也可以通过新闻类别或新闻标题对新闻进行查找;
- 管理员可以增加新闻、修改新闻、根据新闻类别查找新闻、删除新闻,也可以增加类别、修改类别、删除类别;在删除类别时,该类别的新闻会被同时删除。
一、系统开发环境
Eclipse2021.03
jdk1.8.0
Tomcat9.0
Mysql8.0.26
二、数据库设计
新闻表t_news
类型表t_type
用户表t_user
三、实现的功能
普通用户(游客):
(1)显示所有新闻
(2)浏览新闻
(3)根据新闻类型对新闻进行查找
(4)根据新闻标题对新闻进行查找
管理员用户:
(1)显示所有新闻
(2)增加新闻
(3)修改新闻
(4)根据新闻类型对新闻进行查找
(5)删除新闻
(6)显示所有类别
(7)增加新闻类别
(8)修改新闻类别
(9)删除新闻类别
四、详细设计
- 开发步骤和主要代码
撰写流程:从dao —> service —> controller —> 视图
NewsDao.java
package zsls.news.dao;
import org.apache.ibatis.annotations.Param;
import zsls.news.pojo.News;
import java.util.List;
public interface NewsDao {
List<News> queryALL(@Param("tid") Integer tid,@Param("title") String title,@Param("num") int num );
News queryById(Integer id);
int save(News news);
int update(News news);
int deleteById(Integer id);
int deleteByTid(Integer tid);
}
TypeDao.java
package zsls.news.dao;
import org.apache.ibatis.annotations.Param;
import zsls.news.pojo.Type;
import java.util.List;
public interface TypeDao {
public List<Type> queryAllTypes();
public List<Type> queryType(@Param("name")String name);
public int insertType(@Param("name")String name);
public int deleteByRecid(String id);
Type queryById(Integer id);
int update(Type type);
}
UserDao.java
package zsls.news.dao;
import org.apache.ibatis.annotations.Param;
import zsls.news.pojo.User;
public interface UserDao {
public User queryUserByUsernameAndPassword(@Param("name")String username, @Param("pass")String password);
}
NewsService.java
package zsls.news.service;
import zsls.news.pojo.News;
import java.util.List;
public interface NewsService {
List<News> queryALL(Integer tid,String title,Integer pageNo);
News queryById(Integer id);
int save(News news);
int update(News news);
int deleteById(Integer id);
}
NewsServiceImpl.java
package zsls.news.service;
import zsls.news.dao.NewsDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import zsls.news.pojo.News;
import java.util.List;
@Service
public class NewsServiceImpl implements NewsService {
@Autowired
private NewsDao newsDao;
@Override
public List<News> queryALL(Integer tid,String title,Integer pageNo) {
if(title != null && !"".equals(title.trim())){
title = "%"+title+"%";
}
int num = (pageNo - 1) * 10;
return newsDao.queryALL(tid,title,num);
}
@Override
public News queryById(Integer id) {
return newsDao.queryById(id);
}
@Override
public int save(News news) {
return newsDao.save(news);
}
@Override
public int update(News news) {
return newsDao.update(news);
}
@Override
public int deleteById(Integer id) {
return newsDao.deleteById(id);
}
}
TypeService.java
package zsls.news.service;
import zsls.news.pojo.Type;
import java.util.List;
public interface TypeService {
public List<Type> queryAllTypes();
public int deleteByRecid(String recid);
int addType(String name);
Type queryById(Integer id);
int update(Type type);
}
TypeServiceImpl.java
package zsls.news.service;
import zsls.news.dao.NewsDao;
import zsls.news.dao.TypeDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import zsls.news.pojo.Type;
import java.util.List;
@Service
public class TypeServiceImpl implements TypeService {
@Autowired
private TypeDao typeDao;
@Autowired
private NewsDao newsDao;
@Override
public List<Type> queryAllTypes() {
// TODO Auto-generated method stub
return typeDao.queryAllTypes();
}
@Override
public int deleteByRecid(String recid) {
// TODO Auto-generated method stub
int i=typeDao.deleteByRecid(recid);
// 删除类型,把同类的新闻也全部删除
int deleteByTid = newsDao.deleteByTid(Integer.valueOf(recid));
return i;
}
@Override
public int addType(String name) {
return typeDao.insertType(name);
}
@Override
public Type queryById(Integer id) {
return typeDao.queryById(id);
}
@Override
public int update(Type type) {
return typeDao.update(type);
}
}
UserService.java
package zsls.news.service;
import zsls.news.pojo.User;
public interface UserService {
public User queryUserByUsernameAndPassword(String username, String password);
}
UserServiceImpl.java
package zsls.news.service;
import zsls.news.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import zsls.news.pojo.User;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserDao userDao;
@Override
public User queryUserByUsernameAndPassword(String username, String password) {
// TODO Auto-generated method stub
return userDao.queryUserByUsernameAndPassword(username, password);
}
}
AdminController.java
package zsls.news.controller;
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 zsls.news.pojo.News;
import zsls.news.pojo.Type;
import zsls.news.pojo.User;
import zsls.news.service.NewsService;
import zsls.news.service.TypeService;
import zsls.news.service.UserService;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;
@Controller
public class AdminController {
@Autowired
private UserService userService;
@Autowired
private TypeService typeService;
@Autowired
private NewsService newsService;
@RequestMapping("login.do")
public String login(String username, String password, HttpSession session, Model model){
User user=userService.queryUserByUsernameAndPassword(username, password);
System.out.println("当前正在执行控制器方法login...");
if(user!=null){
session.setAttribute("loginUser",user);
return "/manager/index";
}else{
model.addAttribute("msg","登录失败,请重新登录!");
return "/login";
}
}
@RequestMapping("logout.do")
public String logout(HttpSession session){
session.invalidate();
return "/login";
}
@RequestMapping("toLogin.do")
public String toLogin(){
return "/login";
}
@RequestMapping("admin/toIndex.do")
public String toIndex(){
return "/manager/index";
}
@RequestMapping("admin/queryAllTypes.do") //管理员方法
public String AdminQueryAllTypes(Model model){
List<Type> typelist=typeService.queryAllTypes();
model.addAttribute("typelist",typelist);
return "/manager/categoryList";
}
@RequestMapping("admin/toAddType.do")
public String toAddType(){
return "/manager/categoryAdd";
}
@RequestMapping("admin/addType.do")
public String addType(String name,Model model){
int i=typeService.addType(name);
if(i>0){
return "redirect:queryAllTypes.do";
}else{
model.addAttribute("msg","添加类型不成功!");
return "/error";
}
}
@RequestMapping("admin/toModifyType.do")
public String toModifyType(Integer recid,Model model){
Type type = typeService.queryById(recid);
model.addAttribute("type",type);
return "/manager/categoryModify";
}
@RequestMapping("admin/modifyType.do")
public String modifyType(Type type,Model model){
int i=typeService.update(type);
if(i>0){
return "redirect:queryAllTypes.do";
}else{
model.addAttribute("msg","修改类型不成功!");
return "/error";
}
}
@RequestMapping("admin/delete.do") //管理员方法
public String deleteByRecid(String recid,Model model){
int i=typeService.deleteByRecid(recid);
if(i>0){
return "redirect:queryAllTypes.do";
}else{
model.addAttribute("msg","删除类型不成功!");
return "/error";
}
}
@RequestMapping("admin/queryAllNews.do") //管理员方法
public String AdminQueryAllNews(Integer tid,Integer pageNo,Model model){
if(pageNo == null || pageNo < 1){
pageNo = 1;
}
List<News> newsList = newsService.queryALL(tid,null,pageNo);
model.addAttribute("newsList",newsList);
List<Type> typelist=typeService.queryAllTypes();
model.addAttribute("typelist",typelist);
model.addAttribute("pageNo1",pageNo-1);
model.addAttribute("pageNo",pageNo);
model.addAttribute("pageNo2",pageNo+1);
model.addAttribute("tid",tid);
return "/manager/newsList";
}
@RequestMapping("admin/toAddNews.do")
public String toAddNews(Model model){
List<Type> typelist=typeService.queryAllTypes();
model.addAttribute("typelist",typelist);
return "/manager/newsAdd";
}
@RequestMapping("admin/addNews.do")
public String addNews(News news,Model model){
if(news.getTid() == null ){
model.addAttribute("msg","添加新闻类型不能为空!");
return "/error";
}
if(news.getTitle() == null || "".equals(news.getTitle()) || news.getContent() == null || "".equals(news.getContent())){
model.addAttribute("msg","添加新闻标题或内容不能为空!");
return "/error";
}
news.setDate(new Date());
int i=newsService.save(news);
if(i>0){
return "redirect:queryAllNews.do";
}else{
model.addAttribute("msg","添加新闻不成功!");
return "/error";
}
}
@RequestMapping("admin/deleteNews.do")
public String deleteNews(Integer id,Model model){
int i=newsService.deleteById(id);
if(i>0){
return "redirect:queryAllNews.do";
}else{
model.addAttribute("msg","删除新闻不成功!");
return "/error";
}
}
@RequestMapping("admin/toModifyNews.do")
public String toModifyNews(Integer id,Model model){
News news = newsService.queryById(id);
model.addAttribute("news",news);
return "/manager/newsModify";
}
@RequestMapping("admin/modifyNews.do")
public String modifyNews(News news,Model model){
news.setDate(new Date());
int i= newsService.update(news);
if(i>0){
return "redirect:queryAllNews.do";
}else{
model.addAttribute("msg","修改新闻不成功!");
return "/error";
}
}
@RequestMapping("queryAllTypes.do")
public String queryAllBooks(Model model){
List<Type> typelist=typeService.queryAllTypes();
model.addAttribute("typelist",typelist);
return "index";
}
}
VisitorController.java
package zsls.news.controller;
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 zsls.news.pojo.News;
import zsls.news.pojo.Type;
import zsls.news.service.NewsService;
import zsls.news.service.TypeService;
import java.util.List;
@Controller
public class VisitorController {
@Autowired
private TypeService typeService;
@Autowired
private NewsService newsService;
@RequestMapping("visitor/toIndex.do")
public String toIndex(){
return "/index";
}
@RequestMapping("visitor/queryAllNews.do")
public String queryAllNews(Integer tid,String title,Integer pageNo, Model model){
if(pageNo == null || pageNo < 1){
pageNo = 1;
}
List<News> newsList = newsService.queryALL(tid,title,pageNo);
model.addAttribute("newsList",newsList);
List<Type> typelist=typeService.queryAllTypes();
model.addAttribute("typelist",typelist);
model.addAttribute("pageNo1",pageNo-1);
model.addAttribute("pageNo",pageNo);
model.addAttribute("pageNo2",pageNo+1);
model.addAttribute("tid",tid);
model.addAttribute("title",title);
return "/search";
}
@RequestMapping("visitor/queryNews.do")
public String queryNews(Integer id, Model model){
News news = newsService.queryById(id);
model.addAttribute("news",news);
Type type = typeService.queryById(news.getTid());
model.addAttribute("type",type);
return "/info";
}
}
index.jsp (管理员)
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body background="${pageContext.request.contextPath}/images/bg.jpg">
欢迎您,${loginUser.name}
<a href="${pageContext.request.contextPath}/admin/toIndex.do">主页</a>
<a href="${pageContext.request.contextPath}/admin/queryAllNews.do">新闻列表</a>
<a href="${pageContext.request.contextPath}/admin/queryAllTypes.do">类型列表</a>
<a href="${pageContext.request.contextPath}/logout.do">注销</a>
<hr>
<br/>
<div style="margin-left: 40%">
<p> 欢迎来到</p>
<p>系统的后台管理</p>
</div>
</body>
</html>
index.jsp (游客)
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body background="${pageContext.request.contextPath}/images/bg.jpg">
欢迎您
<a href="${pageContext.request.contextPath}/visitor/toIndex.do">主页</a>
<a href="${pageContext.request.contextPath}/visitor/queryAllNews.do">新闻列表</a>
<a href="${pageContext.request.contextPath}/login.jsp">登录</a>
<hr>
<br/>
<div style="margin-left: 40%">
<p>欢迎来浏览新闻</p>
</div>
</body>
</html>
LoginInterceptor.java (登录拦截器)
package zsls.news.interceptor;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class LoginInterceptor implements HandlerInterceptor {
@Override
public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
throws Exception {
// 该方法是在整个请求执行即渲染结束后执行,通过此方法实现一些资源清理,记录日志信息等工作
System.out.println("执行afterCompletion....");
}
@Override
public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView mv)
throws Exception {
该方法是在控制器方法调用之后,且视图解析还没进行之前
System.out.println("执行postHandle....");
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
// 该方法是在控制器方法执行前执行,如果为真,则继续下一步的操作,也就是接着执行控制器方法或调用下一个拦截器;为假,则中断
System.out.println("执行preHandle....");
//获取当前请求的地址
String uri=request.getRequestURI();
if(uri.indexOf("login")>0) { //当前你的请求是login,放行
return true;
}
HttpSession session=request.getSession();
if(session.getAttribute("loginUser")!=null) {
return true;
}
session.setAttribute("errorMsg","您还没有登录,请先登录!");
request.getRequestDispatcher("/login.jsp").forward(request, response);
return false;
}
}
login.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
${sessionScope.errorMsg}
<form action="${pageContext.request.contextPath}/login.do" method="post">
username:<input type="text" name="username"><br>
password:<input type="password" name="password"><br>
<input type="submit" value="login"/>
</form>
<div>
<br/>
<a href="${pageContext.request.contextPath}/visitor/toIndex.do" style="font-size: 24px;">游客主页</a>
</div>
</body>
</html>
categoryAdd.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body background="${pageContext.request.contextPath}/images/bg.jpg">
欢迎您,${loginUser.name}
<a href="${pageContext.request.contextPath}/admin/toIndex.do">主页</a>
<a href="${pageContext.request.contextPath}/admin/queryAllNews.do">新闻列表</a>
<a href="${pageContext.request.contextPath}/admin/queryAllTypes.do">类型列表</a>
<a href="${pageContext.request.contextPath}/logout.do">注销</a>
<hr>
<br/>
<div style="margin-left: 20%;width: 50%">
<form action="${pageContext.request.contextPath}/admin/addType.do" method="post">
<label>类型名称:</label><input type="text" name="name">
<br/>
<button type="submit">添加</button>
</form>
</div>
</body>
</html>
categoryList.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body background="${pageContext.request.contextPath}/images/bg.jpg">
欢迎您,${loginUser.name}
<a href="${pageContext.request.contextPath}/admin/toIndex.do">主页</a>
<a href="${pageContext.request.contextPath}/admin/queryAllNews.do">新闻列表</a>
<a href="${pageContext.request.contextPath}/admin/queryAllTypes.do">类型列表</a>
<a href="${pageContext.request.contextPath}/logout.do">注销</a>
<hr>
<br/>
<div style="margin-left: 20%;width: 50%">
<a href="${pageContext.request.contextPath}/admin/toAddType.do">添加类型</a>
<br/>
<table border="1" style="width: 80%">
<thead>
<th>类别编号</th>
<th>类别名称</th>
<th>删除</th>
<th>编辑</th>
</thead>
<c:forEach items="${typelist}" var="type">
<tr>
<td>${type.id}</td>
<td>${type.name}</td>
<td><a href="${pageContext.request.contextPath}/admin/delete.do?recid=${type.id }">删除</a></td>
<td><a href="${pageContext.request.contextPath}/admin/toModifyType.do?recid=${type.id }">编辑</a></td>
</tr>
</c:forEach>
</table>
</div>
</body>
</html>
categoryModify.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body background="${pageContext.request.contextPath}/images/bg.jpg">
欢迎您,${loginUser.name}
<a href="${pageContext.request.contextPath}/admin/toIndex.do">主页</a>
<a href="${pageContext.request.contextPath}/admin/queryAllNews.do">新闻列表</a>
<a href="${pageContext.request.contextPath}/admin/queryAllTypes.do">类型列表</a>
<a href="${pageContext.request.contextPath}/logout.do">注销</a>
<hr>
<br/>
<div style="margin-left: 20%;width: 50%">
<form action="${pageContext.request.contextPath}/admin/modifyType.do" method="post">
<label>类型编号:</label><input type="text" name="id" value="${type.id}" readonly>
<br/>
<label>类型名称:</label><input type="text" name="name" value="${type.name}">
<br/>
<button type="submit">修改</button>
</form>
</div>
</body>
</html>
newsAdd.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body background="${pageContext.request.contextPath}/images/bg.jpg">
欢迎您,${loginUser.name}
<a href="${pageContext.request.contextPath}/admin/toIndex.do">主页</a>
<a href="${pageContext.request.contextPath}/admin/queryAllNews.do">新闻列表</a>
<a href="${pageContext.request.contextPath}/admin/queryAllTypes.do">类型列表</a>
<a href="${pageContext.request.contextPath}/logout.do">注销</a>
<hr>
<br/>
<div style="margin-left: 20%;width: 50%">
<form action="${pageContext.request.contextPath}/admin/addNews.do" method="post">
<label>类型:</label>
<select name="tid">
<c:forEach items="${typelist}" var="type">
<option value="${type.id}" label="${type.name}">${type.name}</option>
</c:forEach>
</select>
<br/>
<label>标题:</label><input type="text" name="title">
<br/>
<label>内容:</label>
<textarea rows="8" cols="40" name="content"></textarea>
<br/>
<button type="submit">添加</button>
</form>
</div>
</body>
</html>
newsList.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body background="${pageContext.request.contextPath}/images/bg.jpg">
欢迎您,${loginUser.name}
<a href="${pageContext.request.contextPath}/admin/toIndex.do">主页</a>
<a href="${pageContext.request.contextPath}/admin/queryAllNews.do">新闻列表</a>
<a href="${pageContext.request.contextPath}/admin/queryAllTypes.do">类型列表</a>
<a href="${pageContext.request.contextPath}/logout.do">注销</a>
<hr>
<br/>
<div style="margin-left: 20%;width: 85%">
<div>
<form action="${pageContext.request.contextPath}/admin/queryAllNews.do">
<label>新闻类型:</label>
<select name="tid">
<option value="" label="">全部</option>
<c:forEach items="${typelist}" var="type">
<option value="${type.id}" label="${type.name}">${type.name}</option>
</c:forEach>
</select>
<button type="submit">查询</button>
</form>
</div>
<a href="${pageContext.request.contextPath}/admin/toAddNews.do">添加新闻</a>
<br/>
<table border="1" style="width: 70%">
<thead>
<th style="width: 50px;">序号</th>
<th>标题</th>
<th style="width: 150px;">日期</th>
<th style="width: 50px;">编辑</th>
<th style="width: 50px;">删除</th>
</thead>
<c:forEach items="${newsList}" var="news">
<tr>
<td>${news.id}</td>
<td>${news.title}</td>
<td>
<fmt:formatDate value="${news.date}"></fmt:formatDate>
</td>
<td><a href="${pageContext.request.contextPath}/admin/toModifyNews.do?id=${news.id }">编辑</a></td>
<td><a href="${pageContext.request.contextPath}/admin/deleteNews.do?id=${news.id }">删除</a></td>
</tr>
</c:forEach>
</table>
<div style="margin-left: 30%">
<span>当前是第${pageNo}页</span>
<a href="${pageContext.request.contextPath}/admin/queryAllNews.do?pageNo=${pageNo1}&tid=${tid}">上一页</a>
<a href="${pageContext.request.contextPath}/admin/queryAllNews.do?pageNo=${pageNo2}&tid=${tid}">下一页</a>
</div>
</div>
</body>
</html>
newsModify.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body background="${pageContext.request.contextPath}/images/bg.jpg">
欢迎您,${loginUser.name}
<a href="${pageContext.request.contextPath}/admin/toIndex.do">主页</a>
<a href="${pageContext.request.contextPath}/admin/queryAllNews.do">新闻列表</a>
<a href="${pageContext.request.contextPath}/admin/queryAllTypes.do">类型列表</a>
<a href="${pageContext.request.contextPath}/logout.do">注销</a>
<hr>
<br/>
<div style="margin-left: 20%;width: 50%">
<form action="${pageContext.request.contextPath}/admin/modifyNews.do" method="post">
<label>新闻编号:</label><input type="text" name="id" value="${news.id}" readonly>
<br/>
<label>类型编号:</label><input type="text" name="tid" value="${news.tid}" readonly>
<br/>
<label>新闻标题:</label><input type="text" name="title" value="${news.title}" >
<br/>
<label>新闻内容:</label>
<textarea name="content" rows="8" cols="40">${news.content}</textarea>
<br/>
<button type="submit">修改</button>
</form>
</div>
</body>
</html>
info.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body background="${pageContext.request.contextPath}/images/bg.jpg">
欢迎您
<a href="${pageContext.request.contextPath}/visitor/toIndex.do">主页</a>
<a href="${pageContext.request.contextPath}/visitor/queryAllNews.do">新闻列表</a>
<a href="${pageContext.request.contextPath}/login.jsp">登录</a>
<hr>
<br/>
<div style="margin-left: 20%;width: 60%" >
<h4>${news.title}</h4>
<span>${type.name} </span>
<span>
<fmt:formatDate value="${news.date}"></fmt:formatDate>
</span>
<br/>
<p>${news.content}</p>
</div>
</body>
</html>
search.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body background="${pageContext.request.contextPath}/images/bg.jpg">
欢迎您
<a href="${pageContext.request.contextPath}/visitor/toIndex.do">主页</a>
<a href="${pageContext.request.contextPath}/visitor/queryAllNews.do">新闻列表</a>
<a href="${pageContext.request.contextPath}/login.jsp">登录</a>
<hr>
<br/>
<div style="margin-left: 20%;width: 85%">
<div>
<form action="${pageContext.request.contextPath}/visitor/queryAllNews.do" method="post">
<label>新闻类型:</label>
<select name="tid">
<option value="" label="">全部</option>
<c:forEach items="${typelist}" var="type">
<option value="${type.id}" label="${type.name}">${type.name}</option>
</c:forEach>
</select>
<label>标题:</label><input type="text" name="title">
<button type="submit">搜索</button>
</form>
</div>
<br/>
<table border="1" style="width: 70%">
<thead>
<th style="width: 50px;">序号</th>
<th>标题</th>
<th style="width: 150px;">日期</th>
<th style="width: 50px;">详情</th>
</thead>
<c:forEach items="${newsList}" var="news">
<tr>
<td>${news.id}</td>
<td>${news.title}</td>
<td>
<fmt:formatDate value="${news.date}"></fmt:formatDate>
</td>
<td><a href="${pageContext.request.contextPath}/visitor/queryNews.do?id=${news.id }">详情</a></td>
</tr>
</c:forEach>
</table>
<div style="margin-left: 30%">
<span>当前是第${pageNo}页</span>
<a href="${pageContext.request.contextPath}/visitor/queryAllNews.do?pageNo=${pageNo1}&tid=${tid}&title=${title}">上一页</a>
<a href="${pageContext.request.contextPath}/visitor/queryAllNews.do?pageNo=${pageNo2}&tid=${tid}&title=${title}">下一页</a>
</div>
</div>
</body>
</html>
五、效果展示
普通用户(游客)
(1)显示所有新闻
文章来源地址https://www.toymoban.com/news/detail-763518.html
(2)浏览新闻
(3)根据新闻类别对新闻进行查找
(4)根据新闻标题对新闻进行查找
管理员用户
(1)显示所有新闻
(2)增加新闻
(3)修改新闻
(4)根据新闻类型对新闻进行查找
(5)删除新闻
(6)显示所有类别
(7)增加新闻类别
(8)修改新闻类别
(9)删除新闻类别
文章来源:https://www.toymoban.com/news/detail-763518.html
到了这里,关于新闻管理系统(ssm+jsp+mysql)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!