目录:

  1. 自定义模型IModelBinder
  2. 自定义模型验证
  3. 自定义视图引擎
  4. 自定义Html辅助方法
  5. 自定义Razor辅助方法
  6. 自定义Ajax辅助方法
  7. 自定义控制器扩展
  8. 自定义过滤器
  9. 自定义ActionResult

自定义模型IModelBinder

IModelBinder主要解决的问题是,将请求的数据转换成需要的数据这部分逻辑进行了封装。比如说 http://localhost:4742/Person/Person/2 请求的参数Id是2,通过参数2,获得2相关的所有数据。

这样做的好处是:

  1. 使代码变得更加简洁
  2. 帮助我们获取HTTP请求中的数据
  3. 帮助我们完成必要的数据类型转换

Controller部分:

当访问http://localhost:4742/Person/Person?Name=admin&Age=12时,自动转换为setting对象

[HttpPost]
public ActionResult Person2([ModelBinder(typeof(SettingsBinder))]Settings settings)
{
return View("Person");
}

IModelBinder部分

SettingsBinder继承了IModelBinder,并实现了BindModel,通过controllerContext.HttpContext.Request获取请求,从请求中获取参数值,然后转换为对象

public class SettingsBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var request = controllerContext.HttpContext.Request;
// 从request中获取参数值
var name = request["Name"];
var age = request["Age"];
// 然后将参数值转为对象
var setting = new { Name = name, Age = age };
return setting;
}
}

注:当Person2([ModelBinder(typeof(SettingsBinder))]Settings settings)已存在时,不能再定义Person2方法

自定义验证

通过定义自定义验证特性类,实现View的模型验证,NotEqualTo即自定义验证

public class RegisterModel
{
[Required]
[StringLength(, MinimumLength = )] //加
[Display(Name = "用户名")]
public string UserName { get; set; } [NotEqualTo("UserName", ErrorMessage = "不能与用户名的值相同")]
public string OtherName { get; set; } // NotEqualTo 是自定义模型验证特性
}

NotEqualToAttribute继承了ValidationAttribute和IClientValidatable ,并实现了IsValid和GetClientValidationRules方法

通过NotEqualTo构造参数的值UserName,获得该对象对应该参数值的属性值,匹配属性的值和约束的值OtherName是否相等,然后返回结果信息

using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Web.Mvc; namespace MvcValidation.Extension
{
// ValidationAttribute 验证特性
// IClientValidatable 客户端验证接口(View视图验证)
public class NotEqualToAttribute : ValidationAttribute, IClientValidatable
{
public string OtherProperty { get; set; } // 构造参数
public NotEqualToAttribute(string otherProperty)
{
OtherProperty = otherProperty;
} // 验证方法
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
//从验证上下文中可以获取我们想要的的属性
var property = validationContext.ObjectType.GetProperty(OtherProperty);
if (property == null)
{
return new ValidationResult(string.Format(CultureInfo.CurrentCulture, "{0} 不存在", OtherProperty));
} //获取属性的值
var otherValue = property.GetValue(validationContext.ObjectInstance, null); // 判断并返回验证结果
if (object.Equals(value, otherValue))
{
return new ValidationResult(FormatErrorMessage(validationContext.DisplayName));
}
return null;
}
// 客户端验证
public System.Collections.Generic.IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
// 设置客户端验证结果信息
var rule = new ModelClientValidationRule
{
ValidationType = "notequalto",
ErrorMessage = FormatErrorMessage(metadata.GetDisplayName())
};
rule.ValidationParameters["other"] = OtherProperty;
yield return rule;
}
}
}

自定义视图引擎

系统提供了视图和视图引擎,我们需要了解它之后继承并重写它的逻辑。

/*
* 思路
* 1、控制器方法返回ActionResult是一个抽象类
* 2、ActionResult的其中一个子类ViewResult,正是她使用IView实例最终渲染出视图
* 3、需要自定义IView
* 4、IViewEngine管理着IView,同时也需要自定义IViewEngine
* 5、自定义IViewEngine是需要全局注册的
*/
//namespace System.Web.Mvc

    //public interface IView
