源码获取:俺的博客首页 "资源" 里下载!
项目介绍
本项目新闻推荐管理系统;
前台:
登录、首页、全部新闻、系统特色、猜你喜欢、分类、评论
后台:
(1)文件管理:文件列表。
(2)用户管理:用户管理。
(3)新闻管理:新闻管理。
(4)三联管理:联动管理。
(5)新闻审核:新闻的审核和管理。
技术栈
SSM+mysql+layui+CSS+JavaScript
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入http://localhost:8080 访问
用户管理控制层:
-
@Controller
-
@RequestMapping("UsersServlet")
-
public
class
UsersController {
-
private
UsersDao
usersDao
=
new
UsersDao();
-
-
@Autowired
-
private HttpServletRequest request;
-
-
-
@RequestMapping("/loginadmin")
-
public String
loginadmin
() {
-
String
username
= request.getParameter(
"username");
-
String
password
= request.getParameter(
"password");
-
Users
users
= usersDao.login(username, password);
-
-
if (users !=
null) {
-
request.getSession().setAttribute(
"loginUsers", users);
-
return
"admin_index";
-
-
}
else {
-
request.setAttribute(
"msg",
"登录失败,账号密码不匹配");
-
return
"admin_login";
-
-
}
-
-
}
-
-
@RequestMapping("/userlogin")
-
public String
userlogin
() {
-
String
userName
= request.getParameter(
"username");
-
String
password
= request.getParameter(
"password");
-
String
clientCheckcode
= request.getParameter(
"validateCode");
-
String
serverCheckcode
= (String) request.getSession().getAttribute(
"checkcode");
-
if (clientCheckcode.equals(serverCheckcode)) {
-
// 2. 去访问dao , 看看是否满足登录。
-
-
Users
Users
= usersDao.userlogin(userName, password);
-
-
// 3. 针对dao的返回结果,做出响应
-
if (Users !=
null) {
-
-
-
request.getSession().setAttribute(
"usersLogin", Users);
-
CategoryDao
categoryDao
=
new
CategoryDao();
-
List<Category> categoryList = categoryDao.queryAll();
-
request.setAttribute(
"categoryList", categoryList.stream().filter(x -> x.getState().equals(
"1")).collect(Collectors.toList()));
-
return
"index";
-
-
-
}
else {
-
request.setAttribute(
"error",
"用户名或密码错误!");
-
return
"login";
-
-
-
}
-
}
else {
-
request.setAttribute(
"error",
"登录失败,验证码不正确!");
-
return
"login";
-
-
}
-
}
-
-
@RequestMapping("/userreg")
-
public String
userreg
() {
-
String
username
= request.getParameter(
"username");
-
String
password
= request.getParameter(
"password");
-
String
account
= request.getParameter(
"account");
-
String
email
= request.getParameter(
"email");
-
String
password2
= request.getParameter(
"password2");
-
if (!password.equals(password2)) {
-
request.setAttribute(
"error",
"注册失败,密码与确认密码不一致!");
-
return
"reg";
-
}
else {
-
-
boolean
isSuccess
= usersDao.isReg(account);
-
-
if (!isSuccess) {
-
-
request.setAttribute(
"error",
"注册失败,该用户名已存在!");
-
return
"reg";
-
-
}
else {
-
usersDao.reg(username, account, password, email);
-
request.setAttribute(
"error",
"注册成功!");
-
-
return
"reg";
-
}
-
}
-
-
}
-
-
@RequestMapping("/listforadmin")
-
public String
listforadmin
() {
-
-
-
List<Users> list = usersDao.getUsers();
-
request.setAttribute(
"list", list);
-
return
"listusers";
-
-
}
-
@RequestMapping("/del")
-
public String
del
(Integer id) {
-
-
usersDao.del(id);
-
-
List<Users> list = usersDao.getUsers();
-
request.setAttribute(
"list", list);
-
return
"listusers";
-
-
}
-
}
新闻管理控制层:
-
@Controller
-
@RequestMapping(
"NewsServlet")
-
public
class
NewsController {
-
@Autowired
-
private
HttpServletRequest request;
-
private
NewsDao newsDao =
new
NewsDao();
-
private
CategoryDao categoryDao =
new
CategoryDao();
-
private
CommentsDao commentsDao =
new
CommentsDao();
-
@RequestMapping(
"/publish")
-
public
String
publish(
){
-
String title = request.
getParameter(
"title");
-
String content = request.
getParameter(
"content");
-
String categoryid = request.
getParameter(
"categoryid");
-
-
Users users = (
Users) request.
getSession().
getAttribute(
"loginUsers");
-
Integer usersId = users.
getId();
-
-
Integer deptid = users.
getDeptid();
-
-
News news =
new
News();
-
news.
setCategoryid(
Integer.
parseInt(categoryid));
-
news.
setClicks(
0);
-
news.
setContent(content);
-
news.
setPbdate(
new
Date());
-
news.
setPbdeptid(deptid);
-
news.
setPublisher(usersId);
-
news.
setCategoryid(
Integer.
parseInt(categoryid));
-
news.
setTitle(title);
-
newsDao.
save(news);
-
return
"redirect:listforadmin";
-
}
-
-
-
@RequestMapping(
"/listforadmin")
-
public
String
listforadmin(
){
-
List<
News> newsList = newsDao.
queryAll();
-
request.
setAttribute(
"list", newsList);
-
return
"listnews";
-
}
-
-
-
-
-
-
@RequestMapping(
"/toaddnews")
-
public
String
toaddnews(
){
-
List<
News> newsList = newsDao.
queryAll();
-
request.
setAttribute(
"list", newsList);
-
List<
Category> categoryList = categoryDao.
queryAll();
-
request.
setAttribute(
"categoryList", categoryList);
-
return
"addnews";
-
}
-
-
-
@RequestMapping(
"/edit")
-
public
String
edit(
){
-
String title = request.
getParameter(
"title");
-
String content = request.
getParameter(
"content");
-
String categoryid = request.
getParameter(
"categoryid");
-
-
News news =
new
News();
-
news.
setCategoryid(
Integer.
parseInt(categoryid));
-
news.
setContent(content);
-
news.
setPbdate(
new
Date());
-
news.
setId(
Integer.
parseInt(request.
getParameter(
"id")));
-
-
news.
setTitle(title);
-
newsDao.
edit(news);
-
return
"redirect:listforadmin";
-
}
-
-
-
-
@RequestMapping(
"/del")
-
public
String
del(
){
-
newsDao.
deleteById(
Integer.
parseInt(request.
getParameter(
"id")));
-
List<
News> newsList = newsDao.
queryAll();
-
request.
setAttribute(
"list", newsList);
-
return
"listnews";
-
-
}
-
-
-
@RequestMapping(
"/toeditnews")
-
public
String
toeditnews(
){
-
News news = newsDao.
queryByid(
Integer.
parseInt(request.
getParameter(
"id")));
-
request.
setAttribute(
"v", news);
-
List<
Category> categoryList = categoryDao.
queryAll();
-
request.
setAttribute(
"categoryList", categoryList);
-
return
"editnews";
-
}
-
-
-
@RequestMapping(
"/queryByType")
-
public
String
queryByType(
){
-
String categoryid = request.
getParameter(
"categoryid");
-
-
List<
News> newsList = newsDao.
queryAll();
-
request.
setAttribute(
"list", newsList.
stream()
-
.
filter(x -> x.
getCategoryid().
equals(
Integer.
parseInt(categoryid))).
collect(
Collectors.
toList()));
-
List<
Category> categoryList = categoryDao.
queryAll();
-
request.
setAttribute(
"categoryList",
-
categoryList.
stream().
filter(x -> x.
getState().
equals(
"1")).
collect(
Collectors.
toList()));
-
-
return
"typenews";
-
}
-
-
-
@RequestMapping(
"/detail")
-
public
String
detail(
){
-
//测试
-
String id = request.
getParameter(
"id");
-
if(id.
contains(
".jsp"))
-
{
-
id= request.
getParameter(
"id").
replaceAll(
".jsp",
"");
-
-
}
-
-
News news = newsDao.
queryByid(
Integer.
parseInt(id));
-
-
news.
setClicks(news.
getClicks() +
1);
-
-
newsDao.
setClicksIncrement(news);
-
-
NewsDetail detail =
new
NewsDetail();
-
detail.
setNews(news);
-
-
Category category = categoryDao.
queryById(news.
getCategoryid());
-
-
detail.
setCategory(category);
-
-
String content = news.
getContent();
-
int length = content.
length();
-
-
length = length /
60;
-
-
length = length *
27 +
10;
-
-
request.
setAttribute(
"length", length);
-
-
request.
setAttribute(
"v", detail);
-
-
List<
Category> categoryList = categoryDao.
queryAll();
-
-
List<
Comments> commentsList = commentsDao.
getByNewsId(news.
getId());
-
request.
setAttribute(
"commentsList", commentsList);
-
-
request.
setAttribute(
"contentstr", content);
-
-
request.
setAttribute(
"categoryList",
-
categoryList.
stream().
filter(x -> x.
getState().
equals(
"1")).
collect(
Collectors.
toList()));
-
-
return
"detailnews";
-
}
-
-
@RequestMapping(
"/search")
-
public
String
search(
){
-
String search = request.
getParameter(
"search");
-
-
request.
setAttribute(
"searchStr", search);
-
-
List<
News> newsList = newsDao.
queryAll();
-
newsList=newsList.
stream().
filter(x -> x.
getTitle().
contains(search)).
collect(
Collectors.
toList());
-
-
newsList= newsList.
stream().
map(x->{
-
-
String title = x.
getTitle();
-
-
/* String[] split = title.split(search);
-
*/
-
/*if(split.length>=2){
-
for(int i=0;i<split.length-1;i++){
-
title=split[i]+"<font color='red'>"+search+"</font>"+split[i+1];
-
-
}
-
}else{
-
title=split[0]+"<font color='red'>"+search+"</font>";
-
}*/
-
title=title.
replace(search,
"<font color='red'>"+search+
"</font>");
-
-
-
System.
out.
println(title);
-
-
x.
setTitle(title);
-
-
return x;
-
}).
collect(
Collectors.
toList());
-
-
request.
setAttribute(
"list",newsList
-
);
-
List<
Category> categoryList = categoryDao.
queryAll();
-
request.
setAttribute(
"categoryList",
-
categoryList.
stream().
filter(x -> x.
getState().
equals(
"1")).
collect(
Collectors.
toList()));
-
-
return
"searchnews";
-
}
-
-
}
类别管理控制层:
-
@Controller
-
@RequestMapping(
"CategoryServlet")
-
public
class
CategoryController {
-
@Autowired
-
private
HttpServletRequest request;
-
private
CategoryDao categoryDao=
new
CategoryDao();
-
-
@RequestMapping(
"/listforadmin")
-
public
String
listforadmin(
){
-
List<
Category> categoryList = categoryDao.
queryAll();
-
request.
setAttribute(
"list", categoryList);
-
return
"listcategory";
-
}
-
@RequestMapping(
"/show")
-
public
String
show(
){
-
List<
Category> categoryList = categoryDao.
queryAll();
-
categoryList=categoryList.
stream().
filter(x->x.
getState().
equals(
"1")).
collect(
Collectors.
toList());
-
-
if(categoryList.
size()>=
5)
-
{
-
-
request.
setAttribute(
"list", categoryDao.
queryAll());
-
request.
setAttribute(
"msg",
"设置栏目显示失败,前台栏目最多显示5个");
-
return
"listcategory";
-
}
else {
-
categoryDao.
show(
Integer.
parseInt(request.
getParameter(
"id")));
-
return
"redirect:listforadmin";
-
}
-
}
-
@RequestMapping(
"/hidden")
-
public
String
hidden(
){
-
-
categoryDao.
hidden(
Integer.
parseInt(request.
getParameter(
"id")));
-
return
"redirect:listforadmin";
-
}
-
@RequestMapping(
"/add")
-
public
String
add(
){
-
String name=request.
getParameter(
"name");
-
String state=request.
getParameter(
"state");
-
Category category=
new
Category();
-
category.
setName(name);
-
category.
setState(state);
-
categoryDao.
save(category);
-
return
"redirect:listforadmin";
-
}
-
-
-
-
}
源码获取:俺的博客首页 "资源" 里下载!
转载:https://blog.csdn.net/m0_66863468/article/details/128363995
查看评论