pull/5/head
wmz 3 months ago
parent e8edf658a8
commit 4ff828a25a

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <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" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

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

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

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

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

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

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

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

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

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

@ -8,12 +8,34 @@ import javax.servlet.http.HttpServletRequest;
/** /**
* *
*
* MyBatis Plus IService
* IService
*
*
* 使便
*/ */
public interface ForumService extends IService<ForumEntity> { 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> { 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; package com.service;
import java.util.List; import java.util.List;
@ -9,20 +8,92 @@ import com.baomidou.mybatisplus.service.IService;
import com.entity.TokenEntity; import com.entity.TokenEntity;
import com.utils.PageUtils; import com.utils.PageUtils;
/** /**
* token * token
* token token
* @author yangliyuan * @author yangliyuan
* @date 20191010 9:18:20 * @date 20191010 9:18:20
*/ */
public interface TokenService extends IService<TokenEntity> { public interface TokenService extends IService<TokenEntity> {
PageUtils queryPage(Map<String, Object> params);
/**
List<TokenEntity> selectListView(Wrapper<TokenEntity> wrapper); *
* token
PageUtils queryPage(Map<String, Object> params,Wrapper<TokenEntity> wrapper); *
* @param params
String generateToken(Integer userid,String username,String tableName, String role); *
*
TokenEntity getTokenEntity(String token); * 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") @Service("forumService")
@Transactional @Transactional
public class ForumServiceImpl extends ServiceImpl<ForumDao, ForumEntity> implements ForumService { public class ForumServiceImpl extends ServiceImpl<ForumDao, ForumEntity> implements ForumService {
/**
*
* 使
*
* @param params Map
*
* @return PageUtils
* 便
*/
@Override @Override
public PageUtils queryPage(Map<String,Object> params) { public PageUtils queryPage(Map<String, Object> params) {
if(params != null && (params.get("limit") == null || params.get("page") == null)){ // 如果传入的参数不为空,
params.put("page","1"); // 并且参数中没有设置 "limit"(每页显示数量)
params.put("limit","10"); // 或者 "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") @Service("newsService")
@Transactional @Transactional
public class NewsServiceImpl extends ServiceImpl<NewsDao, NewsEntity> implements NewsService { public class NewsServiceImpl extends ServiceImpl<NewsDao, NewsEntity> implements NewsService {
/**
*
* 便使
*
* @param params Map
*
* @return PageUtils 便
*/
@Override @Override
public PageUtils queryPage(Map<String,Object> params) { public PageUtils queryPage(Map<String, Object> params) {
if(params != null && (params.get("limit") == null || params.get("page") == null)){ // 首先判断传入的参数是否不为空,并且在参数中没有设定
params.put("page","1"); // "limit"(表示每页显示的公告数量)或者 "page"(表示页码)这两个关键分页参数时,
params.put("limit","10"); // 则为其赋予默认值,即将页码设为 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; package com.service.impl;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -21,60 +19,211 @@ import com.utils.CommonUtil;
import com.utils.PageUtils; import com.utils.PageUtils;
import com.utils.Query; import com.utils.Query;
/** /**
* token * token
* `TokenService`
* token MyBatis Plus `ServiceImpl`
*
* Spring `@Service`
* 便 Spring 使
* @author * @author
*/ */
@Service("tokenService") @Service("tokenService")
public class TokenServiceImpl extends ServiceImpl<TokenDao, TokenEntity> implements TokenService { public class TokenServiceImpl extends ServiceImpl<TokenDao, TokenEntity> implements TokenService {
/**
* token
* `TokenService`
* MyBatis Plus
* token
*
* @param params Map
* token
*
* @return `PageUtils`
* token
* 便
*/
@Override @Override
public PageUtils queryPage(Map<String, Object> params) { public PageUtils queryPage(Map<String, Object> params) {
// 通过传入的参数构建一个 `Query<TokenEntity>` 对象,
// 并调用其 `getPage` 方法获取一个 `Page<TokenEntity>` 类型的分页对象,
// 这个分页对象包含了基本的分页信息(如当前页码、每页显示数量等),用于后续的分页查询操作。
Page<TokenEntity> page = this.selectPage( Page<TokenEntity> page = this.selectPage(
new Query<TokenEntity>(params).getPage(), new Query<TokenEntity>(params).getPage(),
new EntityWrapper<TokenEntity>() new EntityWrapper<TokenEntity>()
); );
return new PageUtils(page); // 使用获取到的包含分页数据的 `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 @Override
public List<TokenEntity> selectListView(Wrapper<TokenEntity> wrapper) { public List<TokenEntity> selectListView(Wrapper<TokenEntity> wrapper) {
return baseMapper.selectListView(wrapper); return baseMapper.selectListView(wrapper);
} }
/**
* paramswrapper
* token `TokenService`
*
* `PageUtils`
*
* @param params Map
*
* `wrapper`
* @param wrapper token
* token
* `params`
* @return `PageUtils`
* token
*
*/
@Override @Override
public PageUtils queryPage(Map<String, Object> params, public PageUtils queryPage(Map<String, Object> params, Wrapper<TokenEntity> wrapper) {
Wrapper<TokenEntity> wrapper) { // 通过传入的参数构建一个 `Page<TokenEntity>` 类型的分页对象,该对象包含了基本的分页设置信息,为后续查询做准备。
Page<TokenEntity> page =new Query<TokenEntity>(params).getPage();
page.setRecords(baseMapper.selectListView(page,wrapper)); Page<TokenEntity> page = new Query<TokenEntity>(params).getPage();
PageUtils pageUtil = new PageUtils(page); // 调用 `baseMapper` 的 `selectListView` 方法,传入分页对象和条件包装器,获取符合条件的分页数据列表,
return pageUtil; // 并将这些数据设置到 `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 @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)); TokenEntity tokenEntity = this.selectOne(new EntityWrapper<TokenEntity>().eq("userid", userid).eq("role", role));
// 调用工具类 `CommonUtil` 的 `getRandomString`
// 方法生成一个长度为 32 的随机字符串,作为新的 token 值,
// 这个随机字符串将作为唯一标识用户身份的关键信息,用于后续的身份验证等操作。
String token = CommonUtil.getRandomString(32); String token = CommonUtil.getRandomString(32);
Calendar cal = Calendar.getInstance(); // 获取一个 `Calendar` 实例,
cal.setTime(new Date()); // 用于操作日期和时间,这里用于设置 token 的过期时间。
cal.add(Calendar.HOUR_OF_DAY, 1); Calendar cal = Calendar.getInstance();
if(tokenEntity!=null) { // 将 `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.setToken(token);
tokenEntity.setExpiratedtime(cal.getTime()); tokenEntity.setExpiratedtime(cal.getTime());
this.updateById(tokenEntity); this.updateById(tokenEntity);
} else { } 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; return token;
} }
/**
* token `TokenEntity`
* `TokenService`
* token token
* `TokenEntity` `null` token
*
* @param token token
* `generateToken`
* `TokenEntity`
*
* @return token `TokenEntity`
*
* `token` `null` token
*/
@Override @Override
public TokenEntity getTokenEntity(String token) { public TokenEntity getTokenEntity(String token) {
// 通过构建一个 `EntityWrapper`
// 对象设置查询条件(使用 `eq` 方法表示相等条件,即查找 `token` 字段与传入的 `token` 值相等的记录),
// 然后调用 `selectOne`
// 方法从数据库中查找对应的 `TokenEntity` 对象,如果找到则返回该对象,否则返回 `null`。
TokenEntity tokenEntity = this.selectOne(new EntityWrapper<TokenEntity>().eq("token", token)); 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; return null;
} }
// 如果 token 存在且未过期,则返回对应的 `TokenEntity` 对象,以便后续可以获取其中的详细信息(如关联用户、角色等)进行相应的业务操作,
// 例如基于该 token 进行权限验证、获取用户相关信息等。
return tokenEntity; return tokenEntity;
} }
} }
Loading…
Cancel
Save