//{
// 第一个参数ViewContext包含了需要被渲染的信息,被传递到前台的强类型Model也包含在其中。
// 第二个参数TextWriter可以帮助我们写出想要的html格式。
// void Render(ViewContext viewContent, TextWriter textWriter);
//}
//namespace System.Web.Mvc
//public interface IViewEngine
//{
// // FindPartialView:在当前控制器上下文ControllerContext中找到部分视图。
// System.Web.Mvc.ViewEngineResult FindPartialView(System.Web.Mvc.ControllerContext controllerContext, string partialViewName, bool useCache);
// // FindView:在当前控制器上下文ControllerContext中找到视图。
// System.Web.Mvc.ViewEngineResult FindView(System.Web.Mvc.ControllerContext controllerContext, string viewName, string masterName, bool useCache);
// // ReleaseView:释放当前控制器上下文ControllerContext中的视图。
// void ReleaseView(System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.IView view);
//}

我们将派生出它们的类,通过自定义视图引擎类实现渲染,并显示。
准备资源:

public class Student
{
public int Id { get; set; }
public string Name { get; set; }
public int Score { get; set; }
} public class DataAccess
{
List<Student> students = new List<Student>(); public DataAccess()
{
for (int i = ; i < ; i++)
{
students.Add(new Student()
{
Id=i+,
Name="Name"+Convert.ToString(i+),
Score = i+
});
}
} public List<Student> GetStudents()
{
return students;
}
}

自定义扩展

public class StudentView : IView
{
/// <summary>
/// 渲染
/// 通过获得视图上下文数据,然后自定义输出格式通过TextWriter输出数据
/// </summary>
/// <param name="viewContent"></param>
/// <param name="writer"></param>
public void Render(ViewContext viewContent, TextWriter writer)
{
// 从视图上下文ViewContext拿到model
var model = viewContent.ViewData.Model;
var students=model as List<Student>;
// 自定义输出视图的html格式
writer.Write("<table border=1><tr><th>编号</th><th>名称</th><th>分数</th></tr>");
foreach (Student stu in students)
{
writer.Write("<tr><td>" + stu.Id + "</td><td>" + stu.Name + "</td><td>" + stu.Score + "</td></tr>");
}
writer.Write("</table>");
}
} public class StudentViewEngine : IViewEngine
{
//呈现部分视图
public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache)
{
throw new NotImplementedException();
}
//呈现视图
public ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
{
if (viewName == "StudentView")
{
// 呈现自定义视图
return new ViewEngineResult(new StudentView(), this);
}
else
{
return new ViewEngineResult(new string[] { "针对Student的视图还没创建!" });
}
}
//显示视图
public void ReleaseView(ControllerContext controllerContext, System.Web.Mvc.IView view)
{ }
}

至此自定义视图引擎完成。接下来我们进行调用:
我们只需要在View中指定自定义视图的名称即可。

public ActionResult Index()
{
var students = new DataAccess().GetStudents();
ViewData.Model = students; return View("StudentView");
}

设置默认的,全局的视图引擎
只需要添加ViewEngines.Engines.Add(new StudentViewEngine());即可实现。

protected void Application_Start()
{
AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes); ViewEngines.Engines.Add(new StudentViewEngine());
}

自定义HtmlHelper辅助方法

定义扩展方法类和扩展方法

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc; // 设置命名空间为统一的Html命名空间
namespace System.Web.WebPages.Html
{
// 设置静态类
public static class HtmlExtensions
{
// 为HtmlHelper类提辅助方法Img,参数为src和alt
public static MvcHtmlString Img(this HtmlHelper html,string src,string alt)
        {
            return MvcHtmlString.Create("<img src=\"" + src + "\" alt=\"" + alt + "\" />");
        }
}
}

在View页面中调用该扩展方法

@* 调用Img方法,前者为src,后者为alt,生成的结果是:<img src="C:\images\btn.ico\" alt="" /> *@
@Html.Img("C:\\images\\btn.ico","")

自定义Razor辅助方法

在MVC项目根目录下新建一个文件夹名为:App_Code,用于存放MyHelpers.cshtml

编写MyHelpers.cshtml内容如下:

相当于定义了MyHelpers.li(List<string> arrays)方法,通过关键字helper进行声明,这样其他的cshtml页面都可以访问该方法

@helper li(List<string> arrays) {
<ul>
@foreach (var item in arrays)
{
<li>@(item)</li>
}
</ul>
}

cshtml页面访问li方法

Index.cshtml页面调用:

@MyHelpers.li(new List<string>() { "甲","乙","丙","丁"})

页面输出结果:

自定义AjaxHelper辅助方法

