Posts in category “Programming”

什么是AOP?这种在运行时,动态地将代码切入到类的指定方法、指定位置上的编程思想就是面向切面的编程。

什么是AOP?这种在运行时,动态地将代码切入到类的指定方法、指定位置上的编程思想就是面向切面的编程。

https://www.zhihu.com/question/24863332

Caution: Javascript A || B expression is handy, but it also can cause tricky bug

I had written the following code in a project

   ...
   return s && s.value || null

It works well for some days until a colleague did some code refactoring. In the beginning, s.value is a string value, and an empty string is not a valid value, so the code works well. After the refactoring, s.value became an integer, and this time 0 is a valid value. So you can imagine when s.value === 0 the code above will return null instead of 0. It caused a bug!

Therefore please use the"A || B" expression with caution!

Vue.js Event modifier: .stop .prevent .passive .once .self .capture explanation

Two articles explain well this subject. One is in Chinese, the other is in English.

.NET Core 3.1 Swagger UI Tweaks

  1. Present enums as string. Modify your StartUp.cs, add the highlight part below:
             services.AddMemoryCache().AddMvcCore().AddJsonOptions(opts =>
                 {
                     opts.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
                 })
                 .AddDataAnnotationsLocalization();
    

  1. Enable XML Comments
    1. Manually add the two lines in PropertyGroup below to the .csproj file:
      <PropertyGroup>
        <GenerateDocumentationFile>true</GenerateDocumentationFile>
        <NoWarn>$(NoWarn);1591</NoWarn>
      </PropertyGroup>
      
    2. Add the options in the code below
           services.AddSwaggerGen(options =>
           {
               options.IncludeXmlComments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{AppDomain.CurrentDomain.FriendlyName}.xml"), true);
           });
      

SQLSugar: How to implement Count(FieldName) and GROUP BY in SQLSugar

            await Db.Queryable<Entity>().Where(_ => _.SampleFieldName== sampleFieldValue)
                .GroupBy("AnothterFieldNameInStringFormat")
                .Select<ResultModel>("AnotherFieldNameInStringFormat, Count(AnotherFieldNameInStringFormat) Total")
                .ToListAsync();