1、巧用select where orderby 等方式。
将复杂的for循环和foreach循环提炼在
List<Math_Deptinfo> list = bLL_Deptinfo.Search(start, length, out total, where); List<UI_Math_Deptinfo> listUIRoleModel = new List<UI_Math_Deptinfo>(); foreach (Math_Deptinfo item in list) { UI_Math_Deptinfo uIRoleModel = Mapper.Map<UI_Math_Deptinfo>(item); listUIRoleModel.Add(uIRoleModel); }
list.Select(item => Mapper.Map<UI_Math_Deptinfo>(item)).ToList();
2、将一些常量代码,进行static优化。
#region 操作上的称呼 /// <summary> /// 操作上的称呼 /// </summary> public class OpCommonString { public static string DeleteSuccess = "删除成功"; public static string DeleteFail = "删除失败"; public static string InsertSuccess = "录入成功"; public static string InsertFail = "录入失败"; public static string UpdateSuccess = "更新成功"; public static string UpdateFail = "更新失败"; public static string Executing = "程序正在处理......"; public static string ExecutedSuccess = "处理成功"; public static string ExecutedError = "处理失败"; } #endregion
3、能用字典,不用对象。
4、能在maper里面配置,不在for循环里自己赋值。
5、接口数据尽量简洁,前端可以用computered进行加工。
原文地址:https://www.cnblogs.com/sexintercourse/p/12194558.html
时间: 2024-10-10 14:53:36