#6

Merged
p4vb9jpo3 merged 2 commits from branch/wmz into develop 3 months ago

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager">
<component name="ProjectRootManager" version="2" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -17,45 +17,174 @@ import java.util.List;
import java.util.Map;
/**
* ,,
*
* `ServletContextListener`
*
*
*
*
*
*
*
* Servlet
* Servlet
*
*
*
*
* 线
* 线
*/
@WebListener
public class DictionaryServletContextListener implements ServletContextListener {
// 创建一个日志记录器,用于记录该类在执行过程中的相关信息,
//
// 比如服务器启动、停止时的状态,字典表初始化的进度以及线程启动等操作情况,
// 方便在开发、调试以及运行时查看操作详情、排查问题等。
private static final Logger logger = LoggerFactory.getLogger(DictionaryServletContextListener.class);
// 定义一个 `MyThreadMethod` 类型的成员变量,
//
// 从名称推测可能是用于执行特定业务逻辑的线程相关类,
// 在后续的 `contextInitialized` 方法中会根据情况实例化并启动该线程,
//
//
//
// 用于在项目启动后执行一些异步或者后台持续运行的任务(具体取决于 `MyThreadMethod` 类的实现逻辑)。
private MyThreadMethod myThreadMethod;
/**
* Servlet
*
*
* 便
*
* @param sce `ServletContextEvent`
*
* Servlet 使
*
*/
@Override
public void contextDestroyed(ServletContextEvent sce) {
logger.info("----------服务器停止----------");
}
/**
* Servlet
*
* 1. Spring
*
* 便 Bean `DictionaryService`
* 2.
*
* 便使 `dictionaryMap` Servlet
* 3. `MyThreadMethod` 线
*
* 使线
*
* @param sce `ServletContextEvent`
*
*
* Servlet Servlet
* Spring
*
*
* Servlet
*/
@Override
public void contextInitialized(ServletContextEvent sce) {
// 通过 `WebApplicationContextUtils` 工具类,
//
// 基于传入的 `ServletContext`(从 `ServletContextEvent` 中获取)获取 Spring 的应用上下文对象,
// 应用上下文对象包含了 Spring 容器管理的所有 Bean 以及相关的配置信息,
//
// 后续可以通过它获取到需要的业务逻辑组件(如 `DictionaryService`)来执行具体的操作。
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
logger.info("----------字典表初始化开始----------");
DictionaryService dictionaryService = (DictionaryService)appContext.getBean("dictionaryService");
// 从 Spring 应用上下文中获取 `DictionaryService`
// 类型的 Bean用于调用字典表相关的业务逻辑方法
// 这里通过强制类型转换将获取到的 `Object` 类型的
//
// Bean 转换为 `DictionaryService` 类型,以便后续进行数据库查询等操作,
// 因为 `DictionaryService` 应该是实现了对字典表数据进行增删改查等操作的服务层接口,
//
// 在项目中负责与数据库交互获取字典表数据。
DictionaryService dictionaryService = (DictionaryService) appContext.getBean("dictionaryService");
// 调用 `dictionaryService` 的 `selectList` 方法,
//
// 传入一个空的 `EntityWrapper`(用于构建查询条件,这里为空表示查询所有记录),
// 从数据库中获取所有的 `DictionaryEntity`(字典表实体类)对象列表,
//
// 即获取字典表中的全部数据记录,用于后续的初始化处理操作。
List<DictionaryEntity> dictionaryEntities = dictionaryService.selectList(new EntityWrapper<DictionaryEntity>());
Map<String, Map<Integer,String>> map = new HashMap<>();
for(DictionaryEntity d :dictionaryEntities){
// 创建一个 `HashMap` 类型的对象,用于存储字典表数据按照字典代码
//
// `dic_code`)分组后的信息,每个 `dic_code` 对应一个内部的 `Map`
// 内部 `Map` 的键是 `code_index`(编码索引),值是 `index_name`(索引名称),
//
//
//
//
// 方便后续根据字典代码快速查找对应的索引信息等操作,
// 这个数据结构会被存储到 Servlet 上下文中,供整个项目中其他地方方便地获取和使用字典表相关信息。
Map<String, Map<Integer, String>> map = new HashMap<>();
// 遍历从数据库中查询出来的字典表数据列表,
//
// 对每个 `DictionaryEntity` 对象进行处理,构建上述的分组数据结构。
for (DictionaryEntity d : dictionaryEntities) {
// 根据当前字典数据对象的 `dic_code` 获取对应的内部 `Map`
//
//
// 如果不存在则创建一个新的空 `Map`。
Map<Integer, String> m = map.get(d.getDicCode());
if(m ==null || m.isEmpty()){
if (m == null || m.isEmpty()) {
m = new HashMap<>();
}
m.put(d.getCodeIndex(),d.getIndexName());
map.put(d.getDicCode(),m);
// 将当前字典数据对象的 `code_index` 和
//
// `index_name` 放入对应的内部 `Map` 中,建立索引关系。
m.put(d.getCodeIndex(), d.getIndexName());
// 将包含当前字典数据对象索引信息的内部 `Map`
//
// 重新放入外层的 `map` 中,以 `dic_code` 为键进行关联,完成分组存储。
map.put(d.getDicCode(), m);
}
sce.getServletContext().setAttribute("dictionaryMap", map);
logger.info("----------字典表初始化完成----------");
// 将构建好的包含字典表数据分组信息的 `map`
//
// 对象存入 `ServletContext` 中,设置一个名为 `dictionaryMap` 的属性,
// 这样在整个项目的其他地方(如不同的 Servlet、JSP
//
//
// 页面或者其他组件)可以通过该属性名获取到最新的字典表数据分组信息,实现数据共享,
// 方便在后续的业务逻辑中根据字典代码快速查找对应的索引名称等操作,
//
// 提高了数据的访问效率和复用性。
sce.getServletContext().setAttribute("dictionaryMap", map);
logger.info("----------字典表初始化完成----------");
logger.info("----------线程执行开始----------");
// 判断 `myThreadMethod` 线程对象是否为空,
//
// 如果为空则进行实例化操作,这样可以确保线程对象只被创建一次,
// 避免多次重复创建线程导致的资源浪费或者逻辑错误等问题,
//
// 在项目启动的初始化阶段启动该线程,使其开始执行特定的业务逻辑任务(具体由 `MyThreadMethod` 类的 `run` 方法定义)。
if (myThreadMethod == null) {
myThreadMethod = new MyThreadMethod();
myThreadMethod.start(); // servlet 上下文初始化时启动线程myThreadMethod
myThreadMethod.start(); // servlet
// 上下文初始化时启动线程 myThreadMethod
}
logger.info("----------线程执行结束----------");
}
}
}

@ -1,4 +1,3 @@
package com.controller;
import java.io.File;
@ -35,246 +34,276 @@ import com.alibaba.fastjson.*;
/**
*
*
*
*
*
*
*
*
*
*
*
* Spring MVC
*
*
*
* 使便
* @author
* @email
*/
*/
@RestController
@Controller
@RequestMapping("/dictionary")
public class DictionaryController {
// 创建一个日志记录器,
// 用于记录该控制器类中各个方法执行过程中的相关信息,
// 方便在开发、调试以及运行时查看操作情况、排查问题等。
private static final Logger logger = LoggerFactory.getLogger(DictionaryController.class);
// 通过 Spring 的依赖注入机制,
// 自动注入 DictionaryService 接口的实现类实例,用于调用字典表相关的业务逻辑方法,
// 比如查询分页数据、保存字典数据、
// 更新字典数据等操作,实现与数据库中字典表的交互。
@Autowired
private DictionaryService dictionaryService;
// 通过 Spring 的依赖注入机制,
// 自动注入 TokenService 接口的实现类实例,可能用于与用户身份验证相关的操作,
// 例如验证请求中携带的 token
// 是否有效等,确保接口访问的安全性(虽然在当前代码中未看到明确的使用场景,但具备这种依赖注入的可能性)。
@Autowired
private TokenService tokenService;
//级联表service
// 通过 Spring 的依赖注入机制,自动注入
// YonghuService 接口的实现类实例,这应该是与用户相关的服务层接口,
// 从名称来看可能用于处理用户相关的业务逻辑
// (在当前代码中虽未体现具体使用,但为后续扩展或关联用户操作预留了可能),属于级联表相关的服务注入。
@Autowired
private YonghuService yonghuService;
/**
*
*/
*
*
*
*
* `dictionaryConvert`
*
* @param params Map
*
* @param request HttpServletRequest
*
* @return `R`
* `com.utils.R` `PageUtils`
*
* `data`
*/
@RequestMapping("/page")
@IgnoreAuth
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
if(params.get("orderBy")==null || params.get("orderBy")==""){
params.put("orderBy","id");
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request) {
// 使用日志记录器记录当前
// `page` 方法的执行情况,记录控制器类的名称以及传入的查询参数信息
// (将参数转换为 JSON 字符串格式记录),方便调试查看请求参数是否正确等情况。
logger.debug("page方法:,,Controller:{},,params:{}", this.getClass().getName(), JSONObject.toJSONString(params));
// 如果传入的参数中没有指定排序字段
// `orderBy`)或者排序字段为空字符串,则默认按照 `id` 字段进行排序,设置默认的排序规则。
if (params.get("orderBy") == null || params.get("orderBy") == "") {
params.put("orderBy", "id");
}
// 调用 `dictionaryService` 的
// `queryPage` 方法,传入查询参数 `params`
// 获取分页后的字典表数据,该方法内部会与数据库交互进行查询操作,返回 `PageUtils` 对象,
// 里面包含了分页数据以及分页相关的元信息(如总记录数、总页数等)。
PageUtils page = dictionaryService.queryPage(params);
//字典表数据转换
List<DictionaryView> list =(List<DictionaryView>)page.getList();
for(DictionaryView c:list){
//修改对应字典表字段
// 获取分页数据中的字典表数据列表,
// 将其转换为 `DictionaryView` 类型的列表,
// `DictionaryView` 可能是适合前端展示或者其他业务场景需求的视图实体类,
// 用于承载更丰富、更便于展示的字典表相关信息(相较于直接的数据库实体类)。
List<DictionaryView> list = (List<DictionaryView>) page.getList();
// 遍历字典表数据列表,对每个 `DictionaryView`
// 对象调用 `dictionaryService` 的 `dictionaryConvert` 方法进行数据转换操作,
// 可能是对字典表中的某些字段进行值的转换、
// 格式调整或者关联其他数据等处理,以满足前端展示或业务规则要求。
for (DictionaryView c : list) {
dictionaryService.dictionaryConvert(c, request);
}
// 返回包含操作成功状态信息(通过 `R.ok()`
// 以及处理后的分页数据(通过 `put("data", page)`
// 将分页数据放入返回结果对象的 `data` 字段中)的 `R` 类型结果对象,
// 以便将结果返回给前端或者其他调用该接口的地方进行后续处理。
return R.ok().put("data", page);
}
/**
*
*/
*
* `id`
*
*
*
* @param id `@PathVariable` `id`
*
* @param request HttpServletRequest
*
* @return `R`
* `data`
*
* `511` `R`
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
public R info(@PathVariable("id") Long id, HttpServletRequest request) {
// 使用日志记录器记录当前 `info`
// 方法的执行情况,记录控制器类的名称以及传入的 `id` 参数值,
// 方便调试查看请求的参数情况。
logger.debug("info方法:,,Controller:{},,id:{}", this.getClass().getName(), id);
// 调用 `dictionaryService` 的 `selectById` 方法,
// 根据传入的 `id` 参数从数据库中查询对应的 `DictionaryEntity`(字典表实体类)对象,
// 如果查询到则返回该对象,若不存在则返回 `null`。
DictionaryEntity dictionary = dictionaryService.selectById(id);
if(dictionary !=null){
//entity转view
if (dictionary!= null) {
// 创建一个 `DictionaryView` 类型的视图实体类对象,
// 用于承载适合返回给前端展示的字典表数据详情信息。
DictionaryView view = new DictionaryView();
BeanUtils.copyProperties( dictionary , view );//把实体数据重构到view中
//修改对应字典表字段
// 使用 Spring 的 `BeanUtils` 工具类,
// 将查询到的 `DictionaryEntity` 实体类中的属性值复制到 `DictionaryView` 视图实体类对象中,
// 实现数据的转换和整合,以便返回更符合前端展示需求的数据结构。
BeanUtils.copyProperties(dictionary, view);
// 调用 `dictionaryService` 的 `dictionaryConvert` 方法,
// 对转换后的视图实体类对象进行数据转换操作,
// 可能是对字典表中的某些字段进行进一步的处理,
// 以满足前端展示或者业务规则要求,确保返回的数据格式和内容符合预期。
dictionaryService.dictionaryConvert(view, request);
// 返回包含操作成功状态信息(通过 `R.ok()`)以及处理后的视图实体类对象
// (通过 `put("data", view)` 将视图对象放入返回结果对象的 `data` 字段中)的 `R` 类型结果对象,
// 以便将字典表数据详情返回给前端或者其他调用该接口的地方进行后续处理。
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
} else {
// 如果未查询到对应的数据记录,
// 则返回包含错误信息(“查不到数据”)和错误状态码 `511` 的 `R` 类型结果对象,表示查询失败的情况,
// 以便前端或者其他调用方能够知晓并做出相应的处理。
return R.error(511, "查不到数据");
}
}
/**
*
*/
*
*
*
*
* @param dictionary `@RequestBody`
* JSON `DictionaryEntity`
*
* @param request HttpServletRequest
*
*
*
* @return `R`
* `R.ok()`
*
* `511` `R`
*
*/
@RequestMapping("/save")
public R save(@RequestBody DictionaryEntity dictionary, HttpServletRequest request){
logger.debug("save方法:,,Controller:{},,dictionary:{}",this.getClass().getName(),dictionary.toString());
public R save(@RequestBody DictionaryEntity dictionary, HttpServletRequest request) {
// 使用日志记录器记录当前 `save` 方法的执行情况,
// 记录控制器类的名称以及传入的要保存的字典表数据对象信息(将对象转换为字符串格式记录),
// 方便调试查看请求的数据情况。
logger.debug("save方法:,,Controller:{},,dictionary:{}", this.getClass().getName(), dictionary.toString());
// 从请求的会话中获取用户的角色信息,将其转换为字符串类型,
// 虽然当前代码中 `if(false)` 这个条件永远为假,
// 可能是后续会添加基于角色判断是否有权限进行保存操作的逻辑,
// 这里先预留了代码结构,
// 暂时不会进入到后面的 `return R.error(511,"永远不会进入");` 这一行代码执行。
String role = String.valueOf(request.getSession().getAttribute("role"));
if(false)
return R.error(511,"永远不会进入");
if (false)
return R.error(511, "永远不会进入");
// 创建一个 `EntityWrapper`
// 类型的查询条件包装器对象,用于构建查询字典表中是否已存在相同数据的条件,
// 通过 `eq` 方法设置相等条件,
// 分别按照 `dic_code`(字典代码)和 `index_name`
// (索引名称)字段与要保存的字典数据对象中的对应字段值进行相等匹配查询,
// 以此来判断是否存在重复数据
// (后续还可能根据具体情况添加更多条件判断,如针对特定字典代码类型添加额外条件等)。
Wrapper<DictionaryEntity> queryWrapper = new EntityWrapper<DictionaryEntity>()
.eq("dic_code", dictionary.getDicCode())
.eq("index_name", dictionary.getIndexName())
;
if(dictionary.getDicCode().contains("_erji_types")){
queryWrapper.eq("super_id",dictionary.getSuperId());
.eq("dic_code", dictionary.getDicCode())
.eq("index_name", dictionary.getIndexName())
;
// 如果要保存的字典数据对象的 `dic_code`
// 字段包含 `_erji_types` 字符串(可能表示二级类型相关的字典数据,这里根据业务规则进行额外的条件判断),
// 则在查询条件包装器中添加一个相等条件,按照 `super_id`
// (父字段 `id`)字段与要保存的字典数据对象中的 `super_id` 值进行匹配查询,进一步细化重复数据的判断条件。
if (dictionary.getDicCode().contains("_erji_types")) {
queryWrapper.eq("super_id", dictionary.getSuperId());
}
logger.info("sql语句:"+queryWrapper.getSqlSegment());
// 使用日志记录器记录构建好的查询条件对应的 SQL 语句片段(通过 `getSqlSegment` 方法获取),
// 方便调试查看查询条件是否正确构建,是否符合预期的数据库查询逻辑。
logger.info("sql语句:" + queryWrapper.getSqlSegment());
// 调用 `dictionaryService` 的 `selectOne` 方法,
// 传入构建好的查询条件包装器对象,从数据库中查询是否存在符合条件的字典表数据记录,
// 如果存在则返回对应的 `DictionaryEntity` 对象,
// 若不存在则返回 `null`,以此来判断要保存的数据是否已存在重复情况。
DictionaryEntity dictionaryEntity = dictionaryService.selectOne(queryWrapper);
if(dictionaryEntity==null){
if (dictionaryEntity == null) {
// 如果要保存的数据不存在重复情况,则设置该字典数据对象的
// `createTime`(创建时间)字段为当前时间,用于记录数据的创建时间信息。
dictionary.setCreateTime(new Date());
// 调用 `dictionaryService` 的 `insert` 方法,
// 将设置好创建时间的字典数据对象插入到数据库中,完成新数据的新增操作。
dictionaryService.insert(dictionary);
//字典表新增数据,把数据再重新查出,放入监听器中
List<DictionaryEntity> dictionaryEntities = dictionaryService.selectList(new EntityWrapper<DictionaryEntity>());
ServletContext servletContext = request.getServletContext();
Map<String, Map<Integer,String>> map = new HashMap<>();
for(DictionaryEntity d :dictionaryEntities){
Map<Integer, String> m = map.get(d.getDicCode());
if(m ==null || m.isEmpty()){
m = new HashMap<>();
}
m.put(d.getCodeIndex(),d.getIndexName());
map.put(d.getDicCode(),m);
}
servletContext.setAttribute("dictionaryMap",map);
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
/**
*
*/
@RequestMapping("/update")
public R update(@RequestBody DictionaryEntity dictionary, HttpServletRequest request){
logger.debug("update方法:,,Controller:{},,dictionary:{}",this.getClass().getName(),dictionary.toString());
String role = String.valueOf(request.getSession().getAttribute("role"));
// if(false)
// return R.error(511,"永远不会进入");
//根据字段查询是否有相同数据
Wrapper<DictionaryEntity> queryWrapper = new EntityWrapper<DictionaryEntity>()
.notIn("id",dictionary.getId())
.eq("dic_code", dictionary.getDicCode())
.eq("index_name", dictionary.getIndexName())
;
if(dictionary.getDicCode().contains("_erji_types")){
queryWrapper.eq("super_id",dictionary.getSuperId());
}
logger.info("sql语句:"+queryWrapper.getSqlSegment());
DictionaryEntity dictionaryEntity = dictionaryService.selectOne(queryWrapper);
if(dictionaryEntity==null){
dictionaryService.updateById(dictionary);//根据id更新
//如果字典表修改数据的话,把数据再重新查出,放入监听器中
// 字典表新增数据后,把字典表中的所有数据重新查询出来,
// 用于放入监听器中(可能是为了在其他地方能够获取到最新的字典表数据,保持数据一致性等业务需求)。
List<DictionaryEntity> dictionaryEntities = dictionaryService.selectList(new EntityWrapper<DictionaryEntity>());
// 获取当前请求的 `ServletContext` 对象,
// 它可以用于在整个应用程序的不同组件之间共享数据,在这里用于存放字典表数据信息,供监听器等其他组件使用。
ServletContext servletContext = request.getServletContext();
Map<String, Map<Integer,String>> map = new HashMap<>();
for(DictionaryEntity d :dictionaryEntities){
// 创建一个 `HashMap` 类型的对象,
// 用于存储字典表数据按照字典代码(`dic_code`)分组后的信息,每个 `dic_code` 对应一个内部的 `Map`
// 内部 `Map` 的键是 `code_index`(编码索引),
// 值是 `index_name`(索引名称),方便后续根据字典代码快速查找对应的索引信息等操作。
Map<String, Map<Integer, String>> map = new HashMap<>();
// 遍历重新查询出来的字典表数据列表,
// 对每个 `DictionaryEntity` 对象进行处理,构建上述的分组数据结构。
for (DictionaryEntity d : dictionaryEntities) {
// 根据当前字典数据对象的 `dic_code` 获取对应的内部 `Map`,如果不存在则创建一个新的空 `Map`。
Map<Integer, String> m = map.get(d.getDicCode());
if(m ==null || m.isEmpty()){
if (m == null || m.isEmpty()) {
m = new HashMap<>();
}
m.put(d.getCodeIndex(),d.getIndexName());
map.put(d.getDicCode(),m);
// 将当前字典数据对象的 `code_index` 和
// `index_name` 放入对应的内部 `Map` 中,建立索引关系。
m.put(d.getCodeIndex(), d.getIndexName());
// 将包含当前字典数据对象索引信息的内部 `Map`
// 重新放入外层的 `map` 中,以 `dic_code` 为键进行关联,完成分组存储。
map.put(d.getDicCode(), m);
}
servletContext.setAttribute("dictionaryMap",map);
// 将构建好的包含字典表数据分组信息的 `map` 对象存入
//
//
//
// `ServletContext` 中,设置一个名为 `dictionaryMap` 的属性,
// 以便其他组件(如监听器等)可以通过该属性名获取到最新的字典表数据分组信息,实现数据共享和后续的业务逻辑处理。
servletContext.setAttribute("dictionaryMap", map);
// 返回操作成功的状态信息(通过 `R.ok()`),表示字典表数据新增成功,
//
//
// 以便前端或者其他调用该接口的地方知晓操作结果并进行后续处理。
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
} else {
/**
*
*/
@RequestMapping("/delete")
public R delete(@RequestBody Integer[] ids){
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
dictionaryService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
*
*/
@RequestMapping("/maxCodeIndex")
public R maxCodeIndex(@RequestBody DictionaryEntity dictionary){
logger.debug("maxCodeIndex:,,Controller:{},,dictionary:{}",this.getClass().getName(),dictionary.toString());
List<String> descs = new ArrayList<>();
descs.add("code_index");
Wrapper<DictionaryEntity> queryWrapper = new EntityWrapper<DictionaryEntity>()
.eq("dic_code", dictionary.getDicCode())
.orderDesc(descs);
logger.info("sql语句:"+queryWrapper.getSqlSegment());
List<DictionaryEntity> dictionaryEntityList = dictionaryService.selectList(queryWrapper);
if(dictionaryEntityList != null ){
return R.ok().put("maxCodeIndex",dictionaryEntityList.get(0).getCodeIndex()+1);
}else{
return R.ok().put("maxCodeIndex",1);
}
}
/**
*
*/
@RequestMapping("/batchInsert")
public R save( String fileName, HttpServletRequest request){
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
List<DictionaryEntity> dictionaryList = new ArrayList<>();//上传的东西
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
Date date = new Date();
int lastIndexOf = fileName.lastIndexOf(".");
if(lastIndexOf == -1){
return R.error(511,"该文件没有后缀");
}else{
String suffix = fileName.substring(lastIndexOf);
if(!".xls".equals(suffix)){
return R.error(511,"只支持后缀为xls的excel文件");
}else{
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
File file = new File(resource.getFile());
if(!file.exists()){
return R.error(511,"找不到上传文件,请联系管理员");
}else{
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
dataList.remove(0);//删除第一行,因为第一行是提示
for(List<String> data:dataList){
//循环
DictionaryEntity dictionaryEntity = new DictionaryEntity();
// dictionaryEntity.setDicCode(data.get(0)); //字段 要改的
// dictionaryEntity.setDicName(data.get(0)); //字段名 要改的
// dictionaryEntity.setCodeIndex(Integer.valueOf(data.get(0))); //编码 要改的
// dictionaryEntity.setIndexName(data.get(0)); //编码名字 要改的
// dictionaryEntity.setSuperId(Integer.valueOf(data.get(0))); //父字段id 要改的
// dictionaryEntity.setBeizhu(data.get(0)); //备注 要改的
// dictionaryEntity.setCreateTime(date);//时间
dictionaryList.add(dictionaryEntity);
//把要查询是否重复的字段放入map中
}
//查询是否重复
dictionaryService.insertBatch(dictionaryList);
return R.ok();
}
}
}
}catch (Exception e){
e.printStackTrace();
return R.error(511,"批量插入数据异常,请联系管理员");
// 如果查询到要保存的数据已存在重复情况,
//
// 则返回包含错误信息(“表中有相同数据”)和相应错误状态码(`511`)的 `R` 类型结果对象,
// 表示新增数据失败,以便前端或者其他调用方能够知晓并做出相应的处理。
return R.error(511, "表中有相同数据");
}
}
}
/**
*
*

@ -1,4 +1,3 @@
package com.controller;
import java.io.File;
@ -35,315 +34,305 @@ import com.alibaba.fastjson.*;
/**
*
*
* @author
* HTTP
*
* @author WMZ
* @email
*/
*/
@RestController
@Controller
@RequestMapping("/forum")
public class ForumController {
// 创建日志记录器,
// 用于记录该类中各个方法执行过程中的关键信息,方便调试和问题排查
private static final Logger logger = LoggerFactory.getLogger(ForumController.class);
// 通过Spring的依赖注入自动装配ForumService
// 用于处理论坛相关的业务逻辑,比如查询、插入、更新、删除等操作
@Autowired
private ForumService forumService;
// 自动注入TokenService
// 可能用于处理用户认证相关的令牌操作(具体功能需看对应服务层实现)
@Autowired
private TokenService tokenService;
// 自动注入DictionaryService
// 用于处理字典表相关的数据转换等操作(比如将字典表中的编码转换为对应的有意义的值等)
@Autowired
private DictionaryService dictionaryService;
//级联表service
// 自动注入YonghuService
// 用于处理与用户Yonghu可能是具体业务中的一种用户类型相关的级联表操作
@Autowired
private YonghuService yonghuService;
// 自动注入UsersService
// 用于处理与普通用户相关的级联表操作(比如获取用户详细信息等)
@Autowired
private UsersService usersService;
/**
*
*/
*
* paramsHttpServletRequest
*
* @param params Map
* @param request HttpServletRequest
* @return RR
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
if(params.get("orderBy")==null || params.get("orderBy")==""){
params.put("orderBy","id");
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request) {
// 记录page方法的调用信息
// 包括当前类名和传入的参数,
// 方便调试查看参数情况以JSON字符串形式记录参数
logger.debug("page方法:,,Controller:{},,params:{}", this.getClass().getName(), JSONObject.toJSONString(params));
// 如果传入的排序字段参数为空,
// 则默认按照"id"字段进行排序
if (params.get("orderBy") == null || params.get("orderBy") == "") {
params.put("orderBy", "id");
}
// 调用forumService的queryPage方法
// 根据传入的参数获取分页数据(该方法内部应该是与数据库交互获取相应的数据列表等)
PageUtils page = forumService.queryPage(params);
//字典表数据转换
List<ForumView> list =(List<ForumView>)page.getList();
for(ForumView c:list){
//修改对应字典表字段
// 获取分页数据中的列表数据
// 这里应该是ForumView类型的列表ForumView可能是用于展示的视图对象
List<ForumView> list = (List<ForumView>) page.getList();
// 遍历列表数据,
// 对每条数据进行字典表数据转换操作(比如将字典表中的编码转换为对应的实际含义显示给前端)
for (ForumView c : list) {
dictionaryService.dictionaryConvert(c, request);
}
// 返回包含处理后数据的成功结果对象
// R.ok()表示操作成功,并将数据放入返回对象中返回给前端)
return R.ok().put("data", page);
}
/**
*
*/
*
* id
*
* @param id Longid
* @param request HttpServletRequest
*
* @return R
*
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
public R info(@PathVariable("id") Long id, HttpServletRequest request) {
logger.debug("info方法:,,Controller:{},,id:{}", this.getClass().getName(), id);
// 通过forumService根据传入的id从数据库中查询对应的ForumEntity对象ForumEntity可能是数据库对应的实体类
ForumEntity forum = forumService.selectById(id);
if(forum !=null){
//entity转view
if (forum!= null) {
// 创建ForumView对象
// 用于将查询到的实体数据转换为适合展示的视图数据ForumView可能包含了部分需要展示给前端的字段等
ForumView view = new ForumView();
BeanUtils.copyProperties( forum , view );//把实体数据重构到view中
//级联表
YonghuEntity yonghu = yonghuService.selectById(forum.getYonghuId());
if(yonghu != null){
BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime"});//把级联的数据添加到view中,并排除id和创建时间字段
view.setYonghuId(yonghu.getId());
}
//管理员用户表做特殊处理,防止和用户表账户姓名字段冲突
UsersEntity users = usersService.selectById(forum.getUsersId());
if(users != null){
view.setUsersId(users.getId());
view.setUusername(users.getUsername());
view.setUpassword(users.getPassword());
view.setUrole(users.getRole());
view.setUaddtime(users.getAddtime());
}
//修改对应字典表字段
// 使用Spring的BeanUtils工具
// 将forum实体对象中的属性值复制到view视图对象中
BeanUtils.copyProperties(forum, view);
// 处理级联表数据,
// 获取与该论坛记录关联的YonghuEntity用户相关的实体对象并将部分属性复制到view中排除一些不需要的字段
YonghuEntity yonghu = yonghuService.selectById(forum.getYonghuId());
if (yonghu!= null) {
BeanUtils.copyProperties(yonghu, view, new String[] { "id", "createTime", "insertTime", "updateTime" });
view.setYonghuId(yonghu.getId());
}
// 处理管理员用户表数据,
// 获取与该论坛记录关联的UsersEntity管理员用户相关的实体对象并将部分关键属性设置到view中
UsersEntity users = usersService.selectById(forum.getUsersId());
if (users!= null) {
view.setUsersId(users.getId());
view.setUusername(users.getUsername());
view.setUpassword(users.getPassword());
view.setUrole(users.getRole());
view.setUaddtime(users.getAddtime());
}
// 对view视图对象进行字典表数据转换操作
// (比如将字典表中的编码转换为对应的实际含义显示给前端)
dictionaryService.dictionaryConvert(view, request);
// 返回包含处理后详细数据的成功结果对象R.ok()表示操作成功,
// 并将数据放入返回对象中返回给前端)
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
} else {
// 如果未查询到对应的数据,
// 则返回包含错误码和错误提示信息的错误结果对象
return R.error(511, "查不到数据");
}
}
/**
*
*/
*
* ForumEntityHttpServletRequest
* id
* @param forum ForumEntity
* @param request HttpServletRequestid
* @return R
*/
@RequestMapping("/save")
public R save(@RequestBody ForumEntity forum, HttpServletRequest request){
logger.debug("save方法:,,Controller:{},,forum:{}",this.getClass().getName(),forum.toString());
public R save(@RequestBody ForumEntity forum, HttpServletRequest request) {
logger.debug("save方法:,,Controller:{},,forum:{}", this.getClass().getName(), forum.toString());
// 从HttpServletRequest的会话中获取当前用户的角色信息这里先将获取到的Object类型强制转换为String类型
String role = String.valueOf(request.getSession().getAttribute("role"));
if(false)
return R.error(511,"永远不会进入");
else if("用户".equals(role))
if (false)
return R.error(511, "永远不会进入");
else if ("用户".equals(role))
// 如果当前用户角色是"用户"
// 则将论坛记录的YonghuId设置为从会话中获取的当前用户的id这里做了一些类型转换操作
forum.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
else if("管理员".equals(role))
else if ("管理员".equals(role))
// 如果当前用户角色是"管理员"
// 则将论坛记录的UsersId设置为从会话中获取的当前用户的id同样进行了类型转换
forum.setUsersId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
// 创建EntityWrapper对象
// 用于构建查询条件,检查数据库中是否已经存在相同的数据(根据多个字段进行等值判断)
Wrapper<ForumEntity> queryWrapper = new EntityWrapper<ForumEntity>()
.eq("forum_name", forum.getForumName())
.eq("yonghu_id", forum.getYonghuId())
.eq("users_id", forum.getUsersId())
.eq("super_ids", forum.getSuperIds())
.eq("forum_state_types", forum.getForumStateTypes())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
.eq("forum_name", forum.getForumName())
.eq("yonghu_id", forum.getYonghuId())
.eq("users_id", forum.getUsersId())
.eq("super_ids", forum.getSuperIds())
.eq("forum_state_types", forum.getForumStateTypes());
logger.info("sql语句:" + queryWrapper.getSqlSegment());
// 根据构建的查询条件查询数据库中是否已经存在相同的数据
// 通过selectOne方法查询一条符合条件的数据
ForumEntity forumEntity = forumService.selectOne(queryWrapper);
if(forumEntity==null){
if (forumEntity == null) {
// 如果不存在相同数据,
// 则设置论坛记录的插入时间和创建时间为当前时间并将该记录插入到数据库中通过insert方法
forum.setInsertTime(new Date());
forum.setCreateTime(new Date());
forumService.insert(forum);
return R.ok();
}else {
return R.error(511,"表中有相同数据");
} else {
// 如果存在相同数据,
// 则返回包含错误码和提示信息的错误结果对象,表示表中已有相同数据
return R.error(511, "表中有相同数据");
}
}
/**
*
*/
*
* ForumEntityHttpServletRequest
* id
* @param forum ForumEntity
* @param request HttpServletRequest
* @return R
*/
@RequestMapping("/update")
public R update(@RequestBody ForumEntity forum, HttpServletRequest request){
logger.debug("update方法:,,Controller:{},,forum:{}",this.getClass().getName(),forum.toString());
public R update(@RequestBody ForumEntity forum, HttpServletRequest request) {
logger.debug("update方法:,,Controller:{},,forum:{}", this.getClass().getName(), forum.toString());
String role = String.valueOf(request.getSession().getAttribute("role"));
// if(false)
// return R.error(511,"永远不会进入");
// else if("用户".equals(role))
// if (false)
// return R.error(511, "永远不会进入");
// else if ("用户".equals(role))
// forum.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
// else if("管理员".equals(role))
// else if ("管理员".equals(role))
// forum.setUsersId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
//根据字段查询是否有相同数据
// 创建EntityWrapper对象用于构建查询条件检查数据库中除了当前要修改的记录根据id排除外是否存在相同的数据根据多个字段进行等值判断
Wrapper<ForumEntity> queryWrapper = new EntityWrapper<ForumEntity>()
.notIn("id",forum.getId())
.andNew()
.eq("forum_name", forum.getForumName())
.eq("yonghu_id", forum.getYonghuId())
.eq("users_id", forum.getUsersId())
.eq("super_ids", forum.getSuperIds())
.eq("forum_state_types", forum.getForumStateTypes())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
.notIn("id", forum.getId())
.andNew()
.eq("forum_name", forum.getForumName())
.eq("yonghu_id", forum.getYonghuId())
.eq("users_id", forum.getUsersId())
.eq("super_ids", forum.getSuperIds())
.eq("forum_state_types", forum.getForumStateTypes());
logger.info("sql语句:" + queryWrapper.getSqlSegment());
// 根据构建的查询条件查询数据库中是否已经存在相同的数据通过selectOne方法查询一条符合条件的数据
ForumEntity forumEntity = forumService.selectOne(queryWrapper);
// 设置论坛记录的更新时间为当前时间
forum.setUpdateTime(new Date());
if(forumEntity==null){
forumService.updateById(forum);//根据id更新
if (forumEntity == null) {
// 如果不存在相同数据,
// 则根据传入的forum对象的id更新数据库中的对应论坛记录通过updateById方法
forumService.updateById(forum);
return R.ok();
}else {
return R.error(511,"表中有相同数据");
} else {
// 如果存在相同数据,
// 则返回包含错误码和提示信息的错误结果对象,表示表中已有相同数据
return R.error(511, "表中有相同数据");
}
}
/**
*
*/
/**
*
* idforumService
*
* @param ids id
* @return R
*/
@RequestMapping("/delete")
public R delete(@RequestBody Integer[] ids){
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
public R delete(@RequestBody Integer[] ids) {
logger.debug("delete:,,Controller:{},,ids:{}", this.getClass().getName(), ids.toString());
// 调用forumService的deleteBatchIds方法
// 批量删除数据库中对应id的论坛记录传入的是将数组转换为List后的集合
forumService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
*
*
* fileNameHttpServletRequestExcel
*
* @param fileName
* @param request HttpServletRequestid
* @return R
*/
@RequestMapping("/batchInsert")
public R save( String fileName, HttpServletRequest request){
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
public R save(String fileName, HttpServletRequest request) {
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}", this.getClass().getName(), fileName);
// 从HttpServletRequest的会话中获取当前用户的id并转换为Integer类型这里做了一些强制类型转换操作
Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
List<ForumEntity> forumList = new ArrayList<>();//上传的东西
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
// 创建一个用于存储要插入数据库的ForumEntity对象列表即从文件中读取到的多条论坛数据记录
List<ForumEntity> forumList = new ArrayList<>();
// 创建一个Map用于存储要查询是否重复的字段信息具体的使用方式需看后续代码逻辑
Map<String, List<String>> seachFields = new HashMap<>();
Date date = new Date();
int lastIndexOf = fileName.lastIndexOf(".");
if(lastIndexOf == -1){
return R.error(511,"该文件没有后缀");
}else{
if (lastIndexOf == -1) {
return R.error(511, "该文件没有后缀");
} else {
String suffix = fileName.substring(lastIndexOf);
if(!".xls".equals(suffix)){
return R.error(511,"只支持后缀为xls的excel文件");
}else{
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
if (!".xls".equals(suffix)) {
return R.error(511, "只支持后缀为xls的excel文件");
} else {
// 通过类加载器获取指定文件名对应的文件资源路径(这里应该是位于"static/upload/"目录下的文件)
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);
File file = new File(resource.getFile());
if(!file.exists()){
return R.error(511,"找不到上传文件,请联系管理员");
}else{
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
dataList.remove(0);//删除第一行,因为第一行是提示
for(List<String> data:dataList){
//循环
if (!file.exists()) {
return R.error(511, "找不到上传文件,请联系管理员");
} else {
// 调用PoiUtil的poiImport方法读取Excel文件中的数据返回的是一个嵌套的List外层List表示行内层List表示每行中的单元格数据
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());
// 删除读取到的数据列表中的第一行(可能是表头之类的提示信息,不需要插入数据库)
dataList.remove(0);
for (List<String> data : dataList) {
// 循环处理每一行数据创建一个ForumEntity对象用于存储要插入数据库的一条论坛记录信息
ForumEntity forumEntity = new ForumEntity();
// forumEntity.setForumName(data.get(0)); //帖子标题 要改的
// forumEntity.setYonghuId(Integer.valueOf(data.get(0))); //用户 要改的
// forumEntity.setUsersId(Integer.valueOf(data.get(0))); //管理员 要改的
// forumEntity.setForumContent("");//详情和图片
// forumEntity.setSuperIds(Integer.valueOf(data.get(0))); //父id 要改的
// forumEntity.setForumStateTypes(Integer.valueOf(data.get(0))); //帖子状态 要改的
// forumEntity.setInsertTime(date);//时间
// forumEntity.setUpdateTime(sdf.parse(data.get(0))); //修改时间 要改的
// forumEntity.setCreateTime(date);//时间
forumList.add(forumEntity);
//把要查询是否重复的字段放入map中
}
//查询是否重复
forumService.insertBatch(forumList);
return R.ok();
}
}
}
}catch (Exception e){
e.printStackTrace();
return R.error(511,"批量插入数据异常,请联系管理员");
}
}
/**
*
*/
@IgnoreAuth
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
// 没有指定排序字段就默认id倒序
if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){
params.put("orderBy","id");
}
PageUtils page = forumService.queryPage(params);
//字典表数据转换
List<ForumView> list =(List<ForumView>)page.getList();
for(ForumView c:list)
dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
return R.ok().put("data", page);
}
/**
*
*/
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
ForumEntity forum = forumService.selectById(id);
if(forum !=null){
//entity转view
ForumView view = new ForumView();
BeanUtils.copyProperties( forum , view );//把实体数据重构到view中
//级联表
YonghuEntity yonghu = yonghuService.selectById(forum.getYonghuId());
if(yonghu != null){
BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
view.setYonghuId(yonghu.getId());
}
UsersEntity users = usersService.selectById(forum.getUsersId());
if(users != null){
view.setUsersId(users.getId());
view.setUusername(users.getUsername());
view.setUpassword(users.getPassword());
view.setUrole(users.getRole());
view.setUaddtime(users.getAddtime());
}
//修改对应字典表字段
dictionaryService.dictionaryConvert(view, request);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
*
*/
@RequestMapping("/add")
public R add(@RequestBody ForumEntity forum, HttpServletRequest request){
logger.debug("add方法:,,Controller:{},,forum:{}",this.getClass().getName(),forum.toString());
Wrapper<ForumEntity> queryWrapper = new EntityWrapper<ForumEntity>()
.eq("forum_name", forum.getForumName())
.eq("yonghu_id", forum.getYonghuId())
.eq("users_id", forum.getUsersId())
.eq("super_ids", forum.getSuperIds())
.eq("forum_state_types", forum.getForumStateTypes())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
ForumEntity forumEntity = forumService.selectOne(queryWrapper);
if(forumEntity==null){
forum.setInsertTime(new Date());
forum.setCreateTime(new Date());
forumService.insert(forum);
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
}
// forumEntity.setForumStateTypes(Integer.valueOf(data.get(0))); //帖子状态 要改的

@ -1,4 +1,3 @@
package com.controller;
import java.io.File;
@ -35,178 +34,273 @@ import com.alibaba.fastjson.*;
/**
*
*
* @author
* @email
*/
* HTTP
*
*
* @author wangmuzi
*
*/
@RestController
@Controller
@RequestMapping("/news")
public class NewsController {
// 创建一个日志记录器,用于记录该类中各个方法执行过程中的关键信息,方便后续调试和问题排查
private static final Logger logger = LoggerFactory.getLogger(NewsController.class);
// 通过Spring的依赖注入
// 自动装配NewsService用于处理公告信息相关的核心业务逻辑比如数据库操作等
@Autowired
private NewsService newsService;
// 自动注入TokenService
// 可能用于处理与用户认证令牌相关的操作(具体功能需看对应服务层实现)
@Autowired
private TokenService tokenService;
// 自动注入DictionaryService
// 用于处理字典表数据的转换操作,例如将字典表中的编码转换为有实际意义的展示值
@Autowired
private DictionaryService dictionaryService;
//级联表service
// 自动注入YonghuService
// 可能用于处理与用户Yonghu可能是特定业务中的一种用户类型相关的级联表操作具体使用场景看后续代码逻辑
@Autowired
private YonghuService yonghuService;
/**
*
*/
*
* HttpServletRequest
*
* @param params Map
* @param request HttpServletRequestID便
* @return RR
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request) {
// 记录page方法的调用信息
// 包括当前类名和传入的参数将参数转换为JSON字符串形式记录方便查看参数详情用于调试目的
logger.debug("page方法:,,Controller:{},,params:{}", this.getClass().getName(), JSONObject.toJSONString(params));
// 从HttpServletRequest的会话中获取当前用户的角色信息
// 并转换为String类型
String role = String.valueOf(request.getSession().getAttribute("role"));
if(false)
return R.error(511,"永不会进入");
else if("用户".equals(role))
params.put("yonghuId",request.getSession().getAttribute("userId"));
if(params.get("orderBy")==null || params.get("orderBy")==""){
params.put("orderBy","id");
if (false)
return R.error(511, "永不会进入");
else if ("用户".equals(role))
// 如果当前用户角色是"用户"
// 则将当前用户的ID添加到查询参数中作为查询属于该用户的公告信息的条件这里假设数据库中有对应的关联字段
params.put("yonghuId", request.getSession().getAttribute("userId"));
// 如果传入的排序字段参数为空,则默认按照"id"字段进行排序
if (params.get("orderBy") == null || params.get("orderBy") == "") {
params.put("orderBy", "id");
}
// 调用newsService的queryPage方法
// 根据传入的参数获取公告信息的分页数据(该方法内部应该是与数据库交互来查询相应的数据列表等)
PageUtils page = newsService.queryPage(params);
//字典表数据转换
List<NewsView> list =(List<NewsView>)page.getList();
for(NewsView c:list){
//修改对应字典表字段
// 获取分页数据中的列表数据这里应该是NewsView类型的列表NewsView可能是用于展示的视图对象
List<NewsView> list = (List<NewsView>) page.getList();
// 遍历列表数据,对每条数据进行字典表数据转换操作,
// 将字典表中的编码等转换为对应的实际展示值(比如状态码转换为具体的状态文字描述)
for (NewsView c : list) {
dictionaryService.dictionaryConvert(c, request);
}
// 返回包含处理后数据的成功结果对象R.ok()表示操作成功,
// 并将数据放入返回对象中返回给前端)
return R.ok().put("data", page);
}
/**
*
*/
*
* id
* @param id Longid
* @param request HttpServletRequest
* @return R
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
public R info(@PathVariable("id") Long id, HttpServletRequest request) {
logger.debug("info方法:,,Controller:{},,id:{}", this.getClass().getName(), id);
// 通过newsService根据传入的id从数据库中查询对应的NewsEntity对象NewsEntity可能是数据库对应的实体类
NewsEntity news = newsService.selectById(id);
if(news !=null){
//entity转view
if (news!= null) {
// 创建NewsView对象
// 用于将查询到的实体数据转换为适合展示的视图数据NewsView可能包含了部分需要展示给前端的字段等
NewsView view = new NewsView();
BeanUtils.copyProperties( news , view );//把实体数据重构到view中
// 使用Spring的BeanUtils工具
// 将news实体对象中的属性值复制到view视图对象中实现实体转视图的基本数据复制
BeanUtils.copyProperties(news, view);
//修改对应字典表字段
// 对view视图对象进行字典表数据转换操作
// 将字典表相关字段转换为有实际意义的展示值(比如将类型编码转换为类型名称等)
dictionaryService.dictionaryConvert(view, request);
// 返回包含处理后详细数据的成功结果对象R.ok()表示操作成功,
// 并将数据放入返回对象中返回给前端)
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
} else {
// 如果未查询到对应的数据,
// 则返回包含错误码和错误提示信息的错误结果对象
return R.error(511, "查不到数据");
}
}
/**
*
*/
*
* NewsEntityHttpServletRequest
*
* @param news NewsEntity
* @param request HttpServletRequest使
* @return R
*/
@RequestMapping("/save")
public R save(@RequestBody NewsEntity news, HttpServletRequest request){
logger.debug("save方法:,,Controller:{},,news:{}",this.getClass().getName(),news.toString());
public R save(@RequestBody NewsEntity news, HttpServletRequest request) {
logger.debug("save方法:,,Controller:{},,news:{}", this.getClass().getName(), news.toString());
String role = String.valueOf(request.getSession().getAttribute("role"));
if(false)
return R.error(511,"永远不会进入");
if (false)
return R.error(511, "永远不会进入");
// 创建EntityWrapper对象用于构建查询条件
// 检查数据库中是否已经存在相同的公告信息(根据公告名称和公告类型等字段进行等值判断)
Wrapper<NewsEntity> queryWrapper = new EntityWrapper<NewsEntity>()
.eq("news_name", news.getNewsName())
.eq("news_types", news.getNewsTypes())
;
.eq("news_name", news.getNewsName())
.eq("news_types", news.getNewsTypes());
logger.info("sql语句:"+queryWrapper.getSqlSegment());
logger.info("sql语句:" + queryWrapper.getSqlSegment());
// 根据构建的查询条件查询数据库中是否已经存在相同的数据通过selectOne方法查询一条符合条件的数据
NewsEntity newsEntity = newsService.selectOne(queryWrapper);
if(newsEntity==null){
if (newsEntity == null) {
// 如果不存在相同数据,则设置公告信息的插入时间和创建时间为当前时间,
// 并将该公告信息插入到数据库中通过insert方法
news.setInsertTime(new Date());
news.setCreateTime(new Date());
newsService.insert(news);
return R.ok();
}else {
return R.error(511,"表中有相同数据");
} else {
// 如果存在相同数据,则返回包含错误码和提示信息的错误结果对象,表示表中已有相同数据
return R.error(511, "表中有相同数据");
}
}
/**
*
*/
*
* NewsEntityHttpServletRequest
* id
* @param news NewsEntity
* @param request HttpServletRequest使
* @return R
*/
@RequestMapping("/update")
public R update(@RequestBody NewsEntity news, HttpServletRequest request){
logger.debug("update方法:,,Controller:{},,news:{}",this.getClass().getName(),news.toString());
public R update(@RequestBody NewsEntity news, HttpServletRequest request) {
logger.debug("update方法:,,Controller:{},,news:{}", this.getClass().getName(), news.toString());
String role = String.valueOf(request.getSession().getAttribute("role"));
// if(false)
// return R.error(511,"永远不会进入");
//根据字段查询是否有相同数据
// if (false)
// return R.error(511, "永远不会进入");
// 创建EntityWrapper对象用于构建查询条件检查数据库中除了当前要修改的记录根据id排除外是否存在相同的公告信息根据公告名称和公告类型等字段进行等值判断
Wrapper<NewsEntity> queryWrapper = new EntityWrapper<NewsEntity>()
.notIn("id",news.getId())
.andNew()
.eq("news_name", news.getNewsName())
.eq("news_types", news.getNewsTypes())
;
.notIn("id", news.getId())
.andNew()
.eq("news_name", news.getNewsName())
.eq("news_types", news.getNewsTypes());
logger.info("sql语句:" + queryWrapper.getSqlSegment());
logger.info("sql语句:"+queryWrapper.getSqlSegment());
// 根据构建的查询条件查询数据库中是否已经存在相同的数据通过selectOne方法查询一条符合条件的数据
NewsEntity newsEntity = newsService.selectOne(queryWrapper);
if("".equals(news.getNewsPhoto()) || "null".equals(news.getNewsPhoto())){
news.setNewsPhoto(null);
// 如果公告图片字段为空字符串或者值为"null"
// 这里可能是前端传递过来的表示空值的情况则将其设置为null以便后续正确更新到数据库中
if ("".equals(news.getNewsPhoto()) || "null".equals(news.getNewsPhoto())) {
news.setNewsPhoto(null);
}
if(newsEntity==null){
newsService.updateById(news);//根据id更新
if (newsEntity == null) {
// 如果不存在相同数据,
// 则根据传入的news对象的id更新数据库中的对应公告信息记录通过updateById方法
newsService.updateById(news);
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
} else {
// 如果存在相同数据,
// 则返回包含错误码和提示信息的错误结果对象,表示表中已有相同数据
return R.error(511, "表中有相同数据");
}
}
/**
*
*/
*
* idnewsService
*
* @param ids id
* @return R
*/
@RequestMapping("/delete")
public R delete(@RequestBody Integer[] ids){
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
public R delete(@RequestBody Integer[] ids) {
logger.debug("delete:,,Controller:{},,ids:{}", this.getClass().getName(), ids.toString());
// 调用newsService的deleteBatchIds方法
// 批量删除数据库中对应id的公告信息记录传入的是将数组转换为List后的集合
newsService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
*
*
* fileNameHttpServletRequestExcel
*
* @param fileName Excel
* @param request HttpServletRequestID
* @return R
*/
@RequestMapping("/batchInsert")
public R save( String fileName, HttpServletRequest request){
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
public R save(String fileName, HttpServletRequest request) {
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}", this.getClass().getName(), fileName);
// 从HttpServletRequest的会话中获取当前用户的ID
// 并转换为Integer类型这里做了一些强制类型转换操作
Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
List<NewsEntity> newsList = new ArrayList<>();//上传的东西
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
// 创建一个用于存储要插入数据库的NewsEntity对象列表即从文件中读取到的多条公告信息记录
List<NewsEntity> newsList = new ArrayList<>();
// 创建一个Map
// 用于存储要查询是否重复的字段信息(具体的使用方式需看后续代码逻辑,可能用于去重判断等)
Map<String, List<String>> seachFields = new HashMap<>();
Date date = new Date();
int lastIndexOf = fileName.lastIndexOf(".");
if(lastIndexOf == -1){
return R.error(511,"该文件没有后缀");
}else{
if (lastIndexOf == -1) {
return R.error(511, "该文件没有后缀");
} else {
String suffix = fileName.substring(lastIndexOf);
if(!".xls".equals(suffix)){
return R.error(511,"只支持后缀为xls的excel文件");
}else{
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
if (!".xls".equals(suffix)) {
return R.error(511, "只支持后缀为xls的excel文件");
} else {
// 通过类加载器获取指定文件名对应的文件资源路径(这里应该是位于"static/upload/"目录下的文件)
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);
File file = new File(resource.getFile());
if(!file.exists()){
return R.error(511,"找不到上传文件,请联系管理员");
}else{
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
dataList.remove(0);//删除第一行,因为第一行是提示
for(List<String> data:dataList){
//循环
if (!file.exists()) {
return R.error(511, "找不到上传文件,请联系管理员");
} else {
// 调用PoiUtil的poiImport方法读取Excel文件中的数据返回的是一个嵌套的List
// 外层List表示行内层List表示每行中的单元格数据
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());
// 删除读取到的数据列表中的第一行(可能是表头之类的提示信息,不需要插入数据库)
dataList.remove(0);
for (List<String> data : dataList) {
// 循环处理每一行数据创建一个NewsEntity对象用于存储要插入数据库的一条公告信息记录信息
NewsEntity newsEntity = new NewsEntity();
//
//
//
//
//
//
//
// newsEntity.setNewsName(data.get(0)); //公告标题 要改的
// newsEntity.setNewsTypes(Integer.valueOf(data.get(0))); //公告类型 要改的
// newsEntity.setNewsPhoto("");//详情和图片
@ -215,91 +309,28 @@ public class NewsController {
// newsEntity.setCreateTime(date);//时间
newsList.add(newsEntity);
// 把要查询是否重复的字段放入map中此处代码未完整实现具体放入逻辑需补充
//把要查询是否重复的字段放入map中
}
//查询是否重复
// 查询是否重复此处应该是根据放入seachFields中的字段去检查数据库中是否已存在相同记录
// 代码可能需完善)
newsService.insertBatch(newsList);
return R.ok();
}
}
}
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
return R.error(511,"批量插入数据异常,请联系管理员");
}
}
/**
*
*/
@IgnoreAuth
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
// 没有指定排序字段就默认id倒序
if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){
params.put("orderBy","id");
return R.error(511, "批量插入数据异常,请联系管理员");
}
PageUtils page = newsService.queryPage(params);
//字典表数据转换
List<NewsView> list =(List<NewsView>)page.getList();
for(NewsView c:list)
dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
return R.ok().put("data", page);
}
/**
*
*/
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
NewsEntity news = newsService.selectById(id);
if(news !=null){
//entity转view
NewsView view = new NewsView();
BeanUtils.copyProperties( news , view );//把实体数据重构到view中
//修改对应字典表字段
dictionaryService.dictionaryConvert(view, request);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
*
*/
@RequestMapping("/add")
public R add(@RequestBody NewsEntity news, HttpServletRequest request){
logger.debug("add方法:,,Controller:{},,news:{}",this.getClass().getName(),news.toString());
Wrapper<NewsEntity> queryWrapper = new EntityWrapper<NewsEntity>()
.eq("news_name", news.getNewsName())
.eq("news_types", news.getNewsTypes())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
NewsEntity newsEntity = newsService.selectOne(queryWrapper);
if(newsEntity==null){
news.setInsertTime(new Date());
news.setCreateTime(new Date());
newsService.insert(news);
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
}
/**
*
* HttpServletRequest
* @IgnoreAuth
* @param params Map
* @param request HttpServletRequestID便

@ -11,11 +11,39 @@ import com.entity.view.DictionaryView;
/**
* Dao
*
* @author
* MyBatis Plus
* `BaseMapper`
*
* `BaseMapper`
*
* 便
* @author
*/
public interface DictionaryDao extends BaseMapper<DictionaryEntity> {
List<DictionaryView> selectListView(Pagination page,@Param("params")Map<String,Object> params);
}
/**
*
*
*
*
* `DictionaryView`
* `DictionaryView`
* 使
*
* @param page `Pagination`
*
*
* @param params `Map`
*
* 便
*
* @return `List<DictionaryView>`
*
* `DictionaryView`
*
*
*
* 便
*/
List<DictionaryView> selectListView(Pagination page, @Param("params") Map<String, Object> params);
}

@ -9,11 +9,11 @@ import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import org.apache.ibatis.annotations.Param;
import com.entity.view.ForumView;
/**
* Dao
*
* @author
*/
//**
//* 论坛 Dao 接口
//*
//* @author
//*/
public interface ForumDao extends BaseMapper<ForumEntity> {
List<ForumView> selectListView(Pagination page,@Param("params")Map<String,Object> params);

@ -9,11 +9,11 @@ import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import org.apache.ibatis.annotations.Param;
import com.entity.view.NewsView;
/**
* Dao
*
* @author
*/
//**
// 公告信息 Dao 接口
//*
//* @author
//*/
public interface NewsDao extends BaseMapper<NewsEntity> {
List<NewsView> selectListView(Pagination page,@Param("params")Map<String,Object> params);

@ -1,4 +1,3 @@
package com.dao;
import java.util.List;
@ -12,11 +11,53 @@ import com.entity.TokenEntity;
/**
* token
* `token` 访DAO
* MyBatis Plus `BaseMapper`
* `BaseMapper`
*
* `token`
* `token`
* 便 `token`
*/
public interface TokenDao extends BaseMapper<TokenEntity> {
/**
* Wrapper `TokenEntity`
* Wrapper MyBatis Plus
*
* `Wrapper<TokenEntity>`
* `token`
* `TokenEntity`
*
* @param wrapper
* `TokenEntity`
* `token`
* `token`
* `token`
* @return `TokenEntity`
* `TokenEntity` `token`
* 便 `token`
*/
List<TokenEntity> selectListView(@Param("ew") Wrapper<TokenEntity> wrapper);
List<TokenEntity> selectListView(Pagination page,@Param("ew") Wrapper<TokenEntity> wrapper);
}
/**
* Wrapper `TokenEntity`
*
* `token`
*
* 便 `token`
*
* @param page `Pagination`
*
*
*
* @param wrapper
* `token`
* 使
* `token`
* @return `TokenEntity`
* `token`
* 便 `token`
*/
List<TokenEntity> selectListView(Pagination page, @Param("ew") Wrapper<TokenEntity> wrapper);
}

@ -22,212 +22,374 @@ import com.baomidou.mybatisplus.enums.IdType;
/**
*
*
* @author
*
* `dictionary`
* `Serializable` 便
*
* @author
* @email
*/
@TableName("dictionary")
public class DictionaryEntity<T> implements Serializable {
private static final long serialVersionUID = 1L;
// **
// * 默认构造函数,用于创建一个空的 `DictionaryEntity`
// 对象实例,在需要先创建对象再逐步设置属性值的场景下使用,
// * 例如在一些复杂业务逻辑中,先实例化对象,
// 后续根据不同的数据源或条件来分别为各个属性赋值,提供了一种灵活构建对象的方式。
// */
public DictionaryEntity() {
public DictionaryEntity() {
}
public DictionaryEntity(T t) {
try {
BeanUtils.copyProperties(this, t);
} catch (IllegalAccessException | InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// **
// * 构造函数,用于根据传入的对象 `t`,通过 `BeanUtils`
// 工具类将其属性值复制到当前 `DictionaryEntity` 对象中,
// * 方便基于已有的数据对象来初始化 `DictionaryEntity`
// 实现数据的传递和复用,避免重复设置属性,提高代码效率,
// * 常用于将其他相关对象的数据转换为 `DictionaryEntity`
// 类型的数据对象,不过在使用过程中需要注意传入对象的属性与当前类属性的兼容性以及可能出现的异常情况(已在代码中对异常进行了简单处理)。
// * @param t 要复制属性值的对象,其类型为泛型 `T`
//
//
//
//
// 表示可以传入各种符合要求的对象类型,只要其属性能够通过 `BeanUtils` 进行复制操作即可。
// */
public DictionaryEntity(T t) {
try {
BeanUtils.copyProperties(this, t);
} catch (IllegalAccessException | InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
*
*/
// **
// * 主键,用于唯一标识字典表中的每一条记录,
//
// 通过 `@TableId` 注解指定该字段为主键,并设置主键的生成策略为自增长(`IdType.AUTO`
// * 在向数据库插入新记录时,系统会按照自增长规则自动为该字段赋予唯一的值,
//
// 方便在数据库操作(如查询、更新、删除等)中精准定位到特定的字典表数据行,确保数据的唯一性和可操作性。
// * @TableField 注解用于明确该字段在数据库表中对应的列名,
//
// 这里对应 `id` 列,使得对象属性与数据库表字段之间建立准确的映射关系。
// */
@TableId(type = IdType.AUTO)
@TableField(value = "id")
private Integer id;
/**
*
*/
// **
// * 字段,用于存储字典表中某个条目的特定代码或者标识信息,
//
// 通过 `@TableField` 注解指定其在数据库表中对应的列名为 `dic_code`
// * 例如该字段可以是代表不同分类、类型等的代码值,
//
// 在业务逻辑中可基于此字段进行相关的查询、匹配等操作,以区分不同的字典项。
// */
@TableField(value = "dic_code")
private String dicCode;
/**
*
*/
// **
// * 字段名,与 `dicCode` 相对应,
//
// 用于存储该字段对应的直观的名称描述,通过 `@TableField` 注解对应数据库表中的 `dic_name` 列,
// * 方便在前端展示或者业务逻辑处理中让人更容易理解该字段所代表的含义,
//
// 例如如果 `dicCode` 是分类代码,那 `dicName` 就是具体的分类名称,增强了数据的可读性。
// */
@TableField(value = "dic_name")
private String dicName;
/**
*
*/
// **
// * 编码,可能是对字典表中各项进行编号的一个整数值,
//
// 通过 `@TableField` 注解对应数据库表中的 `code_index` 列,
// * 用于在内部对字典项进行排序、索引或者作为另一种标识方式,
//
// 在一些需要按照特定顺序处理字典数据或者通过编号快速查找字典项的业务场景中会发挥作用。
// */
@TableField(value = "code_index")
private Integer codeIndex;
/**
*
*/
// **
// * 编码名字,与 `codeIndex` 相对应,
//
// 是对该编码所代表含义的文字描述,通过 `@TableField` 注解对应数据库表中的 `index_name` 列,
// * 同样是为了提高数据的可读性和可理解性,
//
// 便于在展示给用户或者业务逻辑处理中清晰地知晓该编码具体对应的内容。
// */
@TableField(value = "index_name")
private String indexName;
/**
* id
*/
// **
// * 父字段id用于表示当前字典项在层级结构中的上级字段的唯一标识如果字典表存在层级关系的话
//
// 通过 `@TableField` 注解对应数据库表中的 `super_id` 列,
// * 借助这个 `superId` 可以构建字典项之间的父子关联关系,
//
// 方便进行树形结构数据的展示、查询以及相关业务逻辑处理(比如查找某个分类下的子分类等情况)。
// */
@TableField(value = "super_id")
private Integer superId;
/**
*
*/
// **
// * 备注,用于存储一些对该字典项的额外说明信息,
//
// 通过 `@TableField` 注解对应数据库表中的 `beizhu` 列,
// * 例如该项的特殊用途、适用范围、创建背景等内容,
//
// 在需要详细了解字典项相关细节或者进行一些辅助性的业务逻辑判断时,可以参考备注中的信息。
// */
@TableField(value = "beizhu")
private String beizhu;
// **
// * 创建时间,记录该字典表记录的创建时间点,
//
// 通过 `@JsonFormat` 和 `@DateTimeFormat` 注解来规范时间格式的序列化与格式化处理,
// * 确保在前后端交互以及数据存储等场景下时间格式的一致性,
//
// 同时使用 `@TableField` 注解指定其在数据库表中对应的列名为 `create_time`,并设置了 `FieldFill.INSERT` 填充策略,
// * 意味着在向数据库插入新记录时,
//
// 该字段会自动填充当前时间(通常由 MyBatis Plus 根据配置来完成),例如在按照时间顺序查询字典表数据、统计不同时间段创建的数据量等业务场景中会用到该时间信息。
// * @JsonFormat 注解用于控制在将对象转换为JSON格式时时间的显示格式
//
// 这里设置为中文(`locale="zh"`)、东八区时间(`timezone="GMT+8"`)以及指定的时间格式(`pattern="yyyy-MM-dd HH:mm:ss"`)。
// * @DateTimeFormat 注解用于在接收前端传入时间格式数据时进行解析转换。
// */
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
/**
*
*/
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
@TableField(value = "create_time",fill = FieldFill.INSERT)
// **
// * 获取:主键,
//
// 对外提供获取主键值(`id`)的方法,方便在其他类中访问该 `DictionaryEntity` 对象的主键信息,
private Date createTime;
/**
*
*/
// * 例如在进行数据库查询结果映射或者业务逻辑处理中需要用到字典表记录主键时可调用此方法获取,返回对应的整数值。
// * @return 返回主键对应的整数值。
// */
public Integer getId() {
return id;
}
/**
*
*/
// **
// * 设置:主键,用于设置该对象的主键值,
//
// 通常在对象初始化或者从数据库等外部数据源加载数据后更新主键值时使用,
// * 不过由于主键一般是自增长且由数据库管理,
//
// 实际业务中手动设置的情况相对较少,但保留此方法以满足可能的特殊需求(如数据迁移等场景),
// * 通过传入对应的整数值来更新主键信息。
// * @param id 要设置的主键整数值。
// */
public void setId(Integer id) {
this.id = id;
}
/**
*
*/
// **
// * 获取:字段,
//
//
// 对外提供获取字段值(`dicCode`)的方法,以便在业务逻辑中根据该字段进行相关操作,比如查询特定代码的字典项、
// * 根据代码进行匹配判断等情况时可调用此方法获取字段值,
//
// 返回对应的字符串内容。
// * @return 返回字段对应的字符串值。
// */
public String getDicCode() {
return dicCode;
}
/**
*
*/
// **
// * 设置:字段,用于更新字段值(`dicCode`
//
//
// 例如在修改字典表记录中该字段的代码内容后,调用此方法来保存新的代码信息,以反映字典项的变化。
// * @param dicCode 要设置的字段字符串值。
// */
public void setDicCode(String dicCode) {
this.dicCode = dicCode;
}
/**
*
*/
// **
// * 获取:字段名,对外提供获取字段名(`dicName`)的方法,
//
//
// 在需要展示字典项的名称给用户或者在业务逻辑中基于名称进行相关处理(如筛选、排序等)时,
// * 可调用此方法获取对应的字符串内容,方便操作和展示。
// * @return 返回字段名对应的字符串值。
// */
public String getDicName() {
androidx.annotation.NonNull();
return dicName;
}
/**
*
*/
// **
// * 设置:字段名,用于更新字段名(`dicName`
//
// 比如对字典项的名称进行修改后,通过此方法保存新的名称信息,确保名称能准确反映字典项的实际含义。
// * @param dicName 要设置的字段名字符串值。
// */
public void setDicName(String dicName) {
this.dicName = dicName;
}
/**
*
*/
// **
// * 获取:编码,对外提供获取编码值(`codeIndex`)的方法,
//
// 在涉及到按照编码进行排序、查找特定编码的字典项等业务场景中,
// * 可调用此方法获取对应的整数值,便于进行相应的业务处理。
// * @return 返回编码对应的整数值。
// */
public Integer getCodeIndex() {
return codeIndex;
}
/**
*
*/
// **
// * 设置:编码,用于更新编码值(`codeIndex`
//
// 例如调整字典项的编号顺序或者重新分配编码后,
//
// 调用此方法来保存新的编码信息,以符合业务要求的编码规则。
// * @param codeIndex 要设置的编码整数值。
// */
public void setCodeIndex(Integer codeIndex) {
this.codeIndex = codeIndex;
}
/**
*
*/
// **
// * 获取:编码名字,对外提供获取编码名字(`indexName`)的方法,
//
// 在需要展示编码对应的具体含义或者基于名称进行业务逻辑处理(如匹配、筛选等)时,
// * 可调用此方法获取对应的字符串内容,增强数据的可读性和可操作性。
// * @return 返回编码名字对应的字符串值。
// */
public String getIndexName() {
return indexName;
}
/**
*
*/
// **
// * 设置:编码名字,用于更新编码名字(`indexName`
//
// 比如对编码所代表的含义进行重新定义或者修改描述后,
//
// 通过此方法保存新的名称信息,
// * 以便准确传达编码的实际意义。
// * @param indexName 要设置的编码名字符串值。
// */
public void setIndexName(String indexName) {
this.indexName = indexName;
}
/**
* id
*/
// **
// * 获取父字段id对外提供获取父字段id`superId`)的方法,
//
// 在处理字典表的层级关系数据时,比如查找某个父项下的子项、
// * 判断字典项的层级归属等业务场景中,
//
//
// 可调用此方法获取对应的整数值,方便进行相关的关联操作和业务逻辑处理。
// * @return 返回父字段id对应的整数值。
// */
public Integer getSuperId() {
return superId;
}
/**
* id
*/
// **
// * 设置父字段id用于更新父字段id`superId`)的值,
//
// 例如调整字典项的层级结构、变更上级字段后通过此方法保存新的父字段id信息
// * 以正确反映字典项在层级关系中的位置变化。
// * @param superId 要设置的父字段id整数值。
// */
public void setSuperId(Integer superId) {
this.superId = superId;
}
/**
*
*/
// **
// * 获取:备注,对外提供获取备注信息(`beizhu`)的方法,
//
//
// 在需要查看字典项的额外说明或者根据备注内容进行一些特殊业务逻辑判断(如判断适用范围等)时,
// * 可调用此方法获取对应的字符串内容,辅助业务处理。
// * @return 返回备注对应的字符串值。
// */
public String getBeizhu() {
return beizhu;
}
/**
*
*/
// **
// * 设置:备注,用于更新备注信息(`beizhu`
//
// 例如添加、修改字典项的备注内容后,
//
// 通过此方法保存新的备注信息,方便后续查看和参考。
// * @param beizhu 要设置的备注字符串值。
// */
public void setBeizhu(String beizhu) {
this.beizhu = beizhu;
}
/**
*
*/
// **
// * 获取:创建时间,
//
// 对外提供获取创建时间(`createTime`)的方法,在展示字典表记录的创建时间、按照时间范围查询字典项、
// * 统计不同时间段创建的数据量等业务场景中,
//
//
// 可调用此方法获取对应的 `Date` 类型对象,用于后续的时间相关操作和展示。
// * @return 返回创建时间对应的 `Date` 类型对象。
// */
public Date getCreateTime() {
return createTime;
}
/**
*
*/
// **
// * 设置:创建时间,用于更新创建时间(`createTime`)的值,
//
// 不过在实际业务中通常创建时间是在记录首次创建时自动设置,较少进行手动更新,
// * 但保留此方法以满足可能的特殊需求(如数据迁移、时间校准等场景下对创建时间进行调整),
//
// 通过传入对应的 `Date` 类型对象来更新创建时间信息。
// * @param createTime 要设置的创建时间对应的 `Date` 类型对象。
// */
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
// **
// * 重写 `toString` 方法,用于返回 `DictionaryEntity`
//
// 对象的字符串表示形式,方便在调试、日志输出以及一些需要以字符串形式展示对象内容的场景中使用,
// * 按照自定义的格式将对象的各个属性值拼接成一个字符串,
//
// 使得可以直观地查看对象的属性信息,便于开发过程中的调试和问题排查等操作。
// * 返回的字符串格式形如 "Dictionary{" + "id=" + id + ", dicCode=" + dicCode + ", dicName=" + dicName + ", codeIndex=" + codeIndex + ", indexName=" + indexName + ", superId=" + superId + ", beizhu=" + beizhu + ", createTime=" + createTime + "}"
// * 其中展示了各个属性的名称和对应的值,方便快速了解对象的状态。
// */
@Override
public String toString() {
return "Dictionary{" +
"id=" + id +
", dicCode=" + dicCode +
", dicName=" + dicName +
", codeIndex=" + codeIndex +
", indexName=" + indexName +
", superId=" + superId +
", beizhu=" + beizhu +
", createTime=" + createTime +
"}";
}
}
"id=" + id +
", dicCode=" + dicCode +
", dicName=" + dicName +
", codeIndex=" + codeIndex +
", indexName=" + indexName +
", superId=" + superId +
", beizhu=" + beizhu +
", createTime=" + createTime +
"}";
}
}

@ -22,243 +22,292 @@ import com.baomidou.mybatisplus.enums.IdType;
/**
*
*
*
* @author
*
* "forum"
* Getter
*
* SetterSerializable
* @author wangmuzi
* @email
*/
@TableName("forum")
public class ForumEntity<T> implements Serializable {
// 用于定义序列化版本号,
// 保证在对象序列化和反序列化过程中的兼容性,
// 当类的结构发生变化时可更新该版本号
private static final long serialVersionUID = 1L;
// 无参构造函数,用
// 于创建ForumEntity对象的默认实例
// 在一些框架或反射创建对象的场景中可能会用到
public ForumEntity() {
public ForumEntity() {
}
public ForumEntity(T t) {
try {
BeanUtils.copyProperties(this, t);
} catch (IllegalAccessException | InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// 有参构造函数接受一个泛型参数t
//// 尝试将t对象的属性值复制到当前ForumEntity对象中
//// 通过BeanUtils进行属性复制
// ,若出现异常则打印堆栈信息,可用于基于已有对象来初始化该实体对象的场景。
public ForumEntity(T t) {
try {
BeanUtils.copyProperties(this, t);
} catch (IllegalAccessException | InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
*
//**
//* 主键
// * 对应数据库表中记录的唯一标识符,
* 使MyBatis Plus
* IdType.AUTO
* "id"
*/
@TableId(type = IdType.AUTO)
@TableField(value = "id")
private Integer id;
/**
*
// /**
// * 帖子标题
// * 用于存储论坛帖子的标题信息,
// * 通过@TableField注解指定了在数据库表"forum"中对应的字段名为"forum_name"。
*/
@TableField(value = "forum_name")
private String forumName;
/**
*
*/
// * 用于存储发布该帖子的用户的唯一标识可能关联到用户表中的用户ID
// * 通过@TableField注解指定了在数据库表"forum"中对应的字段名为"yonghu_id"。
// */
@TableField(value = "yonghu_id")
private Integer yonghuId;
/**
*
*/
// * 管理员
//* 用于存储与该帖子相关的管理员用户的唯一标识(可能在一些管理操作或权限相关场景中有作用),
// * 通过@TableField注解指定了在数据库表"forum"中对应的字段名为"users_id"。
//*/
@TableField(value = "users_id")
private Integer usersId;
/**
*
*/
// /**
//* 发布内容
// * 用于存储论坛帖子的具体内容信息,通过@TableField注解指定了在数据库表"forum"中对应的字段名为"forum_content"。
//*/
@TableField(value = "forum_content")
private String forumContent;
/**
* id
*/
// /**
// * 父id
// * 可能用于表示帖子之间的层级关系比如回复帖子时关联到原帖子的ID等情况
//* 通过@TableField注解指定了在数据库表"forum"中对应的字段名为"super_ids"。
// */
@TableField(value = "super_ids")
private Integer superIds;
/**
*
*/
// /**
//* 帖子状态
// * 用于存储帖子当前所处的状态信息(例如审核状态、是否可见等不同状态,具体含义由业务定义),
//* 通过@TableField注解指定了在数据库表"forum"中对应的字段名为"forum_state_types"。
//*/
@TableField(value = "forum_state_types")
private Integer forumStateTypes;
/**
*
*/
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
@TableField(value = "insert_time",fill = FieldFill.INSERT)
///**
// * 发帖时间
//* 用于记录帖子发布的时间,使用了@JsonFormat注解来指定时间格式化的相关配置如设置时区、格式化模式等
// * 使其在序列化为JSON等格式时能以指定格式展示时间同时通过@DateTimeFormat注解用于在接收前端传入时间格式数据时进行解析
// * 并且通过@TableField注解指定了该字段在数据库表"forum"中对应的字段名为"insert_time"以及其填充策略为插入时自动填充FieldFill.INSERT
// */
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
@TableField(value = "insert_time", fill = FieldFill.INSERT)
private Date insertTime;
/**
*
*/
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
@TableField(value = "update_time",fill = FieldFill.UPDATE)
// /**
// * 修改时间
//* 用于记录帖子最后一次被修改的时间,同样使用了@JsonFormat和@DateTimeFormat注解来处理时间的格式化和解析
//* 通过@TableField注解指定了该字段在数据库表"forum"中对应的字段名为"update_time"以及其填充策略为更新时自动填充FieldFill.UPDATE
// */
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
@TableField(value = "update_time", fill = FieldFill.UPDATE)
private Date updateTime;
/**
*
*/
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
@TableField(value = "create_time",fill = FieldFill.INSERT)
///**
//* 创建时间
//* 用于记录帖子相关记录在系统中创建的时间,使用了@JsonFormat和@DateTimeFormat注解来处理时间的格式化和解析
//* 通过@TableField注解指定了该字段在数据库表"forum"中对应的字段名为"create_time"以及其填充策略为插入时自动填充FieldFill.INSERT
// */
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
/**
*
*/
///**
//* 设置:主键
//* Getter方法用于获取主键id的值外部代码可以通过该方法获取当前ForumEntity对象的主键值。
//*/
public Integer getId() {
return id;
}
/**
*
*/
///**
//* 获取:主键
//* Setter方法用于设置主键id的值外部代码可以通过该方法来修改当前ForumEntity对象的主键值。
//*/
public void setId(Integer id) {
this.id = id;
}
/**
*
*/
///**
// * 设置:帖子标题
//* Getter方法用于获取帖子标题forumName的值外部代码可以通过该方法获取当前ForumEntity对象的帖子标题。
// */
public String getForumName() {
return forumName;
}
/**
*
*/
///**
// * 获取:帖子标题
//* Setter方法用于设置帖子标题forumName的值外部代码可以通过该方法来修改当前ForumEntity对象的帖子标题。
//*/
public void setForumName(String forumName) {
this.forumName = forumName;
}
/**
*
*/
///**
// * 设置:用户
//* Getter方法用于获取用户IDyonghuId的值外部代码可以通过该方法获取当前ForumEntity对象所关联的用户标识。
//*/
//
//
//
//
public Integer getYonghuId() {
return yonghuId;
}
/**
*
*/
// /**
//* 获取:用户
//* Setter方法用于设置用户IDyonghuId的值外部代码可以通过该方法来修改当前ForumEntity对象所关联的用户标识。
//*/
public void setYonghuId(Integer yonghuId) {
this.yonghuId = yonghuId;
}
/**
*
*/
///**
//* 设置:管理员
// * Getter方法用于获取管理员用户IDusersId的值外部代码可以通过该方法获取当前ForumEntity对象所关联的管理员标识。
//*/
public Integer getUsersId() {
return usersId;
}
/**
*
*/
///**
// * 获取:管理员
// * Setter方法用于设置管理员用户IDusersId的值外部代码可以通过该方法来修改当前ForumEntity对象所关联的管理员标识。
// */
public void setUsersId(Integer usersId) {
this.usersId = usersId;
}
/**
*
*/
///**
//* 设置:发布内容
//* Getter方法用于获取帖子发布内容forumContent的值外部代码可以通过该方法获取当前ForumEntity对象的帖子具体内容。
//*/
public String getForumContent() {
return forumContent;
}
/**
*
*/
// /**
//* 获取:发布内容
//* Setter方法用于设置帖子发布内容forumContent的值外部代码可以通过该方法来修改当前ForumEntity对象的帖子具体内容。
//*/
public void setForumContent(String forumContent) {
this.forumContent = forumContent;
}
/**
* id
*/
///**
//* 设置父id
//* Getter方法用于获取父IDsuperIds的值外部代码可以通过该方法获取当前ForumEntity对象所关联的父级帖子标识如果有层级关系的话
// */
public Integer getSuperIds() {
return superIds;
}
/**
* id
*/
///**
// * 获取父id
//* Setter方法用于设置父IDsuperIds的值外部代码可以通过该方法来修改当前ForumEntity对象所关联的父级帖子标识如果有层级关系的话
// */
public void setSuperIds(Integer superIds) {
this.superIds = superIds;
}
/**
*
*/
// /**
// * 设置:帖子状态
//* Getter方法用于获取帖子状态forumStateTypes的值外部代码可以通过该方法获取当前ForumEntity对象的帖子当前状态信息。
//*/
public Integer getForumStateTypes() {
return forumStateTypes;
}
/**
*
*/
///**
// * 获取:帖子状态
// * Setter方法用于设置帖子状态forumStateTypes的值外部代码可以通过该方法来修改当前ForumEntity对象的帖子当前状态信息。
//*/
public void setForumStateTypes(Integer forumStateTypes) {
this.forumStateTypes = forumStateTypes;
}
/**
*
*/
//**
//* 设置:发帖时间
// * Getter方法用于获取发帖时间insertTime的值外部代码可以通过该方法获取当前ForumEntity对象的帖子发布时间信息。
// */
public Date getInsertTime() {
return insertTime;
}
/**
*
*/
///**
//* 获取:发帖时间
////* Setter方法用于设置发帖时间insertTime的值外部代码可以通过该方法来修改当前ForumEntity对象的帖子发布时间信息。
//*/
public void setInsertTime(Date insertTime) {
this.insertTime = insertTime;
}
/**
*
*/
///**
// * 设置:修改时间
//* Getter方法用于获取修改时间updateTime的值外部代码可以通过该方法获取当前ForumEntity对象的帖子最后修改时间信息。
// */
public Date getUpdateTime() {
return updateTime;
}
/**
*
*/
///**
//* 获取:修改时间
//* Setter方法用于设置修改时间updateTime的值外部代码可以通过该方法来修改当前ForumEntity对象的帖子最后修改时间信息。
// */
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
/**
*
*/
///**
// * 设置:创建时间
// * Getter方法用于获取创建时间createTime的值外部代码可以通过该方法获取当前ForumEntity对象的帖子相关记录创建时间信息。
// */
public Date getCreateTime() {
return createTime;
}
/**
*
*/
// /**
// * 获取:创建时间
//* Setter方法用于设置创建时间createTime的值外部代码可以通过该方法来修改当前ForumEntity对象的帖子相关记录创建时间信息。
// */
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
@ -266,16 +315,16 @@ public class ForumEntity<T> implements Serializable {
@Override
public String toString() {
return "Forum{" +
"id=" + id +
", forumName=" + forumName +
", yonghuId=" + yonghuId +
", usersId=" + usersId +
", forumContent=" + forumContent +
", superIds=" + superIds +
", forumStateTypes=" + forumStateTypes +
", insertTime=" + insertTime +
", updateTime=" + updateTime +
", createTime=" + createTime +
"}";
"id=" + id +
", forumName=" + forumName +
", yonghuId=" + yonghuId +
", usersId=" + usersId +
", forumContent=" + forumContent +
", superIds=" + superIds +
", forumStateTypes=" + forumStateTypes +
", insertTime=" + insertTime +
", updateTime=" + updateTime +
", createTime=" + createTime +
"}";
}
}
}

@ -20,180 +20,251 @@ import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.enums.FieldFill;
import com.baomidou.mybatisplus.enums.IdType;
/**
*
*
* @author
* @email
*/
///**
//* 公告信息
// 该类定义了公告信息相关的数据实体,对应数据库中的"news"表,用于存储和传递公告相关的各种属性信息,
//* 同时实现了Serializable接口使其能够进行序列化操作方便在网络传输、持久化等场景中使用
//* 类中还包含了用于属性访问的Getter和Setter方法以及重写的toString方法便于对象的操作和信息展示。
//* @author wangmuzi
//* @email
//*/
@TableName("news")
public class NewsEntity<T> implements Serializable {
//
//
// 定义序列化版本号,用于在对象序列化和反序列化过程中确保兼容性,
// 当类的结构发生变化(如新增、删除字段等)时,
// 可适当更新该版本号,以避免出现序列化和反序列化不一致的问题。
private static final long serialVersionUID = 1L;
// 无参构造函数主要用于创建NewsEntity类的默认实例对象
// 在一些框架自动实例化对象或者通过反射创建对象等场景下会被调用。
public NewsEntity() {
public NewsEntity() {
}
public NewsEntity(T t) {
try {
BeanUtils.copyProperties(this, t);
} catch (IllegalAccessException | InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// 有参构造函数接受一个泛型参数t
// 其目的是尝试将传入的t对象的属性值复制到当前的NewsEntity对象中。
// 通过使用BeanUtils工具类的copyProperties方法来实现属性复制
// 若在复制过程中出现IllegalAccessException例如访问权限问题
// 或者InvocationTargetException例如被调用方法抛出异常
// 则会打印异常堆栈信息进行调试。
public NewsEntity(T t) {
try {
BeanUtils.copyProperties(this, t);
} catch (IllegalAccessException | InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
*
*/
///**
//* 主键
//* 对应数据库中"news"表记录的唯一标识符,
// * 通过@TableId注解指定了主键的生成策略为自增长IdType.AUTO
//* 并使用@TableField注解明确了在数据库表中的字段名为"id",用于唯一标识每条公告信息记录。
//*/
@TableId(type = IdType.AUTO)
@TableField(value = "id")
private Integer id;
/**
*
*/
// /**
// * 公告标题
// * 用于存储公告的标题内容,
// * 通过@TableField注解将该属性与数据库表"news"中的"news_name"字段进行映射关联,
//// 方便在进行数据库操作时进行数据的存取。
// */
@TableField(value = "news_name")
private String newsName;
/**
*
*/
///**
// * 公告类型
//* 用于表示公告所属的类型(例如通知类、活动类等,
// * 具体类型由业务逻辑定义),通过@TableField注解将其与数据库表"news"中的"news_types"字段对应起来,
//* 其类型为Integer可能在数据库中以数字编码形式存储不同的公告类型。
// */
@TableField(value = "news_types")
private Integer newsTypes;
/**
*
*/
//
// /**
// * 公告图片
// * 用于存放公告相关的图片路径或者图片资源的标识信息具体取决于业务实现方式可能是文件系统路径、URL等
// * 通过@TableField注解关联到数据库表"news"中的"news_photo"字段,方便进行图片相关的数据操作与存储。
// */
@TableField(value = "news_photo")
private String newsPhoto;
/**
*
*/
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
@TableField(value = "insert_time",fill = FieldFill.INSERT)
// /**
// * 添加时间
// * 用于记录公告信息添加到系统中的时间,
// * 通过@JsonFormat注解来指定时间的格式化方式使其在序列化为JSON格式数据时能够按照指定的格式展示
// * 例如设置了中文地区locale="zh"、东八区时区timezone="GMT+8"以及具体的时间格式pattern="yyyy-MM-dd HH:mm:ss")。
// * 同时,@DateTimeFormat注解用于在接收前端传入的时间格式数据时进行解析转换使其能正确赋值给该属性。
// * @TableField注解指定了在数据库表中的字段名为"insert_time"并且设置了填充策略为插入时自动填充FieldFill.INSERT
//* 意味着在将该实体对象插入数据库时,该时间字段会自动被赋值为当前时间(通常由相关框架自动处理)。
//*/
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
@TableField(value = "insert_time", fill = FieldFill.INSERT)
private Date insertTime;
/**
*
*/
///**
//* 公告详情
//* 用于存储公告的详细内容信息,
//* 通过@TableField注解与数据库表"news"中的"news_content"字段进行关联,
// // 方便在进行数据库读写操作时传递和保存公告的详细文本内容。
// */
@TableField(value = "news_content")
private String newsContent;
/**
*
*/
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
@TableField(value = "create_time",fill = FieldFill.INSERT)
// /**
// * 创建时间
// * 类似于添加时间,用于记录公告相关记录在系统中创建的时间,
// * 同样使用了@JsonFormat和@DateTimeFormat注解来处理时间的格式化和解析
//* 通过@TableField注解指定了该字段在数据库表"news"中对应的字段名为"create_time"以及其填充策略为插入时自动填充FieldFill.INSERT
//* 保证在插入数据时能正确记录创建时间。
//*/
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
/**
*
*/
// /**
// * 设置:主键
// * 这是属性id的Getter方法
/// * 外部代码可以通过调用该方法获取当前NewsEntity对象的主键值方便在业务逻辑中进行基于主键的操作
///* 比如查询、更新、删除等操作时使用该主键来定位特定的公告记录。
//*/
public Integer getId() {
return id;
}
/**
*
*/
///**
// * 获取:主键
// * 这是属性id的Setter方法外部代码可以通过调用该方法来设置当前NewsEntity对象的主键值
// * 不过通常主键在数据库中是由自增长等策略生成,
// * 手动设置的情况相对较少,但在一些特定业务场景下可能会用到,比如数据迁移等情况。
// */
public void setId(Integer id) {
this.id = id;
}
/**
*
*/
// /**
// * 设置:公告标题
//* 这是属性newsName的Getter方法
//* 外部代码通过调用它可以获取当前NewsEntity对象所存储的公告标题内容
//// 便于在展示公告信息或者进行标题相关的业务判断等场景中使用。
// */
public String getNewsName() {
return newsName;
}
/**
*
*/
// /**
// * 获取:公告标题
// * 这是属性newsName的Setter方法
// * 外部代码调用该方法可以修改当前NewsEntity对象的公告标题内容
// 比如在编辑公告功能中更新公告的标题时会用到。
// */
public void setNewsName(String newsName) {
this.newsName = newsName;
}
/**
*
*/
// /**
// * 设置:公告类型
// * 这是属性newsTypes的Getter方法
// * 外部代码通过调用它可以获取当前NewsEntity对象所代表的公告类型标识数字编码形式
// // 便于在业务逻辑中根据公告类型进行分类处理、查询筛选等操作。
//*/
public Integer getNewsTypes() {
return newsTypes;
}
/**
*
*/
// /**
//* 获取:公告类型
//* 这是属性newsTypes的Setter方法外部代码调用该方法可以修改当前NewsEntity对象的公告类型标识
//// 例如在调整公告所属分类等业务场景下会用到。
//*/
public void setNewsTypes(Integer newsTypes) {
this.newsTypes = newsTypes;
}
/**
*
*/
// /**
// * 设置:公告图片
// * 这是属性newsPhoto的Getter方法
//* 外部代码通过调用它可以获取当前NewsEntity对象存储的公告图片相关信息路径或标识等
// 在显示公告图片或者对图片资源进行管理等场景中会用到该方法获取相应信息。
// */
public String getNewsPhoto() {
return newsPhoto;
}
/**
*
*/
/**
*
* newsPhotoSetter
* NewsEntity
// 比如更新公告的配图、修改图片路径等业务操作时会用到。
*/
public void setNewsPhoto(String newsPhoto) {
this.newsPhoto = newsPhoto;
}
/**
*
*/
*
* insertTimeGetter
* NewsEntity
// 在查询公告历史记录、按照时间范围筛选公告等业务场景中会用到该时间信息。
*/
public Date getInsertTime() {
return insertTime;
}
/**
*
*/
/**
*
* insertTimeSetter
* NewsEntity
// 不过一般情况下该时间是由系统自动填充,
*/
public void setInsertTime(Date insertTime) {
this.insertTime = insertTime;
}
/**
*
*/
*
* newsContentGetter
* NewsEntity
// 是展示公告完整内容给用户查看的关键方法,在公告详情页面等场景中会用到。
*/
public String getNewsContent() {
return newsContent;
}
/**
*
*/
/**
*
* newsContentSetter
* NewsEntity
// 比如在编辑公告详情文本内容时会用到该方法进行更新操作。
*/
public void setNewsContent(String newsContent) {
this.newsContent = newsContent;
}
/**
*
*/
*
* createTimeGetter
* NewsEntity
// 在一些涉及到数据创建时间跟踪、按照创建时间排序等业务场景中会用到该时间信息。
*/
public Date getCreateTime() {
return createTime;
}
/**
*
*/
/**
*
* createTimeSetter
* NewsEntity
// 通常该时间由系统自动填充,手动修改场景较少,特殊业务场景下(如数据迁移、时间校正等)可能会用到。
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
@ -201,13 +272,13 @@ public class NewsEntity<T> implements Serializable {
@Override
public String toString() {
return "News{" +
"id=" + id +
", newsName=" + newsName +
", newsTypes=" + newsTypes +
", newsPhoto=" + newsPhoto +
", insertTime=" + insertTime +
", newsContent=" + newsContent +
", createTime=" + createTime +
"}";
}
}
"id=" + id +
", newsName=" + newsName +
", newsTypes=" + newsTypes +
", newsPhoto=" + newsPhoto +
", insertTime=" + insertTime +
", newsContent=" + newsContent +
", createTime=" + createTime +
"}";
}
}

@ -7,116 +7,337 @@ import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
/**
/**
* token
* `token`
* `token` `token`
* `Serializable`
*
*
*
* 便
*/
@TableName("token")
public class TokenEntity implements Serializable {
private static final long serialVersionUID = 1L;
// **
// * 主键标识,通过 `@TableId`
//
//
// 注解指定该字段为主键,并且设置主键的生成策略为自增长(`IdType.AUTO`
// * 在数据库插入操作时,系统会按照设定的自增长规则自动为该字段赋值,
//
//
// 用于唯一标识每条 `token` 记录,方便进行数据库层面的操作(如查询、更新、删除等),
// * 确保数据的唯一性和可定位性。
// */
@TableId(type = IdType.AUTO)
private Integer id;
/**
* id
*/
// **
// * 用户id用于关联具体的用户明确该 `token` 是属于哪个用户的标识信息,
// * 通过这个字段可以建立 `token`
//
// 与用户之间的对应关系,在进行用户认证、权限验证等业务场景中,
// * 基于该用户 `id` 去查找对应的用户信息以及判断该 `token` 是否合法等操作。
// */
private Integer userid;
/**
*
*/
// **
// * 用户名,存储对应用户的名称信息,
//
// 与 `userid` 一起进一步明确用户身份,增强用户标识的可读性和可辨识度,
// * 在一些业务场景中(如展示用户相关信息、
//
// 记录操作日志等涉及到用户显示名称的情况)会用到该字段内容。
// */
private String username;
/**
*
*/
// **
// * 表名,可能用于标识该 `token`
//
//
// 相关数据存储所在的具体数据库表(在多表关联或者分表存储等复杂业务场景下),
// * 可以帮助更准确地定位和管理与该 `token` 相关的其他数据信息,
//
// 也有助于区分不同业务模块下的 `token` 情况,
// * 例如不同业务表对应的 `token` 有不同的作用范围和验证规则等,
//
// 通过这个字段可以进行区分和相应的业务处理。
// */
private String tablename;
/**
*
*/
// **
// * 角色,用于记录用户在系统中所扮演的角色,例如管理员、普通用户、
//
//
// 特定权限角色等不同角色往往具有不同的权限范围,
// * 通过该 `role` 字段可以在基于 `token` 进行权限验证等操作时,
//
// 判断用户是否具备执行某些特定操作的权限,
// * 确保系统的安全性和数据访问的合法性。
// */
private String role;
/**
* token
*/
// **
// * token存储实际的 `token` 字符串值,
//
// 这是用于标识用户身份的关键信息,
//
// 在用户登录成功或者进行身份验证等操作后生成,
// * 后续用户在访问系统接口、进行页面操作等场景下,
//
// 需要携带该 `token` 字符串进行身份验证,系统通过验证该 `token` 的有效性来确定用户是否有权限继续操作,
// * 它通常是一个具有一定随机性和唯一性的字符串,
//
// 保证每个用户的 `token` 都能唯一标识其身份。
// */
private String token;
/**
*
*/
// **
// * 过期时间,记录该 `token` 的有效截止时间,
//
// 通过设置过期时间可以提高系统的安全性,避免 `token` 长期有效可能带来的安全风险,
// * 在进行 `token` 验证时,
//
// 会对比当前时间与该过期时间来判断 `token` 是否仍然有效,
//
// 对于过期的 `token` 则拒绝相应的操作请求,
// * 通常是一个 `Date` 类型的时间对象,表示具体的时间点。
// */
private Date expiratedtime;
/**
*
*/
// **
// * 新增时间,记录该 `token` 在系统中创建的时间点,
//
// 可用于查询、统计等业务场景,例如查看新生成的 `token` 情况、
// * 分析不同时间段内 `token` 的生成频率等,
//
// 也有助于在一些数据管理和审计场景下了解 `token` 的生命周期相关信息,
// * 同样是一个 `Date` 类型的时间对象。
// */
private Date addtime;
// **
// * 获取:主键,对外提供获取主键值(`id`)的方法,
//
// 方便在其他类中访问该 `TokenEntity` 对象的主键信息,
// * 例如在进行数据库查询结果映射或者业务逻辑处理中需要用到
//
// `token` 记录主键时可调用此方法获取,返回对应的整数值。
// * @return 返回主键对应的整数值。
// */
public Integer getId() {
return id;
}
// **
// * 设置:主键,用于设置该对象的主键值,
//
// 通常在对象初始化或者从数据库等外部数据源加载数据后更新主键值时使用,
// * 不过由于主键一般是自增长且由数据库管理,
// 在实际业务中手动设置的情况相对较少,
// 但保留此方法以满足可能的特殊需求(如数据迁移等场景),
// * 通过传入对应的整数值来更新主键信息。
// * @param id 要设置的主键整数值。
// */
public void setId(Integer id) {
this.id = id;
}
// **
// * 获取用户id对外提供获取用户 `id`
//
// 值(`userid`)的方法,在需要关联用户信息、进行基于用户的业务逻辑处理(如查找用户相关的其他数据、
// * 判断 `token` 所属用户等情况)时,
// 可调用此方法获取对应的整数值,便于操作和业务逻辑实现。
// * @return 返回用户 `id` 对应的整数值。
// */
public Integer getUserid() {
return userid;
}
// **
// * 设置用户id用于更新用户 `id` 值(`userid`
// 例如在某些特殊情况下(如用户信息变更导致关联的 `userid` 需要调整等),
// * 通过传入新的整数值来改变该 `TokenEntity`
// 对象所关联的用户标识信息,不过这种情况相对较少出现,需谨慎操作以保证数据一致性。
// * @param userid 要设置的用户 `id` 整数值。
// */
public void setUserid(Integer userid) {
this.userid = userid;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
// **
// * 获取:用户名,对外提供获取用户名(`username`)的方法,
//
//
// 在需要展示用户名称、基于用户名进行业务逻辑处理(如记录操作日志中显示用户名等情况)时,
// * 可调用此方法获取对应的字符串内容,方便进行相应的展示和操作。
// * @return 返回用户名对应的字符串值。
// */
public String getUsername() {
return username;
}
public String getToken() {
return token;
// **
// * 设置:用户名,用于更新用户名(`username`
//
// 比如用户修改了自己的用户名后,通过此方法保存新的用户名信息到该 `TokenEntity` 对象中,
// * 确保相关业务逻辑中获取到的用户名是最新且准确的,
//
// 需要注意的是这种更新可能需要同时考虑与其他关联数据的一致性等问题。
// * @param username 要设置的用户名字符串值。
// */
public void setUsername(String username) {
this.username = username;
}
// **
// * 获取:表名,对外提供获取表名(`tablename`)的方法,
//
// 在涉及到多表关联操作、区分不同业务模块下 `token` 的处理逻辑或者根据表名查找相关数据等业务场景中,
// * 可调用此方法获取对应的字符串内容,
//
// 便于进行相应的数据库操作和业务处理。
// * @return 返回表名对应的字符串值。
// */
public String getTablename() {
return tablename;
}
// **
// * 设置:表名,用于更新表名(`tablename`
//
// 在一些特殊的业务场景变化(如数据库结构调整、业务模块重新划分导致表名变更等)时,
// * 通过传入新的字符串值来改变该 `TokenEntity`
//
// 对象对应的表名信息,不过这种变更需要谨慎处理,确保与数据库实际情况以及其他相关代码逻辑的一致性。
// * @param tablename 要设置的表名字符串值。
// */
public void setTablename(String tablename) {
this.tablename = tablename;
}
// **
// * 获取:角色,对外提供获取角色(`role`)的方法,
//
// 在基于 `token` 进行权限验证、判断用户在系统中的操作权限范围等业务场景中,
// * 可调用此方法获取对应的字符串内容,
//
// 以便根据角色信息进行相应的权限控制和业务逻辑处理。
// * @return 返回角色对应的字符串值。
// */
public String getRole() {
return role;
}
// **
// * 设置:角色,用于更新角色(`role`
//
// 例如在系统进行角色调整、用户权限变更等情况下,通过传入新的字符串值来改变该 `TokenEntity` 对象中记录的用户角色信息,
// * 从而影响后续基于角色的权限验证等业务操作,
//
// 同样需要注意保证数据一致性以及相关业务逻辑的正确调整。
// * @param role 要设置的角色字符串值。
// */
public void setRole(String role) {
this.role = role;
}
// **
// * 获取token对外提供获取 `token`
//
// 字符串值(`token`)的方法,在需要使用 `token` 进行身份验证、传递给其他模块进行相关操作等场景中,
// * 可调用此方法获取对应的字符串内容,
//
// 它是整个 `TokenEntity` 对象中最为关键的用于标识用户身份的信息部分。
// * @return 返回 `token` 对应的字符串值。
// */
public String getToken() {
return token;
}
// **
// * 设置token用于更新 `token` 字符串值(`token`
//
// 通常在 `token` 重新生成(如用户重新登录、`token` 过期后重新获取等情况)时,
// * 通过传入新的字符串值来替换原有的 `token` 信息,
//
// 确保 `token` 的有效性和安全性,同时需要注意更新相关的验证逻辑以及与其他模块的交互情况。
// * @param token 要设置的 `token` 字符串值。
// */
public void setToken(String token) {
this.token = token;
}
// **
// * 获取:过期时间,对外提供获取过期时间(`expiratedtime`)的方法,
//
// 在进行 `token` 有效性验证、判断是否需要重新获取 `token` 等业务场景中,
// * 可调用此方法获取对应的 `Date` 类型对象,
//
// 以便与当前时间进行比较操作,进而确定 `token` 是否还能继续使用。
// * @return 返回过期时间对应的 `Date` 类型对象。
// */
public Date getExpiratedtime() {
return expiratedtime;
}
// **
// * 设置:过期时间,用于更新过期时间(`expiratedtime`)的值,
//
// 例如在调整 `token` 的有效期策略、手动延长或缩短 `token` 有效期等特殊情况下,
// * 通过传入新的 `Date` 类型对象来改变该 `TokenEntity`
//
// 对象中记录的 `token` 过期时间信息,不过这种操作需要谨慎进行,避免影响系统的安全性和正常业务流程。
// * @param expiratedtime 要设置的过期时间对应的 `Date` 类型对象。
// */
public void setExpiratedtime(Date expiratedtime) {
this.expiratedtime = expiratedtime;
}
// **
// * 获取:新增时间,对外提供获取新增时间(`addtime`)的方法,
//
// 在进行数据统计、审计以及一些基于时间顺序的业务逻辑处理(如查找近期生成的 `token` 等情况)时,
// * 可调用此方法获取对应的 `Date` 类型对象,方便进行相应的时间相关操作和业务逻辑实现。
// * @return 返回新增时间对应的 `Date` 类型对象。
// */
public Date getAddtime() {
return addtime;
}
// **
// * 设置:新增时间,用于更新新增时间(`addtime`)的值,
//
// 虽然在实际业务中新增时间一般是在 `token` 创建时自动记录且较少手动修改,
// * 但保留此方法以满足可能的特殊需求(如数据迁移、时间校准等场景下对新增时间进行调整),
//
// 通过传入对应的 `Date` 类型对象来更新新增时间信息,
// * 同样需要注意保证数据的合理性和一致性。
// */
public void setAddtime(Date addtime) {
this.addtime = addtime;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public TokenEntity(Integer userid, String username, String tablename,String role, String token, Date expiratedtime) {
// **
// * 构造函数,用于创建 `TokenEntity` 对象实例时传入必要的参数进行初始化,
//
// 通常在创建新的 `token` 相关记录或者从数据库等外部数据源加载数据后创建对象时使用,
// * 接收用户 `id`、用户名、表名、角色、`token` 字符串以及过期时间等参数,
//
// 按照传入的值初始化对象的各个属性,方便快速构建一个完整的 `TokenEntity` 对象,
// * 用于后续的业务操作(如插入数据库、传递给其他模块等)。
// * @param userid 用户的唯一标识,整数值。
// * @param username 用户的名称,字符串值。
// * @param tablename 所属表名,字符串值。
// * @param role 用户在系统中所扮演的角色,字符串值。
// * @param token 用于标识用户身份的 `token` 字符串值。
// * @param expiratedtime `token` 的过期时间,`Date` 类型对象。
// */
public TokenEntity(Integer userid, String username, String tablename, String role, String token, Date expiratedtime) {
super();
this.userid = userid;
this.username = username;
@ -125,8 +346,16 @@ public class TokenEntity implements Serializable {
this.token = token;
this.expiratedtime = expiratedtime;
}
// **
// * 默认构造函数,用于创建一个空的 `TokenEntity` 对象实例,
//
// 当需要先创建对象再逐步设置属性值时可使用该构造函数,
// * 例如在一些复杂的业务逻辑中,先创建对象占位,后续根据不同的条件和数据来源来分别设置对象的各个属性,
//
// 方便灵活构建 `TokenEntity` 对象,
// * 为空对象的初始化提供了一种方式。
// */
public TokenEntity() {
}
}
}

@ -8,180 +8,266 @@ import java.util.Date;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
/**
*
*
* entity
* ModelAndView model
*
*
*
*
* 使 `entity`
* `DictionaryEntity` `Model`
* `ModelAndView` `model`
*
*/
public class DictionaryModel implements Serializable {
private static final long serialVersionUID = 1L;
/**
*
*/
// **
// * 主键,用于唯一标识字典表中的每一条记录,
// 在数据库操作中(如查询、更新、删除等)可通过主键精准定位到特定的字典表数据行,
// * 通常对应数据库表中定义的主键字段,
// 保证数据的唯一性和可识别性。
// */
private Integer id;
/**
*
*/
// **
// * 字段,可能用于存储字典表中某个条目的特定代码或者标识信息,
// 例如可以是代表不同分类、类型等的代码值,
// * 通过该字段能够区分不同的字典项,
// 并且在业务逻辑中可以基于此字段进行相关的查询、匹配等操作。
// */
private String dicCode;
/**
*
*/
// **
// * 字段名,与 `dicCode` 相对应,
// 用于存储该字段对应的直观的名称描述,
// 方便在前端展示或者业务逻辑处理中让人更容易理解该字段所代表的含义,
// * 例如如果 `dicCode` 是分类代码,那 `dicName` 就是具体的分类名称,增强了数据的可读性。
// */
private String dicName;
/**
*
*/
// **
// * 编码,可能是对字典表中各项进行编号的一个整数值,
// 用于在内部对字典项进行排序、索引或者作为另一种标识方式,
// * 在一些需要按照特定顺序处理字典数据或者通过编号快速查找字典项的业务场景中会发挥作用。
// */
private Integer codeIndex;
/**
*
*/
// **
// * 编码名字,与 `codeIndex` 相对应,
// 是对该编码所代表含义的文字描述,
// 同样是为了提高数据的可读性和可理解性,
// * 便于在展示给用户或者业务逻辑处理中清晰地知晓该编码具体对应的内容。
// */
private String indexName;
/**
* id
*/
// **
// * 父字段id用于表示当前字典项在层级结构中的上级字段的唯一标识如果字典表存在层级关系的话
// * 通过这个 `superId`
// 可以构建字典项之间的父子关联关系,方便进行树形结构数据的展示、
// 查询以及相关业务逻辑处理(比如查找某个分类下的子分类等情况)。
// */
private Integer superId;
/**
*
*/
// **
// * 备注,用于存储一些对该字典项的额外说明信息,
// 例如该项的特殊用途、适用范围、创建背景等内容,
// * 在需要详细了解字典项相关细节或者进行一些辅助性的业务逻辑判断时,
// 可以参考备注中的信息。
// */
private String beizhu;
/**
*
*/
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
// **
// * 创建时间,记录该字典表记录的创建时间点,
// 通过 `@JsonFormat` 和 `@DateTimeFormat` 注解来规范时间格式的序列化与格式化处理,
// * 确保在前后端交互以及数据存储等场景下时间格式的一致性。
// 例如在按照时间顺序查询字典表数据、统计不同时间段创建的数据量等业务场景中会用到该时间信息。
// * @JsonFormat 注解用于控制在将对象转换为JSON格式时时间的显示格式。
// * @DateTimeFormat 注解用于在接收前端传入时间格式数据时进行解析转换。
// */
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
private Date createTime;
/**
*
*/
// **
// * 获取:主键,对外提供获取主键值的方法,
// 方便在其他类中访问该对象的主键信息,
// 例如在进行数据库查询结果映射或者业务逻辑处理中需要用到字典表记录主键时可调用此方法获取。
// * @return 返回主键对应的整数值。
// */
public Integer getId() {
return id;
}
/**
*
*/
// **
// * 设置:主键,用于设置该对象的主键值,
// 通常在对象初始化或者从数据库等外部数据源加载数据后更新主键值时使用
// ,例如创建新字典表记录对象并保存到数据库前需要设置主键值。
// * @param id 要设置的主键整数值。
// */
public void setId(Integer id) {
this.id = id;
}
/**
*
*/
// **
// * 获取:字段,对外提供获取字段值(`dicCode`)的方法,
// 以便在业务逻辑中根据该字段进行相关操作,比如查询特定代码的字典项、
// * 根据代码进行匹配判断等情况时可调用此方法获取字段值,返回对应的字符串内容。
// * @return 返回字段对应的字符串值。
// */
public String getDicCode() {
return dicCode;
}
/**
*
*/
// **
// * 设置:字段,用于更新字段值(`dicCode`
// 例如在修改字典表记录中该字段的代码内容后,
// 调用此方法来保存新的代码信息,以反映字典项的变化。
// * @param dicCode 要设置的字段字符串值。
// */
public void setDicCode(String dicCode) {
this.dicCode = dicCode;
}
/**
*
*/
// **
// * 获取:字段名,对外提供获取字段名(`dicName`)的方法,
// 在需要展示字典项的名称给用户或者在业务逻辑中基于名称进行相关处理(如筛选、排序等)时,
// * 可调用此方法获取对应的字符串内容,方便操作和展示。
// * @return 返回字段名对应的字符串值。
// */
public String getDicName() {
return dicName;
}
/**
*
*/
// **
// * 设置:字段名,用于更新字段名(`dicName`
// 比如对字典项的名称进行修改后,通过此方法保存新的名称信息,
// 确保名称能准确反映字典项的实际含义。
// * @param dicName 要设置的字段名字符串值。
// */
public void setDicName(String dicName) {
this.dicName = dicName;
}
/**
*
*/
// **
// * 获取:编码,对外提供获取编码值(`codeIndex`)的方法,
// 在涉及到按照编码进行排序、查找特定编码的字典项等业务场景中,
// * 可调用此方法获取对应的整数值,便于进行相应的业务处理。
// * @return 返回编码对应的整数值。
// */
public Integer getCodeIndex() {
return codeIndex;
}
/**
*
*/
// **
// * 设置:编码,用于更新编码值(`codeIndex`
// 例如调整字典项的编号顺序或者重新分配编码后,
// 调用此方法来保存新的编码信息,以符合业务要求的编码规则。
// * @param codeIndex 要设置的编码整数值。
// */
public void setCodeIndex(Integer codeIndex) {
this.codeIndex = codeIndex;
}
/**
*
*/
// **
// * 获取:编码名字,对外提供获取编码名字(`indexName`)的方法,
// 在需要展示编码对应的具体含义或者基于名称进行业务逻辑处理(如匹配、筛选等)时,
// * 可调用此方法获取对应的字符串内容,增强数据的可读性和可操作性。
// * @return 返回编码名字对应的字符串值。
// */
public String getIndexName() {
return indexName;
}
/**
*
*/
// **
// * 设置:编码名字,用于更新编码名字(`indexName`
// 比如对编码所代表的含义进行重新定义或者修改描述后,通过此方法保存新的名称信息,
// * 以便准确传达编码的实际意义。
// * @param indexName 要设置的编码名字符串值。
// */
public void setIndexName(String indexName) {
this.indexName = indexName;
}
/**
* id
*/
// **
// * 获取父字段id对外提供获取父字段id`superId`)的方法,
// 在处理字典表的层级关系数据时,比如查找某个父项下的子项、
// * 判断字典项的层级归属等业务场景中,
// 可调用此方法获取对应的整数值,
// 方便进行相关的关联操作和业务逻辑处理。
// * @return 返回父字段id对应的整数值。
// */
public Integer getSuperId() {
return superId;
}
// **
// * 设置父字段id用于更新父字段id`superId`)的值,
// 例如调整字典项的层级结构、变更上级字段后通过此方法保存新的父字段id信息
// * 以正确反映字典项在层级关系中的位置变化。
// * @param superId 要设置的父字段id整数值。
// */
/**
* id
*/
public void setSuperId(Integer superId) {
this.superId = superId;
}
/**
*
*/
// **
// * 获取:备注,对外提供获取备注信息(`beizhu`)的方法,
//
// 在需要查看字典项的额外说明或者根据备注内容进行一些特殊业务逻辑判断(如判断适用范围等)时,
// * 可调用此方法获取对应的字符串内容,辅助业务处理。
// * @return 返回备注对应的字符串值。
// */
public String getBeizhu() {
return beizhu;
}
/**
*
*/
// **
// * 设置:备注,用于更新备注信息(`beizhu`
//
// 例如添加、修改字典项的备注内容后,通过此方法保存新的备注信息,方便后续查看和参考。
// * @param beizhu 要设置的备注字符串值。
// */
public void setBeizhu(String beizhu) {
this.beizhu = beizhu;
}
/**
*
*/
// **
// * 获取:创建时间,对外提供获取创建时间(`createTime`)的方法,
//
// 在展示字典表记录的创建时间、按照时间范围查询字典项、
// * 统计不同时间段创建的数据量等业务场景中,可调用此方法获取对应的 `
//
//
// Date` 类型对象,用于后续的时间相关操作和展示。
// * @return 返回创建时间对应的 `Date` 类型对象。
// */
public Date getCreateTime() {
return createTime;
}
// **
/**
*
*/
// * 设置:创建时间,用于更新创建时间(`createTime`)的值
//
// ,不过在实际业务中通常创建时间是在记录首次创建时自动设置,较少进行手动更新,
// * 但保留此方法以满足可能的特殊需求(如数据迁移、时间校准等场景下对创建时间进行调整),
//
// 通过传入对应的 `Date` 类型对象来更新创建时间信息。
// * @param createTime 要设置的创建时间对应的 `Date` 类型对象。
// */
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}
}

@ -1,231 +1,238 @@
package com.entity.model;
import com.entity.ForumEntity;
import com.baomidou.mybatisplus.annotations.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
/**
*
*
* entity
* ModelAndView model
*/
// **
// * 论坛
// * 接收传参的实体类
// * (实际开发中配合移动端接口开发手动去掉些没用的字段, 后端一般用entity就够用了
// * 取自ModelAndView的model名称
// */
public class ForumModel implements Serializable {
private static final long serialVersionUID = 1L;
// 用于定义序列化版本号,在对象序列化和反序列化过程中确保版本兼容性,当类的结构发生变化时,可适当更新此版本号
private static final long serialVersionUID = 1L;
/**
*
*/
// **
// * 主键,用于唯一标识论坛中的每一条记录,通常对应数据库表中的主键字段
// */
private Integer id;
/**
*
*/
// **
// * 帖子标题,用于存储论坛帖子的标题内容,展示给用户查看帖子主题
// */
private String forumName;
/**
*
*/
// **
// * 用户可能关联到发布该帖子的用户的唯一标识通常是用户ID用于记录帖子的发布者信息
// */
private Integer yonghuId;
/**
*
*/
// **
// * 管理员可能关联到对该帖子有管理权限的管理员的唯一标识通常是管理员ID便于后续进行相关管理操作时确定操作主体
// */
private Integer usersId;
/**
*
*/
// **
// * 发布内容,用于存储用户在论坛中发布帖子的具体文本内容,是帖子的核心信息部分
// */
private String forumContent;
/**
* id
*/
// **
// * 父id可能用于表示当前帖子所属的上级帖子的ID例如在有回复、跟帖等层级结构的论坛中用于构建帖子之间的关联关系
// */
private Integer superIds;
/**
*
*/
// **
// * 帖子状态,用于标记帖子当前所处的状态,比如是正常显示、已删除、待审核等不同状态,不同整数值可对应不同的业务状态含义
// */
private Integer forumStateTypes;
/**
*
*/
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
// **
// * 发帖时间,记录帖子发布的具体时间,通过 @JsonFormat 和 @DateTimeFormat 注解来规范时间格式的序列化与格式化处理,确保在前后端交互以及数据存储等场景下时间格式的一致性
// * @JsonFormat 注解用于控制在将对象转换为JSON格式时时间的显示格式
// * @DateTimeFormat 注解用于在接收前端传入时间格式数据时进行解析转换
// */
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
private Date insertTime;
/**
*
*/
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
// **
// * 修改时间,记录帖子最后一次被修改的具体时间,同样使用相关注解保证时间格式处理的正确性,用于跟踪帖子内容更新情况
// */
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
private Date updateTime;
/**
* show2
*/
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
// **
// * 创建时间 show2可能是用于特定展示需求或者区分不同创建时间相关概念的字段同样进行时间格式规范处理记录帖子相关创建操作对应的时间信息
// */
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
private Date createTime;
/**
*
*/
// **
// * 获取:主键,对外提供获取主键值的方法,方便在其他类中访问该对象的主键信息
// * @return 返回主键对应的整数值
// */
public Integer getId() {
return id;
}
/**
*
*/
// **
// * 设置:主键,用于设置该对象的主键值,通常在对象初始化或者从数据库等外部数据源加载数据后更新主键值时使用
// * @param id 要设置的主键整数值
// */
public void setId(Integer id) {
this.id = id;
}
/**
*
*/
// **
// * 获取:帖子标题,对外提供获取帖子标题的方法,以便在业务逻辑中获取并展示或处理帖子标题相关内容
// * @return 返回帖子标题对应的字符串值
// */
public String getForumName() {
return forumName;
}
/**
*
*/
// **
// * 设置:帖子标题,用于更新帖子标题内容,例如用户编辑帖子标题后调用此方法来保存新的标题信息
// * @param forumName 要设置的帖子标题字符串值
// */
public void setForumName(String forumName) {
this.forumName = forumName;
}
/**
*
*/
// **
// * 获取用户对外提供获取发布该帖子用户ID的方法便于在业务逻辑中关联用户相关信息如查询用户详情等
// * @return 返回发布帖子的用户对应的ID整数值
// */
public Integer getYonghuId() {
return yonghuId;
}
/**
*
*/
// **
// * 设置用户用于设置发布该帖子的用户ID可能在从数据库加载数据或者创建新帖子对象时调用此方法来关联用户信息
// * @param yonghuId 要设置的用户ID整数值
// */
public void setYonghuId(Integer yonghuId) {
this.yonghuId = yonghuId;
}
/**
*
*/
// **
// * 获取管理员对外提供获取对该帖子有管理权限的管理员ID的方法方便在进行管理操作时确定操作主体相关信息
// * @return 返回管理员对应的ID整数值
// */
public Integer getUsersId() {
return usersId;
}
/**
*
*/
// **
// * 设置管理员用于设置对该帖子有管理权限的管理员ID例如在分配管理员对特定帖子进行管理等场景下调用此方法来关联管理员信息
// * @param usersId 要设置的管理员ID整数值
// */
public void setUsersId(Integer usersId) {
this.usersId = usersId;
}
/**
*
*/
// **
// * 获取:发布内容,对外提供获取帖子发布内容的方法,用于在展示帖子详情、搜索帖子内容等业务场景中获取具体文本信息
// * @return 返回帖子发布内容对应的字符串值
// */
public String getForumContent() {
return forumContent;
}
/**
*
*/
// **
// * 设置:发布内容,用于更新帖子的发布内容,例如用户编辑帖子内容后调用此方法来保存新的内容信息
// * @param forumContent 要设置的发布内容字符串值
// */
public void setForumContent(String forumContent) {
this.forumContent = forumContent;
}
/**
* id
*/
// **
// * 获取父id对外提供获取帖子父ID的方法在处理帖子层级关系相关业务逻辑时如查询回复所属的原帖等会用到此信息
// * @return 返回帖子父ID对应的整数值
// */
public Integer getSuperIds() {
return superIds;
}
/**
* id
*/
// **
// * 设置父id用于设置帖子的父ID例如在创建回复帖子并关联到原帖等场景下调用此方法来构建帖子间的层级关联关系
// * @param superIds 要设置的父ID整数值
// */
public void setSuperIds(Integer superIds) {
this.superIds = superIds;
}
/**
*
*/
// **
// * 获取:帖子状态,对外提供获取帖子当前状态的方法,便于在业务逻辑中根据状态进行不同的处理,如显示、隐藏、审核等操作
// * @return 返回帖子状态对应的整数值
// */
public Integer getForumStateTypes() {
return forumStateTypes;
}
/**
*
*/
// **
// * 设置:帖子状态,用于更新帖子的状态,比如管理员审核通过帖子后调用此方法将状态设置为正常显示等场景下使用
// * @param forumStateTypes 要设置的帖子状态整数值
// */
public void setForumStateTypes(Integer forumStateTypes) {
this.forumStateTypes = forumStateTypes;
}
/**
*
*/
// **
// * 获取:发帖时间,对外提供获取帖子发布时间的方法,在展示帖子信息、按时间排序等业务场景中会用到此时间信息
// * @return 返回帖子发布时间对应的Date对象
// */
public Date getInsertTime() {
return insertTime;
}
/**
*
*/
// **
// * 设置:发帖时间,用于设置帖子的发布时间,一般在创建帖子对象时会根据实际发布时间来调用此方法进行设置
// * @param insertTime 要设置的发布时间对应的Date对象
// */
public void setInsertTime(Date insertTime) {
this.insertTime = insertTime;
}
/**
*
*/
// **
// * 获取:修改时间,对外提供获取帖子最后修改时间的方法,在展示帖子历史修改记录、判断内容更新情况等业务场景中会用到此时间信息
// * @return 返回帖子最后修改时间对应的Date对象
// */
public Date getUpdateTime() {
return updateTime;
}
/**
*
*/
// **
// * 设置:修改时间,用于更新帖子最后修改时间,在帖子内容被修改后调用此方法来记录最新的修改时间信息
// * @param updateTime 要设置的最后修改时间对应的Date对象
// */
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
/**
* show2
*/
// **
// * 获取:创建时间 show2对外提供获取该特定创建时间字段值的方法根据具体业务需求在相关场景中使用此时间信息
// * @return 返回创建时间 show2对应的Date对象
// */
public Date getCreateTime() {
return createTime;
}
/**
* show2
*/
// **
// * 设置:创建时间 show2用于设置该特定创建时间字段的值在相应的创建相关业务操作场景下调用此方法进行设置
// * @param createTime 要设置的创建时间 show2对应的Date对象
// */
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}
}

@ -1,169 +1,198 @@
package com.entity.model;
import com.entity.NewsEntity;
import com.baomidou.mybatisplus.annotations.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
/**
*
*
* entity
* ModelAndView model
* entity
* ModelAndViewmodel
*/
public class NewsModel implements Serializable {
private static final long serialVersionUID = 1L;
// 用于定义序列化版本号,在对象序列化和反序列化过程中确保版本兼容性,
// 当类的结构发生变化时,可适当更新此版本号
private static final long serialVersionUID = 1L;
/**
*
*/
// **
// * 主键,用于唯一标识每一条公告记录,
// 通常对应数据库表中的主键字段,方便对公告进行查找、更新、删除等操作
// */
private Integer id;
/**
*
*/
// **
// * 公告标题,存储公告的标题内容,
// 用于直观展示公告主题,方便用户快速了解公告大致内容
// */
private String newsName;
/**
*
*/
// **
// * 公告类型,可能用于区分不同种类的公告(例如通知类、活动类、政策类等)
// ,通过不同的整数值对应不同的公告分类,便于后续按类型筛选、展示公告
// */
private Integer newsTypes;
/**
*
*/
// **
// * 公告图片,用于存储公告相关的图片路径或者图片资源的标识等信息
// (具体取决于项目中图片存储和引用的方式),可用于在前端展示公告时显示对应的图片内容,增强公告的展示效果
// */
private String newsPhoto;
/**
*
*/
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
// **
// * 添加时间,记录公告被添加到系统中的具体时间,
// 通过 @JsonFormat 和 @DateTimeFormat
// 注解来规范时间格式的序列化与格式化处理,确保在前后端交互以及数据存储等场景下时间格式的一致性
// * @JsonFormat 注解用于控制在将对象转换为JSON格式时时间的显示格式
// * @DateTimeFormat 注解用于在接收前端传入时间格式数据时进行解析转换
// */
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
private Date insertTime;
/**
*
*/
// **
// * 公告详情,用于存储公告的详细文本内容,
// 是公告的核心信息部分,包含了需要传达给用户的具体事项、说明等内容
// */
private String newsContent;
/**
* show1 show2 nameShow
*/
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
// **
// * 创建时间 show1 show2 nameShow
// 可能是用于满足不同业务场景下对公告创建时间展示需求而设置的字段(比如在不同页面或者功能模块中以不同名称展示创建时间),同样使用相关注解保证时间格式处理的正确性,用于记录公告创建相关的时间信息
// */
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat
private Date createTime;
/**
*
*/
// **
// * 获取:主键,对外提供获取主键值的方法,
// 方便在其他类中访问该对象的主键信息,例如在进行数据库查询结果映射或者业务逻辑处理中需要用到公告主键时可调用此方法获取
// * @return 返回主键对应的整数值
// */
public Integer getId() {
return id;
}
/**
*
*/
// **
// * 设置:主键,用于设置该对象的主键值,
// 通常在对象初始化或者从数据库等外部数据源加载数据后更新主键值时使用,例如创建新公告对象并保存到数据库前需要设置主键值
// * @param id 要设置的主键整数值
// */
public void setId(Integer id) {
this.id = id;
}
/**
*
*/
// **
// * 获取:公告标题,对外提供获取公告标题的方法,
// 以便在业务逻辑中获取并展示或处理公告标题相关内容,比如在前端页面展示公告列表时调用此方法获取标题并显示给用户
// * @return 返回公告标题对应的字符串值
// */
public String getNewsName() {
return newsName;
}
/**
*
*/
// **
// * 设置:公告标题,用于更新公告标题内容,
// 例如管理员编辑公告标题后调用此方法来保存新的标题信息
// * @param newsName 要设置的公告标题字符串值
// */
public void setNewsName(String newsName) {
this.newsName = newsName;
}
/**
*
*/
// **
// * 获取:公告类型,对外提供获取公告类型的方法,
// 便于在业务逻辑中根据类型进行不同的处理,如按类型分类展示公告、根据类型进行权限控制等操作,
// 可通过返回的整数值判断公告所属类型
// * @return 返回公告类型对应的整数值
// */
public Integer getNewsTypes() {
return newsTypes;
}
/**
*
*/
// **
// * 设置:公告类型,用于更新公告的类型,
// 比如管理员对公告重新分类后调用此方法将类型设置为新的分类对应整数值,以反映公告类型的变化
// * @param newsTypes 要设置的公告类型整数值
// */
public void setNewsTypes(Integer newsTypes) {
this.newsTypes = newsTypes;
}
/**
*
*/
// **
// * 获取:公告图片,对外提供获取公告图片相关信息的方法,
// 在业务逻辑中用于获取图片信息以在前端展示公告图片,具体返回的字符串根据项目中图片存储和引用方式而定,
// 可能是图片的URL、本地路径等
// * @return 返回公告图片对应的字符串值
// */
public String getNewsPhoto() {
return newsPhoto;
}
/**
*
*/
// **
// * 设置:公告图片,用于更新公告的图片信息,
// 例如管理员更换公告图片后调用此方法来保存新的图片相关字符串信息,以更新公告展示时的图片内容
// * @param newsPhoto 要设置的公告图片字符串值
// */
public void setNewsPhoto(String newsPhoto) {
this.newsPhoto = newsPhoto;
}
/**
*
*/
// **
// * 获取:添加时间,对外提供获取公告添加时间的方法,在展示公告信息、
// 按时间排序等业务场景中会用到此时间信息,例如在公告列表中按照添加时间先后顺序展示公告
// * @return 返回公告添加时间对应的Date对象
// */
public Date getInsertTime() {
return insertTime;
}
/**
*
*/
// **
// * 设置:添加时间,用于设置公告的添加时间,
// 一般在创建公告对象时会根据实际添加时间来调用此方法进行设置,确保添加时间记录的准确性
// * @param insertTime 要设置的添加时间对应的Date对象
// */
public void setInsertTime(Date insertTime) {
this.insertTime = insertTime;
}
/**
*
*/
// **
// * 获取:公告详情,对外提供获取公告详细内容的方法,
// 用于在展示公告详情页面、搜索公告内容等业务场景中获取具体文本信息,以完整呈现公告需要传达的信息
// * @return 返回公告详情对应的字符串值
// */
public String getNewsContent() {
return newsContent;
}
/**
*
*/
// **
// * 设置:公告详情,用于更新公告的详细内容,
// 例如管理员编辑公告内容后调用此方法来保存新的内容信息,保证公告详情能及时更新反映最新情况
// * @param newsContent 要设置的公告详情字符串值
// */
public void setNewsContent(String newsContent) {
this.newsContent = newsContent;
}
/**
* show1 show2 nameShow
*/
// **
// * 获取:创建时间 show1 show2 nameShow
// 对外提供获取该特定创建时间字段值的方法,根据具体业务需求在相关场景中使用此时间信息,例如在不同的展示页面按照对应名称展示公告创建时间
// * @return 返回创建时间 show1 show2 nameShow对应的Date对象
// */
public Date getCreateTime() {
return createTime;
}
/**
* show1 show2 nameShow
*/
// **
// * 设置:创建时间 show1 show2 nameShow
// 用于设置该特定创建时间字段的值,在相应的创建相关业务操作场景下调用此方法进行设置,确保创建时间记录符合业务要求
// * @param createTime 要设置的创建时间 show1 show2 nameShow对应的Date对象
// */
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}
}

@ -12,19 +12,45 @@ import java.util.Date;
/**
*
*
* 使
*
* `DictionaryEntity` `DictionaryEntity`
*
* 使
*
*
*/
@TableName("dictionary")
public class DictionaryView extends DictionaryEntity implements Serializable {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
// **
// * 默认构造函数,用于创建一个空的 `DictionaryView`
// 对象实例,在某些场景下(比如先创建对象,后续再根据具体数据来填充属性值)会使用到,
// * 提供了一种灵活创建该视图实体对象的方式,
//
// 方便后续在复杂业务逻辑中按需构建对象并设置其属性。
// */
public DictionaryView() {
}
// **
// * 构造函数,用于根据传入的 `DictionaryEntity` 对象,
//
// 通过 `BeanUtils` 工具类将其属性值复制到当前 `DictionaryView` 对象中,
// * 这样可以方便地基于已有的 `DictionaryEntity`
//
//
// 类型的数据对象来初始化 `DictionaryView` 对象,实现数据的传递和复用,避免重复设置各个属性,提高代码效率,
// * 在后端从数据库查询出 `DictionaryEntity` 数据后,
//
// 若要转换为适合返回的视图实体时,就可以使用这个构造函数进行属性值的复制,
//
// 不过在使用过程中需要注意可能出现的异常情况(已在代码中对异常进行了简单处理)。
// * @param dictionaryEntity 要复制属性值的 `DictionaryEntity`
//
// 对象,通过该对象的属性来初始化当前 `DictionaryView` 对象的属性。
// */
public DictionaryView(DictionaryEntity dictionaryEntity) {
try {
BeanUtils.copyProperties(this, dictionaryEntity);
@ -33,25 +59,4 @@ public class DictionaryView extends DictionaryEntity implements Serializable {
e.printStackTrace();
}
}
}
}

@ -12,67 +12,102 @@ import java.util.Date;
/**
*
*
* 使
* 使
*/
@TableName("forum")
public class ForumView extends ForumEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
*
*/
private String forumStateValue;
//级联表 yonghu
/**
*
*/
private String yonghuName;
/**
*
*/
private String yonghuPhoto;
/**
*
*/
private String yonghuPhone;
/**
*
*/
private String yonghuEmail;
/**
*
*/
private Double newMoney;
/**
*
*/
private Integer yonghuDelete;
//级联表 users
/**
*
*/
private String uusername;
/**
*
*/
private String upassword;
/**
*
*/
private String urole;
/**
*
*/
private Date uaddtime;
private static final long serialVersionUID = 1L;
// **
// * 帖子状态的值,
// 用于存储帖子状态对应的具体描述性字符串
// (可能比单纯用数字表示状态更直观,便于前端直接展示给用户理解帖子当前状态含义)
// */
private String forumStateValue;
// 以下是与级联表 yonghu 相关的属性,
// 用于扩展论坛帖子关联的用户相关信息,
// 方便在展示帖子时一并提供用户的详细资料
// **
// * 用户姓名,存储发布该帖子的用户的真实姓名信息,
// 便于在前端展示帖子时显示发布者的姓名,增强信息展示的完整性
// */
private String yonghuName;
// **
// * 头像,用于存储用户的头像图片相关信息
// 可能是图片路径、URL或者其他标识取决于项目中头像存储和引用方式
// 以便在前端展示用户头像,提升用户界面的可视化效果
// */
private String yonghuPhoto;
// **
// * 手机号,存储用户的手机号码信息,
// 在某些业务场景下(比如需要联系用户、验证用户身份等)
// 可能会用到该信息进行相关操作或展示给有权限查看的角色
// */
private String yonghuPhone;
// **
// * 电子邮箱,保存用户的电子邮箱地址,
// 可用于发送通知、进行账号相关操作验证等业务场景,
// 也可能展示给用户用于沟通联系等用途
// */
private String yonghuEmail;
// **
// * 余额,可能用于记录用户在系统中的账户余额信息(
// 例如在涉及支付、消费等功能的论坛系统中,用户可能有相应的资金账户情况),
// 方便在相关业务逻辑中查询和处理余额相关操作
// */
private Double newMoney;
// **
// * 假删,可能用于标记用户账号是否处于一种类似“软删除”的状态(
// 即表面上好像删除了,但实际数据还保留,只是在某些业务场景下不显示等情况),方便进行数据管理和状态控制
// */
private Integer yonghuDelete;
// 以下是与级联表 users 相关的属性,
// 用于扩展与论坛帖子可能关联的管理员或其他相关角色的详细信息
// **
// * 用户名,存储对应管理员或相关角色的用户名,
// 便于在前端展示或者业务逻辑中识别和区分不同的操作主体(比如知道是哪个管理员进行了帖子管理操作等)
// */
private String uusername;
// **
// * 密码,虽然在实际返回给前端的视图数据中通常不会直接展示密码(出于安全考虑),
// 但在后端业务逻辑处理中,可能涉及到验证、加密等与密码相关的操作,这里存储对应角色的密码信息
// */
private String upassword;
// **
// * 角色,用于明确该用户在系统中所扮演的角色
// (例如管理员、普通用户、版主等不同角色具有不同的权限和操作范围),方便进行权限控制和业务流程处理
// */
private String urole;
// **
// * 新增时间,记录该用户账号
// (对应管理员或相关角色)在系统中创建的具体时间,
// 可用于查询、统计等业务场景,例如查看新注册的管理员情况等
// */
private Date uaddtime;
// 默认构造函数,用于创建 ForumView
// 对象实例时进行一些默认的初始化操作
// (目前为空实现,可根据后续需求添加初始化逻辑)
public ForumView() {
}
// 构造函数,用于根据已有的 ForumEntity 对象来初始化 ForumView 对象,
// 通过 BeanUtils 工具类将 ForumEntity 中的属性值复制到当前对象中
// 这样可以方便地基于已有的实体对象数据来构建视图对象,
// 减少重复设置属性的操作,提高代码复用性
public ForumView(ForumEntity forumEntity) {
try {
BeanUtils.copyProperties(this, forumEntity);
@ -82,176 +117,241 @@ public class ForumView extends ForumEntity implements Serializable {
}
}
// **
// * 获取: 帖子状态的值,
// 对外提供获取帖子状态对应描述性字符串的方法,
// 以便在前端展示帖子状态信息或者在业务逻辑中根据该字符串进行相应处理
// * @return 返回帖子状态对应的字符串值
// */
public String getForumStateValue() {
return forumStateValue;
}
// **
// * 设置: 帖子状态的值,
// 用于更新帖子状态对应的描述性字符串,
// 例如当帖子状态发生变化后,通过此方法设置新的状态描述信息,方便后续展示和处理
// * @param forumStateValue 要设置的帖子状态描述性字符串值
// */
public void setForumStateValue(String forumStateValue) {
this.forumStateValue = forumStateValue;
}
/**
*
*/
public String getForumStateValue() {
return forumStateValue;
}
/**
*
*/
public void setForumStateValue(String forumStateValue) {
this.forumStateValue = forumStateValue;
}
// 以下是级联表 yonghu 的一系列获取get和设置set方法
// 用于对用户相关属性进行访问和修改操作
// **
// * 获取: 用户姓名,对外提供获取用户姓名的方法,
// 便于在前端展示帖子时获取并显示发布者的姓名信息,
// 或者在业务逻辑中根据姓名进行查询、统计等操作
// * @return 返回用户姓名对应的字符串值
// */
public String getYonghuName() {
return yonghuName;
}
// **
// * 设置: 用户姓名,用于更新用户的姓名信息,
// 例如用户修改了自己的真实姓名后,
// 通过此方法保存新的姓名数据,以便后续正确展示
// * @param yonghuName 要设置的用户姓名字符串值
// */
public void setYonghuName(String yonghuName) {
this.yonghuName = yonghuName;
}
// **
// * 获取: 头像,对外提供获取用户头像相关信息的方法,
// 在前端展示用户头像时调用此方法获取对应数据(根据存储方式进行相应的图片展示处理),
// 也可在业务逻辑中对头像信息进行修改、更新等操作时使用
// * @return 返回用户头像对应的字符串值如图片路径、URL等
// */
public String getYonghuPhoto() {
return yonghuPhoto;
}
// **
// * 设置: 头像,用于更新用户的头像信息,
// 比如用户更换了头像图片后,通过此方法保存新的头像相关数据,
// 确保前端展示的头像为最新的图片
// * @param yonghuPhoto 要设置的用户头像字符串值如新的图片路径、URL等
// */
public void setYonghuPhoto(String yonghuPhoto) {
this.yonghuPhoto = yonghuPhoto;
}
// **
// * 获取: 手机号,对外提供获取用户手机号码的方法,
// 在需要联系用户、验证身份等业务场景下可调用此方法获取手机号信息,
// 也可用于在前端展示用户信息时包含手机号(需考虑隐私保护相关设置)
// * @return 返回用户手机号对应的字符串值
// */
public String getYonghuPhone() {
return yonghuPhone;
}
// **
// * 设置: 手机号,用于更新用户的手机号码信息,
// 例如用户更换了手机号后,通过此方法保存新的手机号数据,
// 以便后续业务逻辑能正确使用最新的号码
// * @param yonghuPhone 要设置的用户手机号字符串值
// */
public void setYonghuPhone(String yonghuPhone) {
this.yonghuPhone = yonghuPhone;
}
// **
// * 获取: 电子邮箱,对外提供获取用户电子邮箱地址的方法,
// 在发送通知、账号验证等业务场景下可调用此方法获取邮箱信息,
// 也可在前端展示用户信息时包含邮箱(同样需考虑隐私保护)
// * @return 返回用户电子邮箱对应的字符串值
// */
public String getYonghuEmail() {
return yonghuEmail;
}
// **
// * 设置: 电子邮箱,用于更新用户的电子邮箱地址,
// 例如用户修改了邮箱后,通过此方法保存新的邮箱数据,
// 保证后续相关业务操作使用正确的邮箱信息
// * @param yonghuEmail 要设置的用户电子邮箱字符串值
// */
public void setYonghuEmail(String yonghuEmail) {
this.yonghuEmail = yonghuEmail;
}
// **
// * 获取: 余额,对外提供获取用户账户余额的方法,
// 在涉及支付、消费、查询余额等业务逻辑中可调用此方法获取余额数值,
// 方便进行相应的资金相关处理
// * @return 返回用户账户余额对应的 Double 类型数值
// */
public Double getNewMoney() {
return newMoney;
}
// **
// * 设置: 余额,用于更新用户的账户余额信息,
// 比如用户进行充值、消费等操作后,通过此方法保存新的余额数据,
// 确保系统中记录的余额是最新准确的
// * @param newMoney 要设置的用户账户余额 Double 类型数值
// */
public void setNewMoney(Double newMoney) {
this.newMoney = newMoney;
}
// **
// * 获取: 假删,对外提供获取用户“假删”状态标记的方法,
// 在数据管理、查询已“删除”用户等业务场景下可调用此方法获取该状态值,
// 以便进行相应的业务处理
// * @return 返回用户“假删”状态对应的整数值(通常是表示是否处于假删状态的标志位)
// */
public Integer getYonghuDelete() {
return yonghuDelete;
}
// **
// * 设置: 假删,
// 用于更新用户的“假删”状态标记,
//
//
//
// 例如管理员进行账号删除操作(软删除情况)时,
//
//
// 通过此方法设置相应的状态值,改变用户在系统中的显示和可操作状态
// * @param yonghuDelete 要设置的用户“假删”状态整数值
// */
public void setYonghuDelete(Integer yonghuDelete) {
this.yonghuDelete = yonghuDelete;
}
// 以下是级联表 users 的一系列获取get和设置set方法
// 用于对管理员或相关角色的属性进行访问和修改操作
// **
// * 获取: 用户名,对外提供获取管理员或相关角色用户名的方法,
// 便于在前端展示帖子管理操作主体信息或者在业务逻辑中根据用户名进行权限判断、操作记录查询等操作
// * @return 返回用户名对应的字符串值
// */
public String getUusername() {
return uusername;
}
// **
// * 设置: 用户名,用于更新管理员或相关角色的用户名信息,
// 例如管理员修改了自己的用户名后,
// 通过此方法保存新的用户名数据,以便后续正确展示和处理相关业务
// * @param uusername 要设置的用户名字符串值
// */
public void setUusername(String uusername) {
this.uusername = uusername;
}
// **
// * 获取: 密码,对外提供获取管理员或相关角色密码的方法,
// 虽然在前端视图展示中通常不会直接显示密码,
// 但在后端业务逻辑中涉及密码验证、加密存储等操作时会用到此方法获取密码信息(需确保密码存储和传输的安全性)
// * @return 返回密码对应的字符串值
// */
public String getUpassword() {
return upassword;
}
// **
// * 设置: 密码,用于更新管理员或相关角色的密码信息,
// 比如管理员修改密码后,通过此方法保存新的密码数据,
// 保证系统中存储的密码是最新且符合安全要求的
// * @param upassword 要设置的密码字符串值
// */
public void setUpassword(String upassword) {
this.upassword = upassword;
}
// **
// * 获取: 角色,对外提供获取管理员或相关角色在系统中所扮演角色的方法,
// 便于在业务逻辑中根据角色进行权限控制、
// 操作范围限定等处理,例如判断是否具有特定帖子管理权限等
// * @return 返回角色对应的字符串值(如管理员、普通用户、版主等不同角色名称或标识)
// */
public String getUrole() {
return urole;
}
//级联表的get和set yonghu
// **
// * 设置: 角色,用于更新管理员或相关角色的角色信息,
// 例如系统进行角色调整后,通过此方法保存新的角色数据,
// 以便后续根据新角色进行相应的权限和业务流程处理
// * @param urole 要设置的角色字符串值(如修改后的角色名称或标识)
// */
public void setUrole(String urole) {
this.urole = urole;
}
/**
*
*/
public String getYonghuName() {
return yonghuName;
}
/**
*
*/
public void setYonghuName(String yonghuName) {
this.yonghuName = yonghuName;
}
// **
// * 获取: 新增时间,
// 对外提供获取管理员或相关角色账号创建时间的方法,
// 在查询新注册管理员、
// 统计账号创建趋势等业务场景下可调用此方法获取时间信息,
// 方便进行相应的数据分析和管理操作
// * @return 返回新增时间对应的 Date 类型对象
// */
public Date getUaddtime() {
return uaddtime;
}
/**
*
*/
public String getYonghuPhoto() {
return yonghuPhoto;
}
/**
*
*/
public void setYonghuPhoto(String yonghuPhoto) {
this.yonghuPhoto = yonghuPhoto;
}
/**
*
*/
public String getYonghuPhone() {
return yonghuPhone;
}
/**
*
*/
public void setYonghuPhone(String yonghuPhone) {
this.yonghuPhone = yonghuPhone;
}
/**
*
*/
public String getYonghuEmail() {
return yonghuEmail;
}
/**
*
*/
public void setYonghuEmail(String yonghuEmail) {
this.yonghuEmail = yonghuEmail;
}
/**
*
*/
public Double getNewMoney() {
return newMoney;
}
/**
*
*/
public void setNewMoney(Double newMoney) {
this.newMoney = newMoney;
}
/**
*
*/
public Integer getYonghuDelete() {
return yonghuDelete;
}
/**
*
*/
public void setYonghuDelete(Integer yonghuDelete) {
this.yonghuDelete = yonghuDelete;
}
//级联表的get和set users
/**
*
*/
public String getUusername() {
return uusername;
}
/**
*
*/
public void setUusername(String uusername) {
this.uusername = uusername;
}
/**
*
*/
public String getUpassword() {
return upassword;
}
/**
*
*/
public void setUpassword(String upassword) {
this.upassword = upassword;
}
/**
*
*/
public String getUrole() {
return urole;
}
/**
*
*/
public void setUrole(String urole) {
this.urole = urole;
}
/**
*
*/
public Date getUaddtime() {
return uaddtime;
}
/**
*
*/
public void setUaddtime(Date uaddtime) {
this.uaddtime = uaddtime;
}
}
// **
// * 设置: 新增时间,
// 用于更新管理员或相关角色的账号创建时间信息
// (虽然在实际业务中一般较少出现修改创建时间的情况,
// 但保留此方法以满足可能的特殊需求),
// 例如数据迁移、时间校准等场景下可能会用到
// * @param uaddtime 要设置的新增时间对应的 Date 类型对象
// */
public void setUaddtime(Date uaddtime) {
this.uaddtime = uaddtime;
}
}

@ -12,23 +12,38 @@ import java.util.Date;
/**
*
*
* 使
//* (通常后端关联的表或者自定义的字段需要返回使用,
便
*/
@TableName("news")
public class NewsView extends NewsEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
*
*/
private String newsValue;
private static final long serialVersionUID = 1L;
// **
// * 公告类型的值,
// 用于存储公告类型对应的具体描述性字符串。
//
//
// 相较于单纯使用数字等方式表示公告类型,这个字符串形式能更直观地体现公告类型含义,
//
// 方便前端直接展示给用户理解公告所属的具体分类情况
// */
private String newsValue;
// 默认构造函数,用于创建 NewsView 对象实例时进行一
// 些默认的初始化操作(当前为空实现,后续若有需要可以添加相应的初始化逻辑,
// 比如设置一些默认属性值等)
public NewsView() {
}
// 构造函数,用于根据已有的 NewsEntity 对象来初始化 NewsView 对象。通
// 过 BeanUtils 工具类将 NewsEntity 中的属性值复制到当前对象中,
// 这样可以便捷地基于已有的实体对象数据构建视图对象,避免重复逐个设置属性,
// 提高代码复用性,减少代码冗余,方便在不同业务场景下进行对象数据的转换和传递
public NewsView(NewsEntity newsEntity) {
try {
BeanUtils.copyProperties(this, newsEntity);
@ -38,28 +53,28 @@ public class NewsView extends NewsEntity implements Serializable {
}
}
// **
// * 获取: 公告类型的值,
// 对外提供获取公告类型对应描述性字符串的方法,
// 以便在前端展示公告信息时能直观呈现公告类型内容,
// 或者在业务逻辑中根据该字符串进行相应的分类处理、筛选等操作
// * @return 返回公告类型对应的字符串值
// */
public String getNewsValue() {
return newsValue;
}
/**
*
*/
public String getNewsValue() {
return newsValue;
}
/**
*
*/
public void setNewsValue(String newsValue) {
this.newsValue = newsValue;
}
}
// **
// * 设置: 公告类型的值,
// 用于更新公告类型对应的描述性字符串,
// 例如当公告分类发生变化或者需要更准确、
//
//
// 更符合业务展示需求的类型描述时,通过此方法设置新的类型描述信息,
// 便于后续展示和处理相关业务逻辑
// * @param newsValue 要设置的公告类型描述性字符串值
// */
public void setNewsValue(String newsValue) {
this.newsValue = newsValue;
}
}

@ -8,17 +8,67 @@ import javax.servlet.http.HttpServletRequest;
/**
*
*
* MyBatis Plus `IService`
* `IService`
*
* 便
* 使
*
*/
public interface DictionaryService extends IService<DictionaryEntity> {
/**
* @param params
* @return
*/
PageUtils queryPage(Map<String, Object> params);
/**
*
* @param obj
*/
void dictionaryConvert(Object obj, HttpServletRequest request);
*
*
*
*
*
* `Map`
*
*
* `PageUtils`
*
* 便
*
* @param params `Map`
*
*
*
*
*
* @return `PageUtils`
*
*
* 便
*
*
*/
PageUtils queryPage(Map<String, Object> params);
/**
*
*
* `HttpServletRequest`
*
*
*
* 使
*
* `Object`
*
* @param obj `Object`
*
* `DictionaryEntity`
*
*
*
* @param request `HttpServletRequest`
*
*
*
*
* 使
*/
void dictionaryConvert(Object obj, HttpServletRequest request);
}

@ -8,12 +8,34 @@ import javax.servlet.http.HttpServletRequest;
/**
*
*
* MyBatis Plus IService
* IService
*
*
* 使便
*/
public interface ForumService extends IService<ForumEntity> {
/**
* @param params
* @return
*/
PageUtils queryPage(Map<String, Object> params);
*
*
*
* @param params Map
*
*
*
*
*
*
*
*
*
*
*
*
* @return PageUtils
* 便
*/
PageUtils queryPage(Map<String, Object> params);
}

@ -8,12 +8,35 @@ import javax.servlet.http.HttpServletRequest;
/**
*
* MyBatis Plus IService
* IService
*
* 便
*
*
*/
public interface NewsService extends IService<NewsEntity> {
/**
* @param params
* @return
*/
PageUtils queryPage(Map<String, Object> params);
*
*
*
* @param params Map
*
*
*
*
*
* @return PageUtils
*
*
*
*
*
*
*
* 便
* 便
*/
PageUtils queryPage(Map<String, Object> params);
}

@ -1,4 +1,3 @@
package com.service;
import java.util.List;
@ -9,20 +8,92 @@ import com.baomidou.mybatisplus.service.IService;
import com.entity.TokenEntity;
import com.utils.PageUtils;
/**
* token
* token token
* @author yangliyuan
* @date 20191010 9:18:20
*/
public interface TokenService extends IService<TokenEntity> {
PageUtils queryPage(Map<String, Object> params);
List<TokenEntity> selectListView(Wrapper<TokenEntity> wrapper);
PageUtils queryPage(Map<String, Object> params,Wrapper<TokenEntity> wrapper);
String generateToken(Integer userid,String username,String tableName, String role);
TokenEntity getTokenEntity(String token);
}
/**
*
* token
*
* @param params
*
*
* Map token
* 便
* @return PageUtils token
* 便
*/
PageUtils queryPage(Map<String, Object> params);
/**
* Wrapper TokenEntity
* Wrapper
* token
*
* @param wrapper
* TokenEntity
*
* token token
* @return TokenEntity TokenEntity
* token
* 便 token
*/
List<TokenEntity> selectListView(Wrapper<TokenEntity> wrapper);
/**
* paramswrapper token
*
*
* @param params Map
*
* wrapper
* @param wrapper token
* token params
* @return PageUtils
* token
*
*/
PageUtils queryPage(Map<String, Object> params, Wrapper<TokenEntity> wrapper);
/**
* token ID token
* token token
* 便
*
* @param userid
* ID token
* token
* @param username
* userid token
* @param tableName
*
* token token
* @param role
*
*
* token 便 token
* @return token
* 访
*/
String generateToken(Integer userid, String username, String tableName, String role);
/**
* token TokenEntity
* TokenEntity token
*
* token TokenEntity
* 便 token token
*
* @param token
* token generateToken
* TokenEntity
* @return token TokenEntity
* null token
*/
TokenEntity getTokenEntity(String token);
}

@ -19,21 +19,48 @@ import com.entity.view.ForumView;
/**
*
* MyBatis Plus ServiceImpl
* ForumService
* Spring @Service
* @Transactional
*/
@Service("forumService")
@Transactional
public class ForumServiceImpl extends ServiceImpl<ForumDao, ForumEntity> implements ForumService {
/**
*
* 使
*
* @param params Map
*
* @return PageUtils
* 便
*/
@Override
public PageUtils queryPage(Map<String,Object> params) {
if(params != null && (params.get("limit") == null || params.get("page") == null)){
params.put("page","1");
params.put("limit","10");
public PageUtils queryPage(Map<String, Object> params) {
// 如果传入的参数不为空,
// 并且参数中没有设置 "limit"(每页显示数量)
// 或者 "page"(页码)字段,则设置默认的页码为 1每页显示数量为 10
if (params!= null && (params.get("limit") == null || params.get("page") == null)) {
params.put("page", "1");
params.put("limit", "10");
}
Page<ForumView> page =new Query<ForumView>(params).getPage();
page.setRecords(baseMapper.selectListView(page,params));
return new PageUtils(page);
}
// 通过传入的参数构建一个 Query 对象,
// 并调用其 getPage 方法获取一个 Page<ForumView> 类型的分页对象,
// 这里 ForumView 可能是一个适合展示给前端的视图实体类,
// 包含了论坛相关数据以及可能关联的其他必要信息。
Page<ForumView> page = new Query<ForumView>(params).getPage();
// 调用 baseMapper继承自 ServiceImpl 类,
// 实际对应 ForumDao 接口中定义的数据库操作方法)的 selectListView 方法,
// 将分页对象以及查询参数传入,获取符合条件的分页数据列表,
// 并设置到 page 对象的 records 属性中,用于后续封装返回。
page.setRecords(baseMapper.selectListView(page, params));
}
// 使用获取到的包含分页数据的 page
// 对象构建并返回一个 PageUtils 对象,将分页数据及相关元信息进行整合封装,方便对外提供统一格式的分页数据结果。
return new PageUtils(page);
}
}

@ -19,21 +19,47 @@ import com.entity.view.NewsView;
/**
*
* MyBatis Plus ServiceImpl
* NewsService
* Spring @Service
* @Transactional
*/
@Service("newsService")
@Transactional
public class NewsServiceImpl extends ServiceImpl<NewsDao, NewsEntity> implements NewsService {
/**
*
* 便使
*
* @param params Map
*
* @return PageUtils 便
*/
@Override
public PageUtils queryPage(Map<String,Object> params) {
if(params != null && (params.get("limit") == null || params.get("page") == null)){
params.put("page","1");
params.put("limit","10");
public PageUtils queryPage(Map<String, Object> params) {
// 首先判断传入的参数是否不为空,并且在参数中没有设定
// "limit"(表示每页显示的公告数量)或者 "page"(表示页码)这两个关键分页参数时,
// 则为其赋予默认值,即将页码设为 1每页显示的公告数量设为 10以此确保分页查询能正常进行。
if (params!= null && (params.get("limit") == null || params.get("page") == null)) {
params.put("page", "1");
params.put("limit", "10");
}
Page<NewsView> page =new Query<NewsView>(params).getPage();
page.setRecords(baseMapper.selectListView(page,params));
return new PageUtils(page);
}
// 通过传入的参数构建一个 Query<NewsView> 类型的对象,
// 并调用其 getPage 方法来获取一个 Page<NewsView> 类型的分页对象。
// 这里的 NewsView 大概率是一个专门为前端展示等需求而设计的视图实体类,
// 它包含了公告信息以及可能与之关联的其他需要展示的相关信息。
Page<NewsView> page = new Query<NewsView>(params).getPage();
// 调用 baseMapper它继承自 ServiceImpl 类,
// 实际上对应的是 NewsDao 接口中定义的与数据库操作相关的方法)的 selectListView 方法,
// 把前面获取到的分页对象以及查询参数传递进去,获取符合查询条件的分页数据列表,
// 然后将这些数据设置到 page 对象的 records 属性中,以便后续进行封装并返回。
page.setRecords(baseMapper.selectListView(page, params));
}
// 最后,利用已经填充好数据的 page 对象来构建并返回一个 PageUtils 对象,
// 该对象会把分页数据以及与之相关的元数据进行整合封装,对外提供统一格式的分页数据结果,方便其他部分的代码进行使用。
return new PageUtils(page);
}
}

@ -1,7 +1,5 @@
package com.service.impl;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@ -21,60 +19,211 @@ import com.utils.CommonUtil;
import com.utils.PageUtils;
import com.utils.Query;
/**
* token
* `TokenService`
* token MyBatis Plus `ServiceImpl`
*
* Spring `@Service`
* 便 Spring 使
* @author
*/
@Service("tokenService")
public class TokenServiceImpl extends ServiceImpl<TokenDao, TokenEntity> implements TokenService {
/**
* token
* `TokenService`
* MyBatis Plus
* token
*
* @param params Map
* token
*
* @return `PageUtils`
* token
* 便
*/
@Override
public PageUtils queryPage(Map<String, Object> params) {
// 通过传入的参数构建一个 `Query<TokenEntity>` 对象,
// 并调用其 `getPage` 方法获取一个 `Page<TokenEntity>` 类型的分页对象,
// 这个分页对象包含了基本的分页信息(如当前页码、每页显示数量等),用于后续的分页查询操作。
Page<TokenEntity> page = this.selectPage(
new Query<TokenEntity>(params).getPage(),
new EntityWrapper<TokenEntity>()
);
return new PageUtils(page);
new Query<TokenEntity>(params).getPage(),
new EntityWrapper<TokenEntity>()
);
// 使用获取到的包含分页数据的 `page`
// 对象构建并返回一个 `PageUtils` 对象,将分页数据及相关元信息进行整合封装,
// 对外提供统一格式的分页数据结果,便于其他部分的代码使用。
return new PageUtils(page);
}
/**
* Wrapper
* `TokenEntity` `TokenService`
* `baseMapper`
* `ServiceImpl` `TokenDao` `selectListView`
* token
*
* @param wrapper
* `TokenEntity`
* token
* token
* token
* @return `TokenEntity`
* `TokenEntity` token
* 便 token
*/
@Override
public List<TokenEntity> selectListView(Wrapper<TokenEntity> wrapper) {
return baseMapper.selectListView(wrapper);
}
/**
* paramswrapper
* token `TokenService`
*
* `PageUtils`
*
* @param params Map
*
* `wrapper`
* @param wrapper token
* token
* `params`
* @return `PageUtils`
* token
*
*/
@Override
public PageUtils queryPage(Map<String, Object> params,
Wrapper<TokenEntity> wrapper) {
Page<TokenEntity> page =new Query<TokenEntity>(params).getPage();
page.setRecords(baseMapper.selectListView(page,wrapper));
PageUtils pageUtil = new PageUtils(page);
return pageUtil;
public PageUtils queryPage(Map<String, Object> params, Wrapper<TokenEntity> wrapper) {
// 通过传入的参数构建一个 `Page<TokenEntity>` 类型的分页对象,该对象包含了基本的分页设置信息,为后续查询做准备。
Page<TokenEntity> page = new Query<TokenEntity>(params).getPage();
// 调用 `baseMapper` 的 `selectListView` 方法,传入分页对象和条件包装器,获取符合条件的分页数据列表,
// 并将这些数据设置到 `page` 对象的 `records` 属性中,填充分页对象的具体数据内容。
page.setRecords(baseMapper.selectListView(page, wrapper));
// 使用填充好数据的 `page` 对象构建一个 `PageUtils` 对象,将分页数据及相关元信息进行整合封装,
// 然后返回这个 `PageUtils` 对象,以便向外提供统一格式的分页数据结果,供其他业务代码使用。
PageUtils pageUtil = new PageUtils(page);
return pageUtil;
}
/**
* token `TokenService` ID token
* token
* token token token
*
* @param userid
* ID token
* token
* @param username `userid` token
* @param tableName
*
* token token
* @param role
*
* token 便 token
* @return token
*
* 访
*/
@Override
public String generateToken(Integer userid,String username, String tableName, String role) {
public String generateToken(Integer userid, String username, String tableName, String role) {
// 首先尝试从数据库中查找是否已存在该用户
// (根据传入的 `userid` 和 `role`)对应的 token 记录,
// 通过构建一个 `EntityWrapper`
// 对象设置查询条件(使用 `eq` 方法表示相等条件,即查找 `userid` 和 `role` 与传入值相等的记录),
// 然后调用 `selectOne` 方法进行查询,
// 如果找到则返回对应的 `TokenEntity` 对象,否则返回 `null`。
TokenEntity tokenEntity = this.selectOne(new EntityWrapper<TokenEntity>().eq("userid", userid).eq("role", role));
// 调用工具类 `CommonUtil` 的 `getRandomString`
// 方法生成一个长度为 32 的随机字符串,作为新的 token 值,
// 这个随机字符串将作为唯一标识用户身份的关键信息,用于后续的身份验证等操作。
String token = CommonUtil.getRandomString(32);
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.HOUR_OF_DAY, 1);
if(tokenEntity!=null) {
// 获取一个 `Calendar` 实例,
// 用于操作日期和时间,这里用于设置 token 的过期时间。
Calendar cal = Calendar.getInstance();
// 将 `Calendar`
// 的时间设置为当前时间,以此为基础来计算过期时间。
cal.setTime(new Date());
// 给当前时间加上 1 小时,
// 即设置 token 的过期时间为从当前时间起 1 小时后,
// 这样可以控制 token 的有效时长,
// 提高系统的安全性,避免 token 长期有效可能带来的安全风险。
cal.add(Calendar.HOUR_OF_DAY, 1);
// 如果之前查询到已存在该用户对应的 token 记录(即 `tokenEntity` 不为 `null`
// 则更新该记录的 `token` 值为新生成的 `token` 字符串,
// 并设置其 `expiratedtime`(过期时间)为刚才计算好的时间,
// 最后调用 `updateById` 方法将更新后的 `TokenEntity`
// 对象保存到数据库中,完成 token 的更新操作。
if (tokenEntity!= null) {
tokenEntity.setToken(token);
tokenEntity.setExpiratedtime(cal.getTime());
this.updateById(tokenEntity);
} else {
this.insert(new TokenEntity(userid,username, tableName, role, token, cal.getTime()));
// 如果之前不存在对应的 token 记录,
// 则创建一个新的 `TokenEntity` 对象,
// 将传入的用户相关信息(`userid`、`username`、`tableName`、`role`)、
// 新生成的 `token` 字符串以及计算好的过期时间作为参数传入构造函数,
// 然后调用 `insert` 方法将新的 `TokenEntity` 对象插入到数据库中,
// 完成新 token 的创建操作。
this.insert(new TokenEntity(userid, username, tableName, role, token, cal.getTime()));
}
// 最后返回生成的 token 字符串,
// 该字符串将作为后续业务操作中用于验证用户身份的标识信息。
return token;
}
/**
* token `TokenEntity`
* `TokenService`
* token token
* `TokenEntity` `null` token
*
* @param token token
* `generateToken`
* `TokenEntity`
*
* @return token `TokenEntity`
*
* `token` `null` token
*/
@Override
public TokenEntity getTokenEntity(String token) {
// 通过构建一个 `EntityWrapper`
// 对象设置查询条件(使用 `eq` 方法表示相等条件,即查找 `token` 字段与传入的 `token` 值相等的记录),
// 然后调用 `selectOne`
// 方法从数据库中查找对应的 `TokenEntity` 对象,如果找到则返回该对象,否则返回 `null`。
TokenEntity tokenEntity = this.selectOne(new EntityWrapper<TokenEntity>().eq("token", token));
if(tokenEntity == null || tokenEntity.getExpiratedtime().getTime()<new Date().getTime()) {
// 如果查询到的 `tokenEntity` 为 `null`,说明数据库中不存在对应的 token 记录,直接返回 `null`,表示该 token 无效;
// 或者如果查询到的 `tokenEntity` 的 `expiratedtime`(过期时间)早于当前时间(通过 `getTime` 方法获取时间的毫秒数进行比较),
// 说明 token 已经过期,同样返回 `null`,表示该 token 已失效,不能用于后续的身份验证等操作。
if (tokenEntity == null || tokenEntity.getExpiratedtime().getTime() < new Date().getTime()) {
return null;
}
// 如果 token 存在且未过期,则返回对应的 `TokenEntity` 对象,以便后续可以获取其中的详细信息(如关联用户、角色等)进行相应的业务操作,
// 例如基于该 token 进行权限验证、获取用户相关信息等。
return tokenEntity;
}
}
}
Loading…
Cancel
Save