Merge branch 'release/1.0.1'

This commit is contained in:
jonah.fu
2025-08-15 13:15:27 +08:00
12 changed files with 620 additions and 51 deletions
+12 -1
View File
@@ -765,7 +765,18 @@ namespace COMCMS.Common
return false; return false;
string extname = filename.Substring(filename.LastIndexOf(".") + 1).ToLower(); string extname = filename.Substring(filename.LastIndexOf(".") + 1).ToLower();
return (extname == "jpg" || extname == "jpeg" || extname == "png" || extname == "bmp" || extname == "gif");
// 从配置中获取图片扩展名列表
string imageExtensions = Configuration["SystemSetting:ImageExtensions"];
if (string.IsNullOrEmpty(imageExtensions))
{
// 如果配置中没有设置,则使用默认值
imageExtensions = "jpg,jpeg,png,bmp,gif";
}
// 将扩展名列表分割成数组并检查
string[] extensions = imageExtensions.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
return extensions.Contains(extname);
} }
/// <summary> /// <summary>
@@ -222,7 +222,15 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
string content = ""; string content = "";
if (System.IO.File.Exists(file)) if (System.IO.File.Exists(file))
{ {
content = System.IO.File.ReadAllText(file); try
{
content = System.IO.File.ReadAllText(file);
}
catch (Exception ex)
{
NewLife.Log.XTrace.WriteException(ex);
// 如果读取文件失败,继续使用空内容
}
} }
ViewBag.content = content; ViewBag.content = content;
Admin.WriteLogActions("查看Robots.txt;"); Admin.WriteLogActions("查看Robots.txt;");
@@ -233,15 +241,18 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
public IActionResult Robots(string content) public IActionResult Robots(string content)
{ {
string file = Path.Combine(_env.WebRootPath, "robots.txt"); string file = Path.Combine(_env.WebRootPath, "robots.txt");
if (System.IO.File.Exists(file)) try
{ {
//写入覆盖 //写入覆盖
System.IO.File.WriteAllText(file, content); System.IO.File.WriteAllText(file, content);
} }
else catch (Exception ex)
{ {
System.IO.File.WriteAllText(file, content); NewLife.Log.XTrace.WriteException(ex);
tip.Message = "修改Robots.txt失败:" + ex.Message;
return Json(tip);
} }
tip.Status = JsonTip.SUCCESS; tip.Status = JsonTip.SUCCESS;
tip.Message = "修改Robots.txt成功"; tip.Message = "修改Robots.txt成功";
Admin.WriteLogActions("修改Robots.txt成功;"); Admin.WriteLogActions("修改Robots.txt成功;");
+132 -35
View File
@@ -27,13 +27,14 @@ namespace COMCMS.Web.Controllers
private IWebHostEnvironment _env; private IWebHostEnvironment _env;
private readonly ICacheProvider _cacheProvider; private readonly ICacheProvider _cacheProvider;
public HomeController(IWebHostEnvironment env,ICacheProvider cacheProvider) public HomeController(IWebHostEnvironment env, ICacheProvider cacheProvider)
{ {
_env = env; _env = env;
_cacheProvider = cacheProvider; _cacheProvider = cacheProvider;
} }
#region 首页 #region 首页
public IActionResult Index() public IActionResult Index()
{ {
bool hasData = AdminMenu.FindCount(null, null, null, 0, 0) > 0; bool hasData = AdminMenu.FindCount(null, null, null, 0, 0) > 0;
@@ -41,21 +42,26 @@ namespace COMCMS.Web.Controllers
{ {
return Redirect("/Home/Install"); return Redirect("/Home/Install");
} }
ViewBag.cfg = cfg; ViewBag.cfg = cfg;
ViewBag.about = Article.FindById(1);//关于我们 ViewBag.about = Article.FindById(1); //关于我们
return View("~/Views/Home/Index.cshtml"); return View("~/Views/Home/Index.cshtml");
} }
#endregion #endregion
#region 显示默认错误页面 #region 显示默认错误页面
public IActionResult Error() public IActionResult Error()
{ {
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
} }
#endregion #endregion
#region 初始化安装 #region 初始化安装
[HttpGet] [HttpGet]
public IActionResult Install() public IActionResult Install()
{ {
@@ -64,6 +70,7 @@ namespace COMCMS.Web.Controllers
{ {
return EchoTip("COMCMS系统已经安装过,如果需要重新安装,请删除程序wwwroot目录下的install.lock文件!", false, "/"); return EchoTip("COMCMS系统已经安装过,如果需要重新安装,请删除程序wwwroot目录下的install.lock文件!", false, "/");
} }
//判断数据库类型 mysql mssql 暂时只支持这两种 //判断数据库类型 mysql mssql 暂时只支持这两种
string sqltype = "mysql"; string sqltype = "mysql";
string sqlProviderName = Utils.GetSetting("connectionStrings:dbconn:providerName"); string sqlProviderName = Utils.GetSetting("connectionStrings:dbconn:providerName");
@@ -71,14 +78,17 @@ namespace COMCMS.Web.Controllers
{ {
sqltype = "mssql"; sqltype = "mssql";
} }
bool hasData = AdminMenu.FindCount(null, null, null, 0, 0) > 0; bool hasData = AdminMenu.FindCount(null, null, null, 0, 0) > 0;
ViewBag.hasData = hasData; ViewBag.hasData = hasData;
ViewBag.sqltype = sqltype; ViewBag.sqltype = sqltype;
return View(); return View();
} }
#endregion #endregion
#region 执行初始化数据库数据 #region 执行初始化数据库数据
[HttpPost] [HttpPost]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public IActionResult DoInstall() public IActionResult DoInstall()
@@ -101,7 +111,8 @@ namespace COMCMS.Web.Controllers
tip.Message = "请输入用户名!"; tip.Message = "请输入用户名!";
return Json(tip); return Json(tip);
} }
if (username.Trim().Length<5)
if (username.Trim().Length < 5)
{ {
tip.Message = "用户名不能小于4个字符!"; tip.Message = "用户名不能小于4个字符!";
return Json(tip); return Json(tip);
@@ -112,11 +123,13 @@ namespace COMCMS.Web.Controllers
tip.Message = "登录密码不能为空或者长度小于5!"; tip.Message = "登录密码不能为空或者长度小于5!";
return Json(tip); return Json(tip);
} }
if(password != password2)
if (password != password2)
{ {
tip.Message = "两次输入密码不一致,请重新输入!"; tip.Message = "两次输入密码不一致,请重新输入!";
return Json(tip); return Json(tip);
} }
string sqltype = "mysql"; string sqltype = "mysql";
string sqlProviderName = Utils.GetSetting("connectionStrings:dbconn:providerName"); string sqlProviderName = Utils.GetSetting("connectionStrings:dbconn:providerName");
if (sqlProviderName == "System.Data.SqlClient") if (sqlProviderName == "System.Data.SqlClient")
@@ -124,7 +137,7 @@ namespace COMCMS.Web.Controllers
sqltype = "mssql"; sqltype = "mssql";
} }
if(sqltype =="mysql" && string.IsNullOrEmpty(mysqltype)) if (sqltype == "mysql" && string.IsNullOrEmpty(mysqltype))
{ {
tip.Message = "请选择系统Mysql服务器类型!"; tip.Message = "请选择系统Mysql服务器类型!";
return Json(tip); return Json(tip);
@@ -139,7 +152,7 @@ namespace COMCMS.Web.Controllers
//判断需要的sql文件 //判断需要的sql文件
string sqlname = "comcms_sqlserver.sql"; string sqlname = "comcms_sqlserver.sql";
if(sqltype == "mysql") if (sqltype == "mysql")
{ {
if (mysqltype == "linux") if (mysqltype == "linux")
sqlname = "comcms_for_linux.sql"; sqlname = "comcms_for_linux.sql";
@@ -155,45 +168,95 @@ namespace COMCMS.Web.Controllers
tip.Message = "缺少初始化SQL文件!"; tip.Message = "缺少初始化SQL文件!";
return Json(tip); return Json(tip);
} }
string fullsql = System.IO.File.ReadAllText(sqlFullPath);
string fullsql = "";
try
{
fullsql = System.IO.File.ReadAllText(sqlFullPath);
}
catch (Exception ex)
{
NewLife.Log.XTrace.WriteException(ex);
tip.Message = "读取SQL文件时发生错误:" + ex.Message;
return Json(tip);
}
//如果是mssql 需要替换一下 GO不能在程序中直接执行 //如果是mssql 需要替换一下 GO不能在程序中直接执行
if (sqltype == "mssql") if (sqltype == "mssql")
{ {
fullsql = fullsql.Replace("GO", ";"); fullsql = fullsql.Replace("GO", ";");
} }
Admin.FindAll(fullsql);//执行 try
{
Admin.FindAll(fullsql); //执行
}
catch (Exception ex)
{
NewLife.Log.XTrace.WriteException(ex);
tip.Message = "执行SQL时发生错误:" + ex.Message;
return Json(tip);
}
//初始化 //初始化
Config cfg = Config.FindById(1); Config cfg = Config.FindById(1);
if(cfg != null) if (cfg != null)
{ {
cfg.SiteName = sitename; try
cfg.SiteUrl = siteurl; {
cfg.Update(); cfg.SiteName = sitename;
cfg.SiteUrl = siteurl;
cfg.Update();
}
catch (Exception ex)
{
NewLife.Log.XTrace.WriteException(ex);
tip.Message = "初始化配置时发生错误:" + ex.Message;
return Json(tip);
}
} }
Admin admin = Admin.Find(Admin._.Id == 1); Admin admin = Admin.Find(Admin._.Id == 1);
if(admin != null) if (admin != null)
{ {
admin.UserName = username; try
admin.Salt = Utils.GetRandomChar(10); {
admin.PassWord = Utils.MD5(admin.Salt + password); admin.UserName = username;
admin.Update(); admin.Salt = Utils.GetRandomChar(10);
admin.PassWord = Utils.MD5(admin.Salt + password);
admin.Update();
}
catch (Exception ex)
{
NewLife.Log.XTrace.WriteException(ex);
tip.Message = "创建管理员账户时发生错误:" + ex.Message;
return Json(tip);
}
} }
//写入Lock文件 //写入Lock文件
System.IO.File.WriteAllText(lockPath, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); try
{
System.IO.File.WriteAllText(lockPath, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
}
catch (Exception ex)
{
NewLife.Log.XTrace.WriteException(ex);
tip.Message = "创建安装锁文件时发生错误:" + ex.Message;
return Json(tip);
}
tip.Message = "导入数据成功!"; tip.Message = "导入数据成功!";
tip.Status = JsonTip.SUCCESS; tip.Status = JsonTip.SUCCESS;
tip.ReturnUrl = "/"; tip.ReturnUrl = "/";
return Json(tip); return Json(tip);
} }
#endregion #endregion
#region 测试 #region 测试
//[Route("c/{*path}/index2.html")] //[Route("c/{*path}/index2.html")]
//public IActionResult Test(string path = "") //public IActionResult Test(string path = "")
//{ //{
@@ -228,10 +291,12 @@ namespace COMCMS.Web.Controllers
//{ //{
// return View(); // return View();
//} //}
#endregion #endregion
#region 系统文章栏目、商品栏目路由 #region 系统文章栏目、商品栏目路由
/// <summary> /// <summary>
/// 一级路径栏目 /// 一级路径栏目
/// </summary> /// </summary>
@@ -240,24 +305,26 @@ namespace COMCMS.Web.Controllers
[Route("{path:regex(^(?!swagger\\b)[[a-zA-Z0-9-]]+$)}/index.html")] [Route("{path:regex(^(?!swagger\\b)[[a-zA-Z0-9-]]+$)}/index.html")]
[Route("{path:regex(^(?!swagger\\b)[[a-zA-Z0-9-]]+$)}/index-{page:int}.html")] [Route("{path:regex(^(?!swagger\\b)[[a-zA-Z0-9-]]+$)}/index-{page:int}.html")]
//[Route("{path:regex(^(?!swagger\\b)[[a-zA-Z0-9-]]+$)}/")] //[Route("{path:regex(^(?!swagger\\b)[[a-zA-Z0-9-]]+$)}/")]
public IActionResult ShowCategory(string path,int page=1) public IActionResult ShowCategory(string path, int page = 1)
{ {
//先判断文章栏目 //先判断文章栏目
ArticleCategory articleCategory = ArticleCategory.FindByFilePath("/" + path); ArticleCategory articleCategory = ArticleCategory.FindByFilePath("/" + path);
if(articleCategory != null) if (articleCategory != null)
{ {
//return Content(articleCategory.Id.ToString()); //return Content(articleCategory.Id.ToString());
ArticleController ac = new ArticleController(); ArticleController ac = new ArticleController();
return ac.Index(articleCategory.Id, page); return ac.Index(articleCategory.Id, page);
} }
//再判断商品 //再判断商品
Category category = Category.FindByFilePath("/" + path); Category category = Category.FindByFilePath("/" + path);
if(category != null) if (category != null)
{ {
ProductController pc = new ProductController(); ProductController pc = new ProductController();
return pc.Index(category.Id,page); return pc.Index(category.Id, page);
} }
return EchoTip("系统找不到本栏目!"+"/"+path);
return EchoTip("系统找不到本栏目!" + "/" + path);
} }
/// <summary> /// <summary>
@@ -279,6 +346,7 @@ namespace COMCMS.Web.Controllers
ArticleController ac = new ArticleController(); ArticleController ac = new ArticleController();
return ac.Index(articleCategory.Id, page); return ac.Index(articleCategory.Id, page);
} }
//再判断商品 //再判断商品
Category category = Category.FindByFilePath(fullPath); Category category = Category.FindByFilePath(fullPath);
if (category != null) if (category != null)
@@ -286,15 +354,19 @@ namespace COMCMS.Web.Controllers
ProductController pc = new ProductController(); ProductController pc = new ProductController();
return pc.Index(category.Id, page); return pc.Index(category.Id, page);
} }
return EchoTip("系统找不到本栏目!" + path + "|" + path2); return EchoTip("系统找不到本栏目!" + path + "|" + path2);
} }
/// <summary> /// <summary>
/// 三级路径栏目 /// 三级路径栏目
/// </summary> /// </summary>
/// <param name="path"></param> /// <param name="path"></param>
/// <returns></returns> /// <returns></returns>
[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/index.html")] [Route(
[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/index-{page:int}.html")] "{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/index.html")]
[Route(
"{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/index-{page:int}.html")]
//[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/")] //[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/")]
public IActionResult ShowCategory(string path, string path2, string path3, int page = 1) public IActionResult ShowCategory(string path, string path2, string path3, int page = 1)
{ {
@@ -307,6 +379,7 @@ namespace COMCMS.Web.Controllers
ArticleController ac = new ArticleController(); ArticleController ac = new ArticleController();
return ac.Index(articleCategory.Id, page); return ac.Index(articleCategory.Id, page);
} }
//再判断商品 //再判断商品
Category category = Category.FindByFilePath(fullPath); Category category = Category.FindByFilePath(fullPath);
if (category != null) if (category != null)
@@ -314,15 +387,19 @@ namespace COMCMS.Web.Controllers
ProductController pc = new ProductController(); ProductController pc = new ProductController();
return pc.Index(category.Id, page); return pc.Index(category.Id, page);
} }
return EchoTip("系统找不到本栏目!" + fullPath); return EchoTip("系统找不到本栏目!" + fullPath);
} }
/// <summary> /// <summary>
/// 四级路径栏目 /// 四级路径栏目
/// </summary> /// </summary>
/// <param name="path"></param> /// <param name="path"></param>
/// <returns></returns> /// <returns></returns>
[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{path4:regex(^[[a-zA-Z0-9-]]+$)}/index.html")] [Route(
[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{path4:regex(^[[a-zA-Z0-9-]]+$)}/index-{page:int}.html")] "{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{path4:regex(^[[a-zA-Z0-9-]]+$)}/index.html")]
[Route(
"{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{path4:regex(^[[a-zA-Z0-9-]]+$)}/index-{page:int}.html")]
//[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{path4:regex(^[[a-zA-Z0-9-]]+$)}/")] //[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{path4:regex(^[[a-zA-Z0-9-]]+$)}/")]
public IActionResult ShowCategory(string path, string path2, string path3, string path4, int page = 1) public IActionResult ShowCategory(string path, string path2, string path3, string path4, int page = 1)
{ {
@@ -333,8 +410,9 @@ namespace COMCMS.Web.Controllers
{ {
//return Content(articleCategory.Id.ToString()); //return Content(articleCategory.Id.ToString());
ArticleController ac = new ArticleController(); ArticleController ac = new ArticleController();
return ac.Index(articleCategory.Id,page); return ac.Index(articleCategory.Id, page);
} }
//再判断商品 //再判断商品
Category category = Category.FindByFilePath(fullPath); Category category = Category.FindByFilePath(fullPath);
if (category != null) if (category != null)
@@ -342,11 +420,14 @@ namespace COMCMS.Web.Controllers
ProductController pc = new ProductController(); ProductController pc = new ProductController();
return pc.Index(category.Id, page); return pc.Index(category.Id, page);
} }
return EchoTip("系统找不到本栏目!" + fullPath); return EchoTip("系统找不到本栏目!" + fullPath);
} }
#endregion #endregion
#region 文章详情、商品详情 #region 文章详情、商品详情
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@@ -368,17 +449,20 @@ namespace COMCMS.Web.Controllers
{ {
article = Article.FindById(int.Parse(filename)); article = Article.FindById(int.Parse(filename));
} }
if (article == null) if (article == null)
{ {
filename = filename + ".html"; filename = filename + ".html";
article = Article.FindByFileName(filename, articleCategory.Id); article = Article.FindByFileName(filename, articleCategory.Id);
} }
if(article != null)
if (article != null)
{ {
ArticleController ac = new ArticleController(); ArticleController ac = new ArticleController();
return ac.Detail(article.Id); return ac.Detail(article.Id);
} }
} }
//再判断商品 //再判断商品
Category category = Category.FindByFilePath(fullPath); Category category = Category.FindByFilePath(fullPath);
if (category != null) if (category != null)
@@ -389,11 +473,13 @@ namespace COMCMS.Web.Controllers
{ {
product = Product.FindById(int.Parse(filename)); product = Product.FindById(int.Parse(filename));
} }
if (product == null) if (product == null)
{ {
filename = filename + ".html"; filename = filename + ".html";
product = Product.FindByFileName(filename, articleCategory.Id); product = Product.FindByFileName(filename, articleCategory.Id);
} }
if (product != null) if (product != null)
{ {
ProductController pc = new ProductController(); ProductController pc = new ProductController();
@@ -403,6 +489,7 @@ namespace COMCMS.Web.Controllers
return EchoTip("系统找不到本详情!" + "/" + path + "/" + filename); return EchoTip("系统找不到本详情!" + "/" + path + "/" + filename);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@@ -410,12 +497,14 @@ namespace COMCMS.Web.Controllers
/// <param name="filename"></param> /// <param name="filename"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{filename:regex(^(?!index\\b)[[a-zA-Z0-9-]]+$)}.html")] [Route(
"{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{filename:regex(^(?!index\\b)[[a-zA-Z0-9-]]+$)}.html")]
public IActionResult ShowDetail(string path, string path2, string filename) public IActionResult ShowDetail(string path, string path2, string filename)
{ {
string fullPath = $"{path}/{path2}"; string fullPath = $"{path}/{path2}";
return ShowDetail(fullPath, filename); return ShowDetail(fullPath, filename);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@@ -423,23 +512,28 @@ namespace COMCMS.Web.Controllers
/// <param name="filename"></param> /// <param name="filename"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{filename:regex(^(?!index\\b)[[a-zA-Z0-9-]]+$)}.html")] [Route(
"{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{filename:regex(^(?!index\\b)[[a-zA-Z0-9-]]+$)}.html")]
public IActionResult ShowDetail(string path, string path2, string path3, string filename) public IActionResult ShowDetail(string path, string path2, string path3, string filename)
{ {
string fullPath = $"{path}/{path2}/{path3}"; string fullPath = $"{path}/{path2}/{path3}";
return ShowDetail(fullPath, filename); return ShowDetail(fullPath, filename);
} }
//四级 //四级
[HttpGet] [HttpGet]
[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{path4:regex(^[[a-zA-Z0-9-]]+$)}/{filename:regex(^(?!index\\b)[[a-zA-Z0-9-]]+$)}.html")] [Route(
"{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{path4:regex(^[[a-zA-Z0-9-]]+$)}/{filename:regex(^(?!index\\b)[[a-zA-Z0-9-]]+$)}.html")]
public IActionResult ShowDetail(string path, string path2, string path3, string path4, string filename) public IActionResult ShowDetail(string path, string path2, string path3, string path4, string filename)
{ {
string fullPath = $"{path}/{path2}/{path3}/{path4}"; string fullPath = $"{path}/{path2}/{path3}/{path4}";
return ShowDetail(fullPath, filename); return ShowDetail(fullPath, filename);
} }
#endregion #endregion
#region sitemap html #region sitemap html
[Route("sitemap.html")] [Route("sitemap.html")]
[HttpGet] [HttpGet]
public IActionResult SitemapHTML() public IActionResult SitemapHTML()
@@ -447,9 +541,11 @@ namespace COMCMS.Web.Controllers
ViewBag.cfg = cfg; ViewBag.cfg = cfg;
return View(); return View();
} }
#endregion #endregion
#region sitemap xml #region sitemap xml
[HttpGet] [HttpGet]
[Route("sitemap.xml")] [Route("sitemap.xml")]
public IActionResult SitemapXML() public IActionResult SitemapXML()
@@ -457,9 +553,11 @@ namespace COMCMS.Web.Controllers
Response.ContentType = "text/xml"; Response.ContentType = "text/xml";
return View(); return View();
} }
#endregion #endregion
#region 测试 #region 测试
public IActionResult Test() public IActionResult Test()
{ {
//至少八个字符,至少一个字母和一个数字 //至少八个字符,至少一个字母和一个数字
@@ -475,7 +573,6 @@ namespace COMCMS.Web.Controllers
bool t6 = Regex.IsMatch("123456vW@", rgx2); bool t6 = Regex.IsMatch("123456vW@", rgx2);
string result = $"t1:{t1}; t2:{t2}; t3:{t3}; t4:{t4}; t5:{t5}; t6:{t6}"; string result = $"t1:{t1}; t2:{t2}; t3:{t3}; t4:{t4}; t5:{t5}; t6:{t6}";
@@ -483,9 +580,9 @@ namespace COMCMS.Web.Controllers
string a = _cacheProvider.Cache.Get<string>("test"); string a = _cacheProvider.Cache.Get<string>("test");
return Content(result+";cache:"+ a); return Content(result + ";cache:" + a);
} }
#endregion #endregion
} }
} }
+131
View File
@@ -0,0 +1,131 @@
using System;
namespace COMCMS.Web.Models
{
/// <summary>
/// 缓存配置设置
/// </summary>
public class CacheSettings
{
/// <summary>
/// 默认过期时间(分钟)
/// </summary>
public int DefaultExpirationMinutes { get; set; } = 30;
/// <summary>
/// 系统配置缓存过期时间(分钟)
/// </summary>
public int SystemConfigExpirationMinutes { get; set; } = 60;
/// <summary>
/// 文章缓存过期时间(分钟)
/// </summary>
public int ArticleExpirationMinutes { get; set; } = 20;
/// <summary>
/// 产品缓存过期时间(分钟)
/// </summary>
public int ProductExpirationMinutes { get; set; } = 20;
/// <summary>
/// 分类缓存过期时间(分钟)
/// </summary>
public int CategoryExpirationMinutes { get; set; } = 120;
/// <summary>
/// 用户缓存过期时间(分钟)
/// </summary>
public int UserExpirationMinutes { get; set; } = 15;
/// <summary>
/// 订单缓存过期时间(分钟)
/// </summary>
public int OrderExpirationMinutes { get; set; } = 10;
/// <summary>
/// 是否启用响应缓存
/// </summary>
public bool EnableResponseCaching { get; set; } = true;
/// <summary>
/// 是否启用分布式缓存
/// </summary>
public bool EnableDistributedCaching { get; set; } = true;
/// <summary>
/// 获取默认过期时间跨度
/// </summary>
public TimeSpan DefaultExpiration => TimeSpan.FromMinutes(DefaultExpirationMinutes);
/// <summary>
/// 获取系统配置过期时间跨度
/// </summary>
public TimeSpan SystemConfigExpiration => TimeSpan.FromMinutes(SystemConfigExpirationMinutes);
/// <summary>
/// 获取文章过期时间跨度
/// </summary>
public TimeSpan ArticleExpiration => TimeSpan.FromMinutes(ArticleExpirationMinutes);
/// <summary>
/// 获取产品过期时间跨度
/// </summary>
public TimeSpan ProductExpiration => TimeSpan.FromMinutes(ProductExpirationMinutes);
/// <summary>
/// 获取分类过期时间跨度
/// </summary>
public TimeSpan CategoryExpiration => TimeSpan.FromMinutes(CategoryExpirationMinutes);
/// <summary>
/// 获取用户过期时间跨度
/// </summary>
public TimeSpan UserExpiration => TimeSpan.FromMinutes(UserExpirationMinutes);
/// <summary>
/// 获取订单过期时间跨度
/// </summary>
public TimeSpan OrderExpiration => TimeSpan.FromMinutes(OrderExpirationMinutes);
}
/// <summary>
/// Redis缓存配置
/// </summary>
public class RedisCacheSettings
{
/// <summary>
/// 连接字符串
/// </summary>
public string ConnectionString { get; set; } = "server=127.0.0.1;password=;db=2";
/// <summary>
/// 实例名称
/// </summary>
public string InstanceName { get; set; } = "COMCMS:";
/// <summary>
/// 默认数据库
/// </summary>
public int DefaultDatabase { get; set; } = 2;
/// <summary>
/// 连接超时时间(毫秒)
/// </summary>
public int ConnectTimeout { get; set; } = 5000;
/// <summary>
/// 同步超时时间(毫秒)
/// </summary>
public int SyncTimeout { get; set; } = 5000;
/// <summary>
/// 是否中断连接
/// </summary>
public bool AbortConnect { get; set; } = false;
/// <summary>
/// 连接重试次数
/// </summary>
public int ConnectRetry { get; set; } = 3;
}
}
+4
View File
@@ -23,6 +23,10 @@ namespace COMCMS.Web.Models
/// </summary> /// </summary>
public string MediaAllowedExtensions { get; set; } public string MediaAllowedExtensions { get; set; }
/// <summary> /// <summary>
/// 图片文件扩展名(用于判断是否为图片)
/// </summary>
public string ImageExtensions { get; set; }
/// <summary>
/// JWT验证的密钥 /// JWT验证的密钥
/// </summary> /// </summary>
public string JwtSecret { get; set; } public string JwtSecret { get; set; }
+90
View File
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using COMCMS.Common;
using COMCMS.Web.Models;
using Microsoft.Extensions.Options;
using NewLife.Caching;
using NewLife.Caching.Services;
namespace COMCMS.Web.Services
{
public class CacheService : ICacheService
{
private readonly NewLife.Caching.ICacheProvider _cacheProvider;
private readonly CacheSettings _settings;
private readonly string _prefix;
public CacheService(NewLife.Caching.ICacheProvider cacheProvider, IOptions<CacheSettings> settings)
{
_cacheProvider = cacheProvider;
_settings = settings.Value;
_prefix = Utils.PrefixKey ?? "comcms:";
}
private string BuildKey(string key) => string.Concat(_prefix, key ?? string.Empty);
public async Task<T> GetAsync<T>(string key)
{
return await Task.FromResult(_cacheProvider.Cache.Get<T>(BuildKey(key)));
}
public async Task SetAsync<T>(string key, T value, TimeSpan? expiration = null)
{
var expireSeconds = (int)(expiration ?? _settings.DefaultExpiration).TotalSeconds;
_cacheProvider.Cache.Add(BuildKey(key), value, expireSeconds);
await Task.CompletedTask;
}
public async Task RemoveAsync(string key)
{
_cacheProvider.Cache.Remove(BuildKey(key));
await Task.CompletedTask;
}
public async Task RemoveByPatternAsync(string pattern)
{
// 暂不支持模式删除,保留占位实现
await Task.CompletedTask;
}
public async Task<bool> ExistsAsync(string key)
{
var val = _cacheProvider.Cache.Get<object>(BuildKey(key));
return await Task.FromResult(val != null);
}
public async Task<T> GetOrSetAsync<T>(string key, Func<Task<T>> factory, TimeSpan? expiration = null)
{
var cacheKey = BuildKey(key);
var existed = _cacheProvider.Cache.Get<T>(cacheKey);
if (!EqualityComparer<T>.Default.Equals(existed, default)) return existed;
var data = await factory();
await SetAsync(key, data, expiration);
return data;
}
public async Task RefreshAsync(string key, TimeSpan expiration)
{
var cacheKey = BuildKey(key);
var val = _cacheProvider.Cache.Get<object>(cacheKey);
if (val != null) _cacheProvider.Cache.Add(cacheKey, val, (int)expiration.TotalSeconds);
await Task.CompletedTask;
}
public async Task<long> GetCacheSizeAsync()
{
// 暂无法获取容量,返回0
return await Task.FromResult(0L);
}
public async Task ClearAllAsync()
{
// 暂不提供全清功能
await Task.CompletedTask;
}
}
}
+80
View File
@@ -0,0 +1,80 @@
using System;
using System.Threading.Tasks;
namespace COMCMS.Web.Services
{
/// <summary>
/// 缓存服务接口
/// </summary>
public interface ICacheService
{
/// <summary>
/// 获取缓存值
/// </summary>
/// <typeparam name="T">数据类型</typeparam>
/// <param name="key">缓存键</param>
/// <returns>缓存值</returns>
Task<T> GetAsync<T>(string key);
/// <summary>
/// 设置缓存值
/// </summary>
/// <typeparam name="T">数据类型</typeparam>
/// <param name="key">缓存键</param>
/// <param name="value">缓存值</param>
/// <param name="expiration">过期时间</param>
/// <returns></returns>
Task SetAsync<T>(string key, T value, TimeSpan? expiration = null);
/// <summary>
/// 移除缓存
/// </summary>
/// <param name="key">缓存键</param>
/// <returns></returns>
Task RemoveAsync(string key);
/// <summary>
/// 根据模式移除缓存
/// </summary>
/// <param name="pattern">模式</param>
/// <returns></returns>
Task RemoveByPatternAsync(string pattern);
/// <summary>
/// 检查缓存是否存在
/// </summary>
/// <param name="key">缓存键</param>
/// <returns></returns>
Task<bool> ExistsAsync(string key);
/// <summary>
/// 获取或设置缓存
/// </summary>
/// <typeparam name="T">数据类型</typeparam>
/// <param name="key">缓存键</param>
/// <param name="factory">数据工厂方法</param>
/// <param name="expiration">过期时间</param>
/// <returns></returns>
Task<T> GetOrSetAsync<T>(string key, Func<Task<T>> factory, TimeSpan? expiration = null);
/// <summary>
/// 刷新缓存过期时间
/// </summary>
/// <param name="key">缓存键</param>
/// <param name="expiration">过期时间</param>
/// <returns></returns>
Task RefreshAsync(string key, TimeSpan expiration);
/// <summary>
/// 获取缓存大小
/// </summary>
/// <returns></returns>
Task<long> GetCacheSizeAsync();
/// <summary>
/// 清空所有缓存
/// </summary>
/// <returns></returns>
Task ClearAllAsync();
}
}
+9
View File
@@ -9,6 +9,7 @@ using COMCMS.Common;
using COMCMS.Web.Common; using COMCMS.Web.Common;
using COMCMS.Web.ExceptionHandler; using COMCMS.Web.ExceptionHandler;
using COMCMS.Web.Models; using COMCMS.Web.Models;
using COMCMS.Web.Services;
using Lib.Core.MiddlewareExtension.Extension; using Lib.Core.MiddlewareExtension.Extension;
using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
@@ -67,7 +68,13 @@ namespace COMCMS.Web
options.Cookie.HttpOnly = true; options.Cookie.HttpOnly = true;
}); });
// 绑定缓存设置
services.Configure<CacheSettings>(Configuration.GetSection("CacheSettings"));
// 响应缓存
services.AddResponseCaching();
services.AddSingleton<ICacheProvider, RedisCacheProvider>(); services.AddSingleton<ICacheProvider, RedisCacheProvider>();
// 缓存服务封装
services.AddSingleton<ICacheService, CacheService>();
//部分系统配置 //部分系统配置
services.Configure<SystemSetting>(Configuration.GetSection("SystemSetting")); services.Configure<SystemSetting>(Configuration.GetSection("SystemSetting"));
@@ -161,6 +168,8 @@ namespace COMCMS.Web
app.UseStaticHttpContext(); app.UseStaticHttpContext();
app.UseRouting(); app.UseRouting();
// 启用响应缓存
app.UseResponseCaching();
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();
+21 -1
View File
@@ -5,11 +5,31 @@
"Default": "Warning" "Default": "Warning"
} }
}, },
"RedisCache": "server=127.0.0.1;password=;db=2", "RedisCache": {
"ConnectionString": "server=127.0.0.1;password=;db=2",
"InstanceName": "COMCMS:",
"DefaultDatabase": 2,
"ConnectTimeout": 5000,
"SyncTimeout": 5000,
"AbortConnect": false,
"ConnectRetry": 3
},
"CacheSettings": {
"DefaultExpirationMinutes": 30,
"SystemConfigExpirationMinutes": 60,
"ArticleExpirationMinutes": 20,
"ProductExpirationMinutes": 20,
"CategoryExpirationMinutes": 120,
"UserExpirationMinutes": 15,
"OrderExpirationMinutes": 10,
"EnableResponseCaching": true,
"EnableDistributedCaching": true
},
"SystemSetting": { "SystemSetting": {
"FileAllowedExtensions": "zip,rar,7z,doc,docx,xls,xlsx,ppt,pptx,csv,pdf,txt,gz,gzip,gif,png,jpg,jpeg,bmp,avi,fla,flv,swf,mp4,mp3,mov,mid,mpg,mpeg,rm,rmvb,wma,wav,wmv", "FileAllowedExtensions": "zip,rar,7z,doc,docx,xls,xlsx,ppt,pptx,csv,pdf,txt,gz,gzip,gif,png,jpg,jpeg,bmp,avi,fla,flv,swf,mp4,mp3,mov,mid,mpg,mpeg,rm,rmvb,wma,wav,wmv",
"ImageAllowedExtensions": "gif,png,jpg,jpeg,bmp", "ImageAllowedExtensions": "gif,png,jpg,jpeg,bmp",
"MediaAllowedExtensions": "flv,mp4,mp3,wmv,swf,mov", "MediaAllowedExtensions": "flv,mp4,mp3,wmv,swf,mov",
"ImageExtensions": "jpg,jpeg,png,bmp,gif",
"COMCMSPrefixKey": "abc_", "COMCMSPrefixKey": "abc_",
"SignSalt": "comcms", "SignSalt": "comcms",
"JwtSecret": "comcms0b311362786dabe03af7b484ed032b91698a4eb9377687bd031d837082", "JwtSecret": "comcms0b311362786dabe03af7b484ed032b91698a4eb9377687bd031d837082",
+1
View File
@@ -53,6 +53,7 @@ COMCMS NETCORE版本,一个简单的CMS后台管理系统,带前台演示。
账号密码都是admin 账号密码都是admin
``` ```
### 技术交流群 ### 技术交流群
**1600800** **1600800**
+8 -8
View File
@@ -7,23 +7,23 @@
<!--SQL目录。设置SQL输出的单独目录,默认为空,SQL输出到当前日志中。生产环境建议输出到站点外单独的SqlLog目录--> <!--SQL目录。设置SQL输出的单独目录,默认为空,SQL输出到当前日志中。生产环境建议输出到站点外单独的SqlLog目录-->
<SQLPath></SQLPath> <SQLPath></SQLPath>
<!--SQL执行时间。跟踪SQL执行时间,大于该阀值将输出日志,默认1000毫秒--> <!--SQL执行时间。跟踪SQL执行时间,大于该阀值将输出日志,默认1000毫秒-->
<TraceSQLTime>1000</TraceSQLTime> <TraceSQLTime>2000</TraceSQLTime>
<!--SQL最大长度。输出日志时的SQL最大长度,超长截断,默认4096,不截断用0--> <!--SQL最大长度。输出日志时的SQL最大长度,超长截断,默认4096,不截断用0-->
<SQLMaxLength>4096</SQLMaxLength> <SQLMaxLength>4096</SQLMaxLength>
<!--参数化添删改查。默认关闭--> <!--参数化添删改查。默认关闭-->
<UseParameter>false</UseParameter> <UseParameter>true</UseParameter>
<!--命令超时。查询执行超时时间,默认0秒不限制--> <!--命令超时。查询执行超时时间,默认0秒不限制-->
<CommandTimeout>0</CommandTimeout> <CommandTimeout>30</CommandTimeout>
<!--失败重试。执行命令超时后的重试次数,默认0不重试--> <!--失败重试。执行命令超时后的重试次数,默认0不重试-->
<RetryOnFailure>0</RetryOnFailure> <RetryOnFailure>3</RetryOnFailure>
<!--数据层缓存。根据sql做缓存,默认0秒--> <!--数据层缓存。根据sql做缓存,默认0秒-->
<DataCacheExpire>0</DataCacheExpire> <DataCacheExpire>300</DataCacheExpire>
<!--实体缓存过期。整表缓存实体列表,默认10秒--> <!--实体缓存过期。整表缓存实体列表,默认10秒-->
<EntityCacheExpire>10</EntityCacheExpire> <EntityCacheExpire>600</EntityCacheExpire>
<!--单对象缓存过期。按主键缓存实体,默认10秒--> <!--单对象缓存过期。按主键缓存实体,默认10秒-->
<SingleCacheExpire>10</SingleCacheExpire> <SingleCacheExpire>600</SingleCacheExpire>
<!--扩展属性过期。扩展属性Extends缓存,默认10秒--> <!--扩展属性过期。扩展属性Extends缓存,默认10秒-->
<ExtendExpire>10</ExtendExpire> <ExtendExpire>300</ExtendExpire>
<!--反向工程。Off 关闭;ReadOnly 只读不执行;On 打开,仅新建;Full 完全,修改删除--> <!--反向工程。Off 关闭;ReadOnly 只读不执行;On 打开,仅新建;Full 完全,修改删除-->
<Migration>On</Migration> <Migration>On</Migration>
<!--表名称、字段名大小写格式。Default 根据模型生成;Upper 全大写;Lower 全小写;Underline下划线--> <!--表名称、字段名大小写格式。Default 根据模型生成;Upper 全大写;Lower 全小写;Underline下划线-->
+115
View File
@@ -0,0 +1,115 @@
# COMCMS_NETCORE 项目优化建议
## TODO 列表
- [ ] 安全性优化
- [ ] 1.1 登录加密算法 - 使用 .NET 内置 AES 替换自定义 DES 实现
- [ ] 1.2 JWT 密钥管理 - 使用环境变量或密钥管理服务
- [ ] 1.3 SQL 注入风险 - 优化 HomeController.DoInstall 中的 SQL 执行方式
- [ ] 性能优化
- [ ] 2.1 缓存策略 - 统一缓存访问接口,优化缓存过期策略
- [ ] 2.2 数据库查询优化 - 优化 ArticleController.Index 和 ProductController.Index 的分页查询
- [ ] 2.3 内存管理 - 移除 IndexController.DoMemoryFree 中的 SetProcessWorkingSetSize 调用
- [ ] 代码质量与可维护性
- [ ] 3.1 重复代码 - 提取公共方法处理栏目和详情查找逻辑
- [ ] 3.2 魔法字符串和数字 - 使用常量或枚举替代魔法值
- [x] 3.3 异常处理 - 为关键操作添加异常处理机制
- [x] 3.4 配置管理 - 将硬编码的配置项移至 appsettings.json
- [ ] 架构与设计
- [ ] 4.1 控制器职责 - 拆分 HomeController 的功能到不同控制器
- [ ] 4.2 业务逻辑与数据访问 - 封装业务逻辑到独立服务类
- [ ] 用户体验优化
- [ ] 5.1 响应式设计 - 考虑使用成熟 CSS 框架改进响应式设计
- [ ] 5.2 错误处理页面 - 设计更友好的错误页面
- [ ] 其他建议
- [ ] 6.1 日志记录 - 增强关键业务操作和异常处理的日志记录
- [ ] 6.2 单元测试 - 为关键业务逻辑和控制器添加单元测试
- [ ] 6.3 API 文档 - 提供完整的 API 文档
---
通过阅读项目代码,我对 COMCMS_NETCORE 项目有了较全面的了解。以下是我发现的一些可以优化的方面:
## 1. 安全性优化
### 1.1 登录加密算法
- **问题:** 登录使用的 `MyDES` 类是一个自定义的 DES 加密实现,代码冗长且可能存在安全隐患。
- **建议:** 使用 .NET 内置的加密库(如 `System.Security.Cryptography` 中的 AES)替换自定义 DES 实现,提高安全性和可维护性。
### 1.2 JWT 密钥管理
- **问题:** JWT 密钥直接存储在 `appsettings.json` 中,且默认值为固定字符串,存在安全风险。
- **建议:** 在生产环境中使用强随机生成的密钥,并通过环境变量或密钥管理服务进行管理,避免将密钥硬编码在配置文件中。
### 1.3 SQL 注入风险
- **问题:** 在 `HomeController.DoInstall` 方法中,直接将 SQL 文件内容作为字符串执行,存在潜在的 SQL 注入风险。
- **建议:** 对 SQL 内容进行严格验证和清理,或使用参数化查询等方式执行初始化 SQL。
## 2. 性能优化
### 2.1 缓存策略
- **现状:** 项目使用了 Redis 缓存,但在一些地方(如 `HomeController.Test`)直接使用了 `NewLife.Caching` 的默认缓存。
- **建议:**
- 统一缓存访问接口,确保所有缓存操作都通过配置的缓存提供者(如 Redis)进行。
- 检查并优化缓存过期策略,确保合理利用缓存提高性能。
### 2.2 数据库查询优化
- **问题:** 在 `ArticleController.Index` 和 `ProductController.Index` 中,获取分页数据时分别执行了 `FindCount` 和 `FindAll` 两次查询。
- **建议:** 优化为单次查询获取总数和数据列表,减少数据库访问次数。
### 2.3 内存管理
- **问题:** 在 `IndexController.DoMemoryFree` 中使用了 `SetProcessWorkingSetSize` API 来释放内存,这种方式在 .NET Core 中并不推荐。
- **建议:** 移除这部分代码,依赖 .NET Core 的垃圾回收机制进行内存管理,或使用更现代的内存优化技术。
## 3. 代码质量与可维护性
### 3.1 重复代码
- **问题:** 在 `HomeController.ShowCategory` 和 `HomeController.ShowDetail` 方法中,存在大量重复的路由匹配和处理逻辑。
- **建议:** 提取公共方法来处理栏目和详情的查找逻辑,减少代码重复。
### 3.2 魔法字符串和数字
- **问题:** 项目中存在多处魔法字符串和数字(如 `AdminLoginWithCode` 的值 "1" 表示需要验证码)。
- **建议:** 使用常量或枚举来替代这些魔法值,提高代码可读性和可维护性。
### 3.3 异常处理
- **问题:** 项目中部分关键操作缺少异常处理(如文件读写、数据库操作等)。
- **建议:** 为关键操作添加适当的异常处理机制,记录日志并提供友好的错误提示。
### 3.4 配置管理
- **问题:** 部分配置项(如文件扩展名白名单)直接写在代码中,而非从配置文件读取。
- **建议:** 将这些配置项移至 `appsettings.json`,通过 `IConfiguration` 读取,便于维护和修改。
## 4. 架构与设计
### 4.1 控制器职责
- **问题:** `HomeController` 承担了过多职责,包括首页展示、安装、路由处理等多个功能。
- **建议:** 将不同功能拆分到不同的控制器中,遵循单一职责原则。
### 4.2 业务逻辑与数据访问
- **问题:** 部分业务逻辑(如权限检查)直接在控制器中实现,与数据访问层耦合较紧。
- **建议:** 将业务逻辑封装到独立的服务类中,通过依赖注入在控制器中使用,提高代码的可测试性和可维护性。
## 5. 用户体验优化
### 5.1 响应式设计
- **问题:** 前端使用了 JavaScript 进行响应式处理,但代码较为简单,可能存在兼容性问题。
- **建议:** 考虑使用成熟的 CSS 框架(如 Bootstrap)来实现更完善的响应式设计。
### 5.2 错误处理页面
- **问题:** 错误处理页面较为简单,用户体验不佳。
- **建议:** 设计更友好的错误页面,提供清晰的错误信息和返回链接。
## 6. 其他建议
### 6.1 日志记录
- **建议:** 增强日志记录,特别是在关键业务操作和异常处理中,便于问题排查和系统监控。
### 6.2 单元测试
- **建议:** 为关键业务逻辑和控制器添加单元测试,提高代码质量和可维护性。
### 6.3 API 文档
- **建议:** 如果项目包含 API 接口,应提供完整的 API 文档,便于第三方集成和维护。