与HtmlHelper扩展一样,为AjaxHelper扩展一个方法Textbox,并设置相应的属性

public static class HtmlExtensions
{
// 为HtmlHelper类提辅助方法Img,参数为src和alt
public static MvcHtmlString Img(this HtmlHelper html, string src, string alt)
{
return MvcHtmlString.Create("<img src=\"" + src + "\" alt=\"" + alt + "\" />");
} public static MvcHtmlString Textbox(this AjaxHelper ajaxHelper, string name, AjaxOptions ajaxOptions, object htmlAttributes)
{
// 设置标签名
var tag = new TagBuilder("input");
// 设置属性值
tag.MergeAttribute("name", name);
tag.MergeAttribute("type", "text"); tag.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
tag.MergeAttributes((ajaxOptions ?? new AjaxOptions()).ToUnobtrusiveHtmlAttributes());
tag.MergeAttribute("value", "自定义Ajax扩展");
// 输出Html
return MvcHtmlString.Create(tag.ToString(TagRenderMode.Normal));
}
}

View调用:

@Ajax.Textbox("search",
new AjaxOptions
{
Url = @Url.Action("GetTime"),
UpdateTargetId = "divTime",
InsertionMode = InsertionMode.Replace
},
new { size = })

输出结果:
输出结果的源码:

<input data-ajax="true" data-ajax-mode="replace" data-ajax-update="#divTime" data-ajax-url="/AjaxHelperExt/GetTime" name="search" size="50" type="text" value="自定义Ajax扩展"></input>

自定义UrlHelper辅助方法

略.

自定义控制器扩展BaseController

//  BaseController  针对Controller进行重写
// 并且提供了一些公用的方法如权限校验,Action跳转、日志记录等
public class BaseController : Controller
{ protected override void OnException(ExceptionContext filterContext)
{
// 处理异常
base.OnException(filterContext);
} protected override void Initialize(RequestContext requestContext)
{
// 处理初始化信息,如Cookie,Session等缓存信息
base.Initialize(requestContext);
} protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
// 在调用操作方法前调用
base.OnActionExecuting(filterContext);
} protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
// 在调用操作方法后调用
base.OnActionExecuted(filterContext);
} }

自定义过滤器

原文

路由访问过滤器

/// <summary>
/// 路由访问过滤器
/// </summary>
public class SystemIActionFilter : IActionFilter
{
//
// Summary:
// Called after the action method is invoked.
// 在Action返回之后
// Parameters:
// filterContext:
// Information about the current request and action.
public void OnActionExecuted(ActionExecutedContext filterContext)
{
}
//
// Summary:
// Called before the action method is invoked.
// 在进入Action之前
// 说明:使用RedirectToRouteResult进行路由值进行重定向时
// RouteName 路由名称
// RouteValues 路由值 特别注意第三个值 Permanent 获取一个值
// 该值指示重定向是否应为永久重定向 如果为true 在本程序会出现问题
// Parameters:
// filterContext:
// Information about the current request and action.
public void OnActionExecuting(ActionExecutingContext filterContext)
{
//验证 控制器 视图
string tempAction = filterContext.RouteData.Values["action"].ToString();
string tempController = filterContext.RouteData.Values["controller"].ToString();
string tempLoginAction = filterContext.RouteData.Values["action"].ToString(); if (tempAction == "HomeLogin" && tempController == "Home" || tempLoginAction == "UserLogin" ? false : true)
{
//请求登录时
if (tempAction == "UserLogin" && tempController == "Home" ? false : true)
{
//Cookie
HttpCookie tempToken = filterContext.HttpContext.Request.Cookies["exclusiveuser_token"];
if (tempToken == null)
{
filterContext.Result = new RedirectToRouteResult("HomeLogin", new RouteValueDictionary(new { controller = "Home", action = "HomeLogin" }), false);
}
//登录token不为null时 进行合法性验证token 头部,载荷,签名,cookie过期时间
if (tempToken == null ? false : true)
{
//UserToken 方法 将验证 token 合法性 包括token 签名 ,token载荷,cookie 过期时间等
//string SystemToken = new SecondTrackToken().UserToken();
//if (SystemToken == null)
//{
// filterContext.Result = new RedirectToRouteResult("HomeLogin", new RouteValueDictionary(new { controller = "Home", action = "HomeLogin" }), false);
//};
}
}
}
}
}

路由访问过滤器

异常处理过滤器

