admin 管理员组文章数量: 887021
👉文末查看项目功能视频演示+获取源码+sql脚本+视频导入教程视频
1 、功能描述
新闻管理系统拥有两个角色,分别为用户和管理员,具体功能如下:
1.1 背景描述
新闻管理系统是一款支持新闻发布、编辑、删除和查询等功能的在线工具,方便用户快速管理新闻信息。通过该系统,管理员可以轻松添加、审核新闻,实现新闻的及时更新和发布;读者可以便捷地浏览、搜索感兴趣的新闻内容。系统采用先进的技术架构,确保数据的安全性和稳定性,提供用户友好的操作界面,适用于各类新闻媒体机构和企事业单位的新闻管理需求。
2、项目技术
后端框架:Jfinal、mvc
前端框架:Freemarker、html、css、JavaScript、JQuery
2.1 Jfinal
JFinal是一个基于Java语言的轻量级Web框架,它可以帮助开发者快速搭建Web应用程序。JFinal将Servlet API、Spring和MyBatis等技术进行整合,使得开发者能够更加高效地开发Web应用。JFinal还提供了丰富的插件和工具类,简化了开发过程,提高了开发效率。同时,JFinal还支持多种数据库访问方式,包括ORM、SQL语句等,方便开发者根据需求选择合适的访问方式。
2.2 mysql
MySQL是一款Relational Database Management System,直译过来的意思就是关系型数据库管理系统,MySQL有着它独特的特点,这些特点使他成为目前最流行的RDBMS之一,MySQL想比与其他数据库如ORACLE、DB2等,它属于一款体积小、速度快的数据库,重点是它符合本次毕业设计的真实租赁环境,拥有成本低,开发源码这些特点,这也是选择它的主要原因。
3、开发环境
- JAVA版本:JDK1.8,其它版本理论上可以
- IDE类型:IDEA、Eclipse
- tomcat版本:Tomcat 7.x、8.x、9.x版本均可
- 数据库版本:MySql 5.7、8.x
- maven版本:无限制
- 硬件环境:Windows 或者 Mac OS
4、功能截图+视频演示+文档目录
4.1 登录
4.2前端 模块
1)用户通过登录后可对新闻进行搜索、查看新闻。其中搜索可采用关键词过滤、年度两个条件进行搜索筛查或根据分类类型查看即时新闻,用户可查看搜索结果,并且对所查看的新闻进行浏览、收藏、分享等操作,并且对新闻延伸的友情链接进行查看,查看往期收藏内容可在个人中心进行查看。
2)新闻分类显示相关信息、新闻提供站内新闻全面搜索功能、支持其他网站的友情链接,为后台管理提供管理入口
4.3 后台模块
管理员在登录后可对新闻进行增删改查等维护操作、以及对用户进行合法性行为进行检查,包括用户对新闻的评论审核、用户的账号的合法性,收藏用户的行为日志对友情链接的维护与更新。
4.4 文档目录
5 、核心代码实现
5.1 管理员代码
package controller;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.kit.Kv;
import com.jfinal.kit.LogKit;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;
import com.jfinal.upload.UploadFile;
import interceptor.Login;
import model.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.Date;
import java.util.List;
@Before(Login.class)
public class AdminController extends Controller {
public void searchUserByNickNameResult(){
List<User> user = User.dao.find("select * from user where nickName =?", nickNameForUser);
setAttr("user",user);
renderFreeMarker("manageUser.ftl");
}
public static String nickNameForUser;
public void searchUserByNickName(){
nickNameForUser = getPara("nickName");
Boolean success = true;
String message = success ? "成功" : "失败";
Kv result = Kv.by("success", success).set("message", message);
System.out.print(success);
renderJson(result);
}
public void DoAddUserInfo(){
String userName = getPara("userName");
String nickName = getPara("nickName");
String tel = getPara("tel");
String email = getPara("email");
String password = getPara("password");
User user = new User();
user.setUserName(userName);
user.setPassword(password);
user.setNickName(nickName);
user.setEmail(email);
user.setTel(tel);
user.save();
Boolean success = true;
String message = success ? "成功" : "失败";
Kv result = Kv.by("success", success).set("message", message);
renderJson(result);
}
public void addUser(){
renderFreeMarker("addUser.ftl");
}
public void DomodifyUserInfo(){
String userName = getPara("userName");
String nickName = getPara("nickName");
Integer id = getParaToInt("id");
String tel = getPara("tel");
String email = getPara("email");
String password = getPara("password");
Db.update("update user set userName=?,nickName=?,password=?,tel=?,email=? where id=?",userName,nickName,password,tel
,email,id);
Boolean success = true;
String message = success ? "成功" : "失败";
Kv result = Kv.by("success", success).set("message", message);
renderJson(result);
}
public void modifyUserInfo(){
Integer paraToInt = getParaToInt(0, -1);
List<User> user = User.dao.find("select * from user where id= ?", paraToInt);
setAttr("user",user.get(0));
renderFreeMarker("modifyUserInfo.ftl");
}
public void deleteUserInfo(){
Integer paraToInt = getParaToInt(0, -1);
Db.delete("delete from user where id =?",paraToInt);
List<User> user = User.dao.find("select * from user");
setAttr("user",user);
renderFreeMarker("manageUser.ftl");
}
public void manageUser(){
List<User> user = User.dao.find("select * from user");
setAttr("user",user);
renderFreeMarker("manageUser.ftl");
}
public void searchAdminByNickNameResult(){
List<Admin> admins = Admin.dao.find("select * from admin where nickName =?", nickNameForAdmin);
setAttr("admins",admins);
renderFreeMarker("manageAdmin.ftl");
}
public static String nickNameForAdmin;
public void searchAdminByNickName(){
nickNameForAdmin = getPara("nickName");
Boolean success = true;
String message = success ? "成功" : "失败";
Kv result = Kv.by("success", success).set("message", message);
System.out.print(success);
renderJson(result);
}
public void DoAddAdminInfo(){
String adminName = getPara("adminName");
String nickName = getPara("nickName");
String tel = getPara("tel");
String email = getPara("email");
Integer Super = getParaToInt("super");
String password = getPara("password");
Admin admin = new Admin();
admin.setAdminName(adminName);
admin.setPassword(password);
admin.setNickName(nickName);
admin.setEmail(email);
admin.setTel(tel);
admin.setSuper(Super);
admin.save();
Boolean success = true;
String message = success ? "成功" : "失败";
Kv result = Kv.by("success", success).set("message", message);
renderJson(result);
}
public void addAdmin(){
renderFreeMarker("addAdmin.ftl");
}
public void DomodifiyAdminInfo(){
String adminName = getPara("adminName");
String nickName = getPara("nickName");
Integer id = getParaToInt("id");
String tel = getPara("tel");
String email = getPara("email");
Integer Super = getParaToInt("super");
String password = getPara("password");
Db.update("update admin set adminName=?,nickName=?,password=?,tel=?,email=?,super=? where id=?",adminName,nickName,password,tel
,email,Super,id);
Boolean success = true;
String message = success ? "成功" : "失败";
Kv result = Kv.by("success", success).set("message", message);
renderJson(result);
}
public void modifyAdminInfo(){
Integer paraToInt = getParaToInt(0, -1);
List<Admin> admins = Admin.dao.find("select * from admin where id= ?", paraToInt);
setAttr("admin",admins.get(0));
renderFreeMarker("modifyAdminInfo.ftl");
}
public void deleteAdminInfo(){
Integer paraToInt = getParaToInt(0, -1);
Db.delete("delete from admin where id =?",paraToInt);
List<Admin> admins = Admin.dao.find("select * from admin");
setAttr("admins",admins);
renderFreeMarker("manageAdmin.ftl");
}
public void manageAdmin(){
List<Admin> admins = Admin.dao.find("select * from admin");
setAttr("admins",admins);
renderFreeMarker("manageAdmin.ftl");
}
public void manageReplyByCategory() {
List<Category> categories = Category.dao.find("select * from category");
setAttr("categories", categories);
SqlPara manageReplyByCategory = Db.getSqlPara("manageReplyByCategory", nickNameForReply);
Integer pageNumber = getParaToInt("page", 1);//从ftl页面传回第几页,为了实现下一页上一页功能
Page<Reply> page = Reply.dao.paginate(pageNumber, 10, manageReplyByCategory);//分页显示方法
setAttr("page", page);
renderFreeMarker("commitManage.ftl");
}
public static String nickNameForReply;
public void searchReplyByCategoryId() {
nickNameForReply = getPara("nickName");
Boolean success = true;
String message = success ? "成功" : "失败";
Kv result = Kv.by("success", success).set("message", message);
System.out.print(success);
renderJson(result);
}
public void refuseReply() {
List<Category> categories = Category.dao.find("select * from category");
setAttr("categories", categories);
Integer para = getParaToInt(0, -1);
Db.update("update reply set status =0 where id =?", para);
SqlPara commitManage = Db.getSqlPara("commitManage");
Integer pageNumber = getParaToInt("page", 1);//从ftl页面传回第几页,为了实现下一页上一页功能
Page<Reply> page = Reply.dao.paginate(pageNumber, 10, commitManage);//分页显示方法
setAttr("page", page);
renderFreeMarker("commitManage.ftl");
}
public void passReply() {
List<Category> categories = Category.dao.find("select * from category");
setAttr("categories", categories);
Integer para = getParaToInt(0, -1);
Db.update("update reply set status =1 where id =?", para);
SqlPara commitManage = Db.getSqlPara("commitManage");
Integer pageNumber = getParaToInt("page", 1);//从ftl页面传回第几页,为了实现下一页上一页功能
Page<Reply> page = Reply.dao.paginate(pageNumber, 10, commitManage);//分页显示方法
setAttr("page", page);
renderFreeMarker("commitManage.ftl");
}
public void commitManage() {
List<Category> categories = Category.dao.find("select * from category");
setAttr("categories", categories);
SqlPara commitManage = Db.getSqlPara("commitManage");
Integer pageNumber = getParaToInt("page", 1);//从ftl页面传回第几页,为了实现下一页上一页功能
Page<Reply> page = Reply.dao.paginate(pageNumber, 10, commitManage);//分页显示方法
setAttr("page", page);
renderFreeMarker("commitManage.ftl");
}
public void DomodifyNew() {
Integer id1 = getParaToInt("id");
String title = getPara("title");
String contetnt = getPara("content");
String link = getPara("link");
String linkName = getPara("linkName");
Integer categoryId = getParaToInt("category");
Db.update("update topic set title=?,content=?,link=?,linkName=?,categoryId=? where id=? ", title, contetnt, link, linkName, categoryId, id1);
Boolean success = true;
String message = success ? "成功" : "失败";
Kv result = Kv.by("success", success).set("message", message);
renderJson(result);
}
public void ModifyNew() {
Integer para = getParaToInt(0, -1);
List<Category> categories = Category.dao.find("select * from category");
setAttr("categories", categories);
Topic byId = Topic.dao.findById(para);
setAttr("topic", byId);
renderFreeMarker("ModifyNew.ftl");
}
public void deleteNew() {
Integer para = getParaToInt(0, -1);
Db.delete("delete from topic where id= ?", para);
List<Category> categories = Category.dao.find("select * from category");
setAttr("categories", categories);
SqlPara manageNew = Db.getSqlPara("manageNew");
Integer pageNumber = getParaToInt("page", 1);//从ftl页面传回第几页,为了实现下一页上一页功能
Page<Topic> page = Topic.dao.paginate(pageNumber, 10, manageNew);//分页显示方法
setAttr("page", page);
renderFreeMarker("manageNew.ftl");
}
public void manageNewByCategory() {
List<Category> categories = Category.dao.find("select * from category");
setAttr("categories", categories);
SqlPara manageNewByCategory = Db.getSqlPara("manageNewByCategory", selectFlag);
Integer pageNumber = getParaToInt("page", 1);//从ftl页面传回第几页,为了实现下一页上一页功能
Page<Topic> page = Topic.dao.paginate(pageNumber, 10, manageNewByCategory);//分页显示方法
setAttr("page", page);
renderFreeMarker("manageNew.ftl");
}
public static int selectFlag = -1;
public void searchNewByCategoryId() {
selectFlag = getParaToInt("select");
Boolean success = true;
String message = success ? "成功" : "失败";
Kv result = Kv.by("success", success).set("message", message);
System.out.print(success);
renderJson(result);
}
public void manageNew() {
List<Category> categories = Category.dao.find("select * from category");
setAttr("categories", categories);
SqlPara manageNew = Db.getSqlPara("manageNew");
Integer pageNumber = getParaToInt("page", 1);//从ftl页面传回第几页,为了实现下一页上一页功能
Page<Topic> page = Topic.dao.paginate(pageNumber, 10, manageNew);//分页显示方法
setAttr("page", page);
renderFreeMarker("manageNew.ftl");
}
public void DouploadCoverPic() {
Boolean success = false;
UploadFile upload = this.getFile();
String fileName = upload.getOriginalFileName();
File file = upload.getFile();
String contentType = upload.getContentType();
String webRootPath = PathKit.getWebRootPath();//得到web路径
PropKit.use("myconfig.properties");//从配置文件中读取保存路径
// String saveFilePathforimage = PropKit.get("saveFilePathforimage");
String saveFilePathforimage = webRootPath + "\\template\\newImg\\";
String filename = file.getName();
String savaFileName = filename;
System.out.println("保存路径=" + saveFilePathforimage);
String saveNme = saveFilePathforimage + savaFileName;
String mysql_save_Path = "/template/newImg/" + savaFileName;
File Direction = new File(saveFilePathforimage);
//判断文件夹是否存在 如果不存在 就创建文件夹
if (!Direction.exists()) {
Direction.mkdirs();
}
File t = new File(saveNme);
try {
t.createNewFile();
Db.update("update topic set coverPic = ? where id =?", mysql_save_Path, tempID);
success = true;
} catch (Exception e) {
e.printStackTrace();
LogKit.error("上传失败,原因是:" + e.getMessage());
}
fileChannelCopy(file, t);
file.delete();
String message = success ? "上传成功" : "上传失败";
Kv result = Kv.by("success", success).set("message", message);
System.out.print(success);
renderJson(result);
}
public void addNew() {
List<Category> categories = Category.dao.find("select * from category");
setAttr("categories", categories);
renderFreeMarker("addNew.ftl");
}
public void upload() {
Boolean success = false;
UploadFile upload = this.getFile();
String fileName = upload.getOriginalFileName();
File file = upload.getFile();
String contentType = upload.getContentType();
String webRootPath = PathKit.getWebRootPath();//得到web路径
PropKit.use("myconfig.properties");//从配置文件中读取保存路径
// String saveFilePathforimage = PropKit.get("saveFilePathforimage");
String saveFilePathforimage = webRootPath + "\\template\\newImg\\";
String filename = file.getName();
String savaFileName = filename;
System.out.println("保存路径=" + saveFilePathforimage);
String saveNme = saveFilePathforimage + savaFileName;
String mysql_save_Path = "/template/newImg/" + savaFileName;
File Direction = new File(saveFilePathforimage);
//判断文件夹是否存在 如果不存在 就创建文件夹
if (!Direction.exists()) {
Direction.mkdirs();
}
File t = new File(saveNme);
try {
t.createNewFile();
success = true;
} catch (Exception e) {
e.printStackTrace();
LogKit.error("上传失败,原因是:" + e.getMessage());
}
fileChannelCopy(file, t);
file.delete();
String message = success ? "上传成功" : "上传失败";
Kv result = Kv.by("errno", 0).set("url", mysql_save_Path);
renderJson(result);
}
public void fileChannelCopy(File s, File t) {
FileInputStream fi = null;
FileOutputStream fo = null;
FileChannel in = null;
FileChannel out = null;
try {
fi = new FileInputStream(s);
fo = new FileOutputStream(t);
in = fi.getChannel();//得到对应的文件通道
out = fo.getChannel();
in.transferTo(0, in.size(), out);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fi.close();
in.close();
fo.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void display() {
List<Test> tests = Test.dao.find("select * from test ");
setAttr("test", tests.get(0));
renderFreeMarker("info.ftl");
}
public void uploadCoverPic() {
// setAttr("topicId",tempID);
renderFreeMarker("uploadCoverPic.ftl");
}
public static int tempID = -1;
public void saveNew() {
String title = getPara("title");
String contetnt = getPara("content");
String link = getPara("link");
String linkName = getPara("linkName");
Integer categoryId = getParaToInt("category");
Date date = new Date();
Admin admin = getSessionAttr("user");
Topic topic = new Topic();
List<Record> records = Db.find("select max(id) as maxId from topic");
System.out.println("最大值ID=" + records.get(0).getStr("maxId"));
int id = Integer.parseInt(records.get(0).getStr("maxId"));
System.out.println("存入的ID=" + id);
topic.setAdminId(admin.getId());
topic.setCategoryId(categoryId);
topic.setPubDate(date);
topic.setContent(contetnt);
topic.setTitle(title);
topic.setCoverPic("null");
topic.setLink(link);
topic.setId(id + 1);
topic.setLinkName(linkName);
tempID = id + 1;
topic.save();
//
// Test test = new Test();
// test.setTitle(title);
// test.setInfo(contetnt);
// test.setAvatar("null");
// test.save();
Boolean success = true;
String message = success ? "成功" : "失败";
Kv result = Kv.by("success", success).set("message", message);
renderJson(result);
}
public void index() {
renderFreeMarker("adminMainPage.ftl");
}
}
5.2 其它核心代码
package controller;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.kit.HashKit;
import com.jfinal.kit.Kv;
import com.jfinal.kit.LogKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;
import interceptor.CategoryNavbarInterceotor;
import interceptor.Login;
import interceptor.LoginValidator;
import interceptor.RegisterValidator;
import model.*;
import java.util.List;
import static com.jfinal.plugin.activerecord.Db.find;
import static model.User.dao;
public class MainController extends Controller {
@Before(CategoryNavbarInterceotor.class)
public void index() {
// List<Category> categories = Category.dao.find("select * from category ");
// setAttr("categories",categories);
SqlPara hotTopic = Db.getSqlPara("hotTopic");
List<Topic> topics = Topic.dao.find(hotTopic);
setAttr("topies",topics);
renderFreeMarker("index.ftl");
}
public void register() {
renderFreeMarker("register.ftl");
}
@Before(RegisterValidator.class)
public void doRegister() {
String username = getPara("username");
String password = getPara("password");
String nickName = getPara("nickName");
String email = getPara("email");
String tel = getPara("tel");
User user = new User();
user.setUserName(username);
user.setPassword(password);
user.setNickName(nickName);
user.setTel(tel);
user.setEmail(email);
boolean success = false;
try {
user.save();
success = true;
} catch (Exception e) {
LogKit.error("用户注册失败,原因是:" + e.getMessage());
}
String message = success ? "注册成功" : "注册失败";
Kv result = Kv.by("success", success).set("message", message);
System.out.print(success);
renderJson(result);
}
public void login() {
renderFreeMarker("login.ftl");
}
@Before(LoginValidator.class)
public void loginCheck() {
boolean success = false;
int flag = -1;
String username = getPara("username");
String password = getPara("password");
Integer usertype = getParaToInt("usertype");
if (usertype == 1) {
String sql = Db.getSql("checkLoginUser");
List<User> users = User.dao.find(sql, username, password);
//登录成功
if (users.size() != 0) {
setSessionAttr("user", users.get(0));
flag = 1;
success = true;
} else {
//登录失败
setAttr("errmsg", "用户名或密码错误");
// renderFreeMarker("login.ftl");
}
} else {
String sql = Db.getSql("checkLoginAdmin");
List<Admin> admins = Admin.dao.find(sql, username, password);
//登录成功
if (admins.size() != 0) {
setSessionAttr("user", admins.get(0));
flag = 2;
success = true;
} else {
//登录失败
setAttr("errmsg", "用户名或密码错误");
}
}
String message = success ? "登录成功" : "登录失败,密码或者用户名错误";
Kv result = Kv.by("success", success).set("message", message).set("flag", flag);
renderJson(result);
}
public void logout() {
removeSessionAttr("user");
redirect("/login");
}
public void captcha(){
renderCaptcha();
}
}
6 、功能视频演示
点击这里播放
7 、 获取方式
👇 大家点赞、收藏、关注、评论啦 👇🏻获取联系方式,后台回复关键词:新闻👇🏻
版权声明:本文标题:新闻管理系统的设计与实现 (含源码+sql+视频导入教程+论文) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1726436347h960294.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论