标签:博客 使用 select list 写法 方法 hmm types initial
老张
public class BlogArticle
{
/// <summary>
/// 主键
/// </summary>
/// 这里之所以没用RootEntity,是想保持和之前的数据库一致,主键是bID,不是Id
[SugarColumn(IsNullable = false, IsPrimaryKey = true, IsIdentity = true)]
public int bID { get; set; }
/// <summary>
/// 创建人
/// </summary>
[SugarColumn(Length = 60, IsNullable = true)]
public string bsubmitter { get; set; }
/// <summary>
/// 标题blog
/// </summary>
[SugarColumn(Length = 256, IsNullable = true)]
public string btitle { get; set; }
/// <summary>
/// 类别
/// </summary>
[SugarColumn(Length = int.MaxValue, IsNullable = true)]
public string bcategory { get; set; }
/// <summary>
/// 内容
/// </summary>
[SugarColumn(IsNullable = true, ColumnDataType = "text")]
public string bcontent { get; set; }
/// <summary>
/// 访问量
/// </summary>
public int btraffic { get; set; }
/// <summary>
/// 评论数量
/// </summary>
public int bcommentNum { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public DateTime bUpdateTime { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public System.DateTime bCreateTime { get; set; }
/// <summary>
/// 备注
/// </summary>
[SugarColumn(Length = int.MaxValue, IsNullable = true)]
public string bRemark { get; set; }
/// <summary>
/// 逻辑删除
/// </summary>
[SugarColumn(IsNullable = true)]
public bool? IsDeleted { get; set; }
}
关键的一些知识点,注释中已经说明了,主要是有以下:
1、继承接口IInterceptor
2、实例化接口IINterceptor的唯一方法Intercept
3、void Proceed();表示执行当前的方法和object ReturnValue { get; set; }执行后调用,object[] Arguments参数对象
4、中间的代码是新建一个类,还是单写,就很随意了。
/// <summary>
/// 拦截器BlogLogAOP 继承IInterceptor接口
/// </summary>
public class BlogLogAOP : IInterceptor
{
/// <summary>
/// 实例化IInterceptor唯一方法
/// </summary>
/// <param name="invocation">包含被拦截方法的信息</param>
public void Intercept(IInvocation invocation)
{
//记录被拦截方法信息的日志信息
var dataIntercept = $"{DateTime.Now.ToString("yyyyMMddHHmmss")} " +
$"当前执行方法:{ invocation.Method.Name} " +
$"参数是: {string.Join(", ", invocation.Arguments.Select(a => (a ?? "").ToString()).ToArray())} \r\n";
//在被拦截的方法执行完毕后 继续执行当前方法
invocation.Proceed();
dataIntercept += ($"被拦截方法执行完毕,返回结果:{invocation.ReturnValue}");
#region 输出到当前项目日志
var path = Directory.GetCurrentDirectory() + @"\Log";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
string fileName = path + $@"\InterceptLog-{DateTime.Now.ToString("yyyyMMddHHmmss")}.log";
StreamWriter sw = File.AppendText(fileName);
sw.WriteLine(dataIntercept);
sw.Close();
#endregion
}
}
标签:博客 使用 select list 写法 方法 hmm types initial
原文地址:https://www.cnblogs.com/yang315/p/14514840.html