/// <summary>
/// 异常处理过滤器
/// </summary>
public class SystemIExceptionFilter : IExceptionFilter
{
void IExceptionFilter.OnException(ExceptionContext filterContext)
{
Exception exception = filterContext.Exception;
if (filterContext.ExceptionHandled)
{
return;
}
HttpException http = new HttpException(null, exception);
/*
* filterContext.Exception.Message 错误信息
*/
string messager = filterContext.Exception.Message; /*
* 错误日志
*/
//Log4NetHelp help = new Log4NetHelp();
//help.ErrorString(filterContext.Exception.Message);
/*
* 设置自定义异常已经处理,避免其他过滤器异常覆盖
*/
filterContext.ExceptionHandled = true; /*
* 在派生类重写时,设置或者重写一个值该值指定是否禁用ISS7.0中自定义错误
*/
filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
}
}

异常处理过滤器

授权处理(获取客户端信息)

public class SystemIAuthorizationFilter : IAuthorizationFilter
{
void IAuthorizationFilter.OnAuthorization(AuthorizationContext filterContext)
{
//当前操作计算机用户
string pcName = ((System.Web.HttpServerUtilityWrapper)((System.Web.HttpContextWrapper)filterContext.RequestContext.HttpContext).Server).MachineName;
//视图
string action = ((System.Web.Mvc.ReflectedActionDescriptor)filterContext.ActionDescriptor).ActionName;
//控制器
string controller = ((System.Web.Mvc.ReflectedActionDescriptor)filterContext.ActionDescriptor).ControllerDescriptor.ControllerName;
//请求时间
string time = filterContext.RequestContext.HttpContext.Timestamp.ToString();
//请求相对路径
string absturl = ((System.Web.UnvalidatedRequestValuesWrapper)((System.Web.HttpRequestWrapper)((System.Web.HttpContextWrapper)filterContext.RequestContext.HttpContext).Request).Unvalidated).Url.AbsoluteUri;
//状态
string code = ((System.Web.HttpResponseWrapper)((System.Web.HttpContextWrapper)filterContext.RequestContext.HttpContext).Response).Status;
// 浏览器版本
string browser = ((System.Web.HttpBrowserCapabilitiesWrapper)((System.Web.HttpRequestWrapper)((System.Web.HttpContextWrapper)filterContext.RequestContext.HttpContext).Request).Browser).Type;
//请求方式
string gepPost = ((System.Web.HttpRequestWrapper)((System.Web.Mvc.Controller)filterContext.Controller).Request).RequestType;
//本地主机名称解析DNS本身处理。
string server = ((System.Web.HttpRequestWrapper)((System.Web.HttpContextWrapper)filterContext.HttpContext).Request).UserHostAddress;
#region server 说明
/*
* 版权(c)1993 - 2009微软(msft . o:行情)。
*
* 这是一个示例所使用的主机文件微软为Windows TCP / IP。
*
* 这个文件包含IP地址到主机名的映射。
每一个
* 条目应该保存在单个行。
IP地址应
*被放置在第一列对应的主机名。
*的IP地址和主机名应该由至少一个
*空间。
*
*此外,评论(这样的)可能是插入的个人
*线或后机器名称用“*”符号。
*
例如:
*
* 102.54.94.97 rhino.acme.com源服务器
* 38.25.63.10 x.acme.com x客户机主机 *本地主机名称解析DNS本身处理。
* 127.0.0.1 localhost
*::1 localhost
*/
#endregion
//用户
//部门
//职位 }
}

授权处理过滤器

自定义属性过滤器

public class CheckLogin: ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
HttpCookieCollection CookieCollect = System.Web.HttpContext.Current.Request.Cookies;
if (CookieCollect["username"] == null || CookieCollect["password"] == null)
{
filterContext.Result = new RedirectResult("/Home/Login");
}
else
{
if (CookieCollect["username"].Value != "admin" && CookieCollect["password"].Value != "")
{
filterContext.Result = new RedirectResult("/Home/Login");
}
}
}
}

检查登录的过滤器

过滤器定义好后,需要在过滤器配置类FilterConfig中添加

public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute()); //将自定义异常过滤器的优先级提高,防止异常被默认的HandleError处理(也可以自定义类重写HandleErrorAttribute 实现错误处理)
filters.Add(new SystemIExceptionFilter(), 1);
//控制器过滤器
filters.Add(new SystemIActionFilter(), 2);
//授权过滤器
filters.Add(new SystemIAuthorizationFilter(), );
        //  自定义属性过滤器
            filters.Add(new CheckLogin());
}
}

