管理员对用户发布的信息具有审批和撤销功能,ssm框架怎么实现代码,从设计数据库开始一步步实现,以及前端代码

时间: 2023-12-06 09:44:17 浏览: 28
1. 设计数据库 首先需要设计数据库,假设有两张表:用户信息表和用户发布信息表。 用户信息表包括以下字段: | 字段名 | 类型 | 描述 | | ---------- | -------- | -------- | | user_id | int | 用户ID | | user_name | varchar | 用户名 | | user_pass | varchar | 用户密码 | | user_level | int | 用户等级 | 用户发布信息表包括以下字段: | 字段名 | 类型 | 描述 | | -------------- | --------- | ---------------- | | info_id | int | 信息ID | | user_id | int | 用户ID | | info_title | varchar | 信息标题 | | info_content | varchar | 信息内容 | | info_time | datetime | 信息发布时间 | | info_is_passed | tinyint | 信息是否已审批 | | info_is_delete | tinyint | 信息是否已删除 | 2. 编写后端代码 使用SSM框架编写后端代码,具体步骤如下: 1.创建User和Info的实体类 ``` public class User { private int user_id; private String user_name; private String user_pass; private int user_level; //省略getter和setter方法 } public class Info { private int info_id; private int user_id; private String info_title; private String info_content; private Date info_time; private int info_is_passed; private int info_is_delete; //省略getter和setter方法 } ``` 2.创建User和Info的Mapper接口 ``` public interface UserMapper { User selectUserById(int user_id); } public interface InfoMapper { List<Info> selectAllInfoByUserId(int user_id); Info selectInfoById(int info_id); void insertInfo(Info info); void updateInfo(Info info); } ``` 3.创建User和Info的Service接口和实现类 ``` public interface UserService { User getUserById(int user_id); } @Service public class UserServiceImpl implements UserService { @Autowired private UserMapper userMapper; @Override public User getUserById(int user_id) { return userMapper.selectUserById(user_id); } } public interface InfoService { List<Info> getAllInfoByUserId(int user_id); Info getInfoById(int info_id); void addInfo(Info info); void updateInfo(Info info); } @Service public class InfoServiceImpl implements InfoService { @Autowired private InfoMapper infoMapper; @Override public List<Info> getAllInfoByUserId(int user_id) { return infoMapper.selectAllInfoByUserId(user_id); } @Override public Info getInfoById(int info_id) { return infoMapper.selectInfoById(info_id); } @Override public void addInfo(Info info) { infoMapper.insertInfo(info); } @Override public void updateInfo(Info info) { infoMapper.updateInfo(info); } } ``` 4.创建Controller类 ``` @Controller @RequestMapping("/info") public class InfoController { @Autowired private UserService userService; @Autowired private InfoService infoService; @RequestMapping("/list") public String list(Model model, HttpSession session) { int user_id = (int) session.getAttribute("user_id"); List<Info> infoList = infoService.getAllInfoByUserId(user_id); model.addAttribute("infoList", infoList); return "info_list"; } @RequestMapping("/add") public String add(Model model) { model.addAttribute("info", new Info()); return "info_add"; } @RequestMapping("/save") public String save(@ModelAttribute("info") Info info, HttpSession session) { int user_id = (int) session.getAttribute("user_id"); info.setUser_id(user_id); info.setInfo_time(new Date()); info.setInfo_is_passed(0); // 初始状态为未审批 info.setInfo_is_delete(0); // 初始状态为未删除 infoService.addInfo(info); return "redirect:/info/list"; } @RequestMapping("/edit") public String edit(@RequestParam("info_id") int info_id, Model model) { Info info = infoService.getInfoById(info_id); model.addAttribute("info", info); return "info_edit"; } @RequestMapping("/update") public String update(@ModelAttribute("info") Info info) { infoService.updateInfo(info); return "redirect:/info/list"; } } ``` 3. 编写前端代码 使用HTML和Thymeleaf模板引擎编写前端代码,具体步骤如下: 1.创建信息列表页面(info_list.html) ``` <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>信息列表</title> </head> <body> <table> <thead> <tr> <th>ID</th> <th>标题</th> <th>内容</th> <th>发布时间</th> <th>审批状态</th> <th>操作</th> </tr> </thead> <tbody> <tr th:each="info : ${infoList}"> <td th:text="${info.info_id}"></td> <td th:text="${info.info_title}"></td> <td th:text="${info.info_content}"></td> <td th:text="${info.info_time}"></td> <td th:text="${info.info_is_passed == 0 ? '未审批' : '已审批'}"></td> <td> <a th:href="@{/info/edit(info_id=${info.info_id})}">编辑</a> </td> </tr> </tbody> </table> <a th:href="@{/info/add}">添加信息</a> </body> </html> ``` 2.创建添加信息页面(info_add.html) ``` <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>添加信息</title> </head> <body> <form th:action="@{/info/save}" th:object="${info}" method="post"> <label>标题:</label> <input type="text" th:field="*{info_title}"><br> <label>内容:</label> <textarea th:field="*{info_content}"></textarea><br> <input type="submit" value="保存"> </form> </body> </html> ``` 3.创建编辑信息页面(info_edit.html) ``` <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>编辑信息</title> </head> <body> <form th:action="@{/info/update}" th:object="${info}" method="post"> <input type="hidden" th:field="*{info_id}"> <label>标题:</label> <input type="text" th:field="*{info_title}"><br> <label>内容:</label> <textarea th:field="*{info_content}"></textarea><br> <input type="submit" value="保存"> </form> </body> </html> ``` 至此,使用SSM框架实现管理员对用户发布的信息具有审批和撤销功能的代码就完成了。

相关推荐

最新推荐

recommend-type

Java中SSM框架实现增删改查功能代码详解

主要介绍了Java中SSM框架实现增删改查功能代码详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
recommend-type

ssm框架上传图片保存到本地和数据库示例

本篇文章主要介绍了ssm框架上传图片保存到本地和数据库示例,主要使用了Spring+SpringMVC+MyBatis框架集合,有兴趣的可以了解一下。
recommend-type

SSM框架下实现登录注册的示例代码

主要介绍了SSM框架下实现登录注册的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
recommend-type

基于SSM框架实现简单的登录注册的示例代码

主要介绍了基于SSM框架实现简单的登录注册的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
recommend-type

基于SSM的云笔记系统设计与实现.doc

系统包括笔记展示界面和笔记编辑界面,笔记编辑界面包括用户登录、数据信息管理、成员管理、评论管理、富文本录入,在线搜索等功能模块。笔记显示界面包括用户注册、搜索和查看数据信息功能模块。在编辑用户界面,...
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

SQL怎么实现 数据透视表

SQL可以通过使用聚合函数和GROUP BY子句来实现数据透视表。 例如,假设有一个销售记录表,其中包含产品名称、销售日期、销售数量和销售额等信息。要创建一个按照产品名称、销售日期和销售额进行汇总的数据透视表,可以使用以下SQL语句: ``` SELECT ProductName, SaleDate, SUM(SaleQuantity) AS TotalQuantity, SUM(SaleAmount) AS TotalAmount FROM Sales GROUP BY ProductName, SaleDate; ``` 该语句将Sales表按照ProductName和SaleDat
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。