自定义属性过滤器在控制器中调用:
在方法的上面加上特性:CheckLogin,当调用该方法时会先进行过滤再执行下面的逻辑。

 [CheckLogin]
public ActionResult About()
{ ViewBag.Message = "Your application description page."; return View();
}

自定义ActionResult

扩展的ActionResult,继承自ActionResult,需要重写ExecuteResult方法,通过构造函数传入参数值,

使用ExecuteResult方法的ControllerContext上下文获得HttpResponse,HttpResponse使用输出参数值结果。

 /// <summary>
/// 自定义JObject返回结果
/// </summary>
public class JObjectActionResult : ActionResult
{
/// <summary>
/// 结果集
/// </summary>
public JObject JObject
{
get;
set;
} public Encoding ContentEncoding
{
get;
set;
} public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
HttpResponseBase response = context.HttpContext.Response;
response.ContentType = "application/json";
if (ContentEncoding != null)
{
response.ContentEncoding = ContentEncoding;
}
if (JObject != null)
{
response.Write(JObject.ToString());
}
}
}

JObjectActionResult

通过response.Write(JObject.ToString());最后输出结果。
接下来我们看看调用:

public ActionResult Index()
{
return View();
}

默认的View()是Controller.View()的方法,因此我们为Controller类扩展一个方法。定义扩展内容如下:

public static class JObjectActionResultExtensions
{
public static JObjectActionResult JObjectResult(this Controller controller, JObject obj)
{
return new JObjectActionResult { JObject = obj };
} public static JObjectActionResult JObjectResult(this Controller controller, bool success)
{
JObject obj = new JObject();
obj.Add("success", success);
if (success)
{
obj.Add("code", );
obj.Add("msg", "Success!");
}
else
{
obj.Add("code", );
obj.Add("msg", "Error!");
}
return JObjectResult(controller, obj);
} public static JObjectActionResult JObjectResult(this Controller controller, bool success, int code, string msg)
{
JObject obj = new JObject();
obj.Add("success", success);
obj.Add("code", code);
obj.Add("msg", msg);
return JObjectResult(controller, obj);
}
}

JObjectActionResult的扩展

控制器中调用输出:
使用this关键字调用JObjectResult即可输出结果。

public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return this.JObjectResult(true);
}

接下来我们再扩展一个序列化的Result.

/// <summary>
/// 泛型的序列化结果
/// </summary>
/// <typeparam name="TData"></typeparam>
public class CustomView<TData> : ActionResult where TData:class,new()
{
/// <summary>
/// 构造函数传入参数
/// </summary>
/// <param name="t"></param>
public CustomView(TData t) { data = t; }
public TData data; protected JsonSerializerSettings SerializerSettings; protected void InitSerialization(ControllerContext context)
{
HttpResponseBase response = context.HttpContext.Response;
response.ContentType = "text/html";
if (SerializerSettings == null)
{
SetSerializerSettings();
}
response.Write(JsonConvert.SerializeObject(data, Formatting.None, SerializerSettings));
} protected virtual void SetSerializerSettings()
{
SerializerSettings = new JsonSerializerSettings
{
Converters = new List<JsonConverter>
{
new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd hh:mm" }
}
};
} public override void ExecuteResult(ControllerContext context)
{
InitSerialization(context);
}
}

CustomView

调用它,只需要实例化一下就行了。

public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
User u = new Models.User();
return new CustomView<User>(u);
}

下载地址

大家还有什么好的扩展方法,可以回复该帖哦。

Asp.Net Mvc 自定义扩展的更多相关文章

  1. asp.net mvc 自定义pager封装与优化

    asp.net mvc 自定义pager封装与优化 Intro 之前做了一个通用的分页组件,但是有些不足,从翻页事件和分页样式都融合在后台代码中,到翻页事件可以自定义,再到翻页和样式都和代码分离, 自 ...

  2. ASP.NET MVC 自定义Razor视图WorkContext

    概述 1.在ASP.NET MVC项目开发的过程中,我们经常需要在cshtml的视图层输出一些公用信息 比如:页面Title.服务器日期时间.页面关键字.关键字描述.系统版本号.资源版本号等 2.普通 ...

  3. ASP.NET MVC 自定义路由中几个需要注意的小细节

    本文主要记录在ASP.NET MVC自定义路由时,一个需要注意的参数设置小细节. 举例来说,就是在访问 http://localhost/Home/About/arg1/arg2/arg3 这样的自定 ...

  4. Asp.net Mvc 自定义Session (二)

    在 Asp.net Mvc 自定义Session (一)中我们把数据缓存工具类写好了,今天在我们在这篇把 剩下的自定义Session写完 首先还请大家跟着我的思路一步步的来实现,既然我们要自定义Ses ...

  5. Asp.net mvc 自定义全局的错误事件HandleErrorAttribute无效

    Asp.net mvc 自定义全局的错误事件HandleErrorAttribute,结果无效, 原因: 1.没有在RegisterGlobalFilters 里面添加或者你要的位置添加. 2.你把这 ...

  6. ASP.NET MVC自定义验证Authorize Attribute(包含cookie helper)

    前几天Insus.NET有在数据库实现过对某一字段进行加密码与解密<使用EncryptByPassPhrase和DecryptByPassPhrase对MS SQLServer某一字段时行加密和 ...

  7. asp.net MVC 自定义模型绑定 从客户端中检测到有潜在危险的 Request.QueryString 值

    asp.net mvc 自定义模型绑定 有潜在的Requset.Form 自定义了一个模型绑定器.前端会传过来一些敏感字符.调用bindContext. valueProvider.GetValue( ...

  8. 13个 ASP.NET MVC 的扩展

    ASP.NET MVC设计的主要原则之一是可扩展性.处理管线(processing pipeline)上的所有(或大多数)东西都是可替换的.因此,如果您不喜欢ASP.NET MVC所使用的约定(或缺乏 ...

  9. 【asp.net mvc】 扩展 htmlhelper 实现分页

    参考文档:http://www.cnblogs.com/caofangsheng/p/5670071.html                  http://www.cnblogs.com/arte ...

随机推荐

  1. centos7.2环境中kettle环境搭建及任务推送配置详解

    目标:将mysql5.5中testdb1的ehr_user表推送到tdoa的ehr_user表中,为避免不必要的麻烦,两张表结构.编码,包括数据库编码保持一致 操作系统:centos7.2 kettl ...

  2. Ex 5_28 Alice想要举办一个舞会..._第十次作业

    根据总人数建立顶点数量为总人数的无向图,顶点之间有边相连表示两个人相互认识,没有边则表示不认识.对于每一个顶点v,设d(v)表示顶点的度,若d(v)<5,即v认识的人数少于5,则不邀请v,若d( ...

  3. vue系列之获取多选框中被选中的值

    多个勾选框,绑定到同一个数组: <input type="checkbox" id="jack" value="Jack" v-mod ...

  4. OCM_第十八天课程:Section8 —》RAC 数据库 _ RAC DB 搭建/RAC DB 配置使用

    注:本文为原著(其内容来自 腾科教育培训课堂).阅读本文注意事项如下: 1:所有文章的转载请标注本文出处. 2:本文非本人不得用于商业用途.违者将承当相应法律责任. 3:该系列文章目录列表: 一:&l ...

  5. keras2.0的一些变化

    keras 变化太快了https://github.com/fchollet/keras/wiki/Keras-2.0-release-notes

  6. react之shouldComponentUpdate简单定制数据更新

    import React from 'react' class Demo extends React.Component{ constructor(props){ super(props) this. ...

  7. Innodb引擎下mysql自身配置优化

    1.简单介绍InnoDB给MySQL提供了具有提交,回滚和崩溃恢复能力的事务安全(ACID兼容)存储引擎.InnoDB锁定在行级并且也在SELECT语句提供一个Oracle风格一致的非锁定读.这些特色 ...

  8. Python的字符串内建函数(字符串处理)

    Python的字符串内建函数这些方法实现了string模块的大部分方法 , 如下表硕士列出了目前字符串内建支持的方法 string = 'XXX' string.capitalize() # 把字符串 ...

  9. windows Service程序的安装、启动、卸载命令

    安装:%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe ServiceTest.exe 启动:Net Start serv ...

  10. django 如何动态使用Q查询函数

    这个Q和F用得少, 需要时,总是独立的存在于那时,显得有些突兀, 这次想将filter,order,Q集合在一起, 查询了很多资料,还是有一些困难, 但即可以将Q查询比较优雅的动态生成. 比如: # ...