【ASP.NET MVC系列】淺談表單和HTML輔助方法

来源:https://www.cnblogs.com/wangjiming/archive/2018/01/21/8293965.html
-Advertisement-
Play Games

【01】淺談Google Chrome瀏覽器(理論篇) 【02】淺談Google Chrome瀏覽器(操作篇)(上) 【03】淺談Google Chrome瀏覽器(操作篇)(下) 【04】淺談ASP.NET框架 【05】淺談ASP.NET MVC運行過程 【06】淺談ASP.NET MVC 控制器 ...


【01】淺談Google Chrome瀏覽器(理論篇)

【02】淺談Google Chrome瀏覽器(操作篇)(上)

【03】淺談Google Chrome瀏覽器(操作篇)(下)

【04】淺談ASP.NET框架   

【05】淺談ASP.NET MVC運行過程    

【06】淺談ASP.NET MVC 控制器   

【07】淺談ASP.NET MVC 路由   

【08】淺談ASP.NET MVC 視圖 

【09】淺談ASP.NET MVC 視圖與控制器傳遞數據

【10】淺談jqGrid 在ASP.NET MVC中增刪改查     

【11】淺談ASP.NET 頁面之間傳值的幾種方式

【12】淺談緩存技術在ASP.NET中的運用       

【13】淺談NuGet在VS中的運用      

【14】淺談ASP.NET 程式發佈過程           

【15】淺談數據註解和驗證           

【16】淺談依賴註入

【17】淺談表單和HTML輔助方法

【18】淺談基於APS.NET身份驗證

【19】淺談ASP.NET MVC 模型

【20】淺談ASP.NET MVC 單元測試

【21】淺談ASP.NET MVC網路安全;

【22】淺談ASP.NET MVC八大類擴展

【23】再談ASP.NET MVC Routing

【24】淺談ASP.NET 高級話題

【25】淺談大型ASP.NET MVC項目(含DEMO)

【26】下一系列:ASP.NET WebAPI

一 概述

基於ASP.NET MVC基架開發模式中,我們很清楚View的擴展名:.cshtml,對該擴展名,不知是否有朋友研究過為啥將其如此命名?我且將它拆分成.cshtml=.cs(後臺代碼)+html(前端純html標簽代碼)。

我們知道,MVC的本質目的是儘量做到前後端分離,View這樣命名,是否有違背前後端分離這一原則呢?當然不是,相反,這樣做卻提高了代碼的復用性,提高了編程的效率。

那有什麼工具來解決該問題呢?HTML輔助方法。

本文將與大家分享HTML輔助方法,當然,HTML輔助方法是在表單上運用的,所以,我們會先大致提一些表單(Form)。HTML輔助方法,我們可大致歸結為基於ASP.NET MVC基架的HTML輔助方法和自定義的

HTML擴展方法,前者不作為本章的重點(因為非常簡單,使用時,只需調用相應的方法即可),後者才是本章的重點。

二 表單

關於表單的內容,將會從下圖的四個方面的來論述:

(1)WebFormb表單與MVC表單的比較

(2)表單提交的方式和url:action和method特性

(3)表單請求方式

(4)數據輸入的一般模式

(一)WebForm表單與MVC表單比較

1.WebForm表單主要是利用其強大的<form>標簽,而MVC並未完全利用<form>標簽;

2.WebForm主要利用伺服器端控制項,MVC主要利用基於MVC基架的HTML輔助方法,兩者都用HTML標簽

 3.WebForm頁面與後臺代碼強綁定,而MVC與後臺代碼松耦合

(1)WebForm中,每個頁面對應一個類,頁面淚繼承Page類,我們稱為頁面類,如上圖中Default頁面對應的類為_Default,

(2)每個頁面由三部分組成:前端代碼(Default.aspx),後臺代碼(Default.aspx.cs)和設計器(Default.aspx.designer.cs);

4.從性能上看,MVC比WebForm性能高。WebForm性能低的主要因素有如下幾點:

(1)伺服器端控制項,消耗帶寬,吃記憶體;

(2)ViewState垃圾數據; 

(二)表單提交的方式和url:action和method特性

action和method為<form>標簽兩個重要的特性

(1)action:指將<form>標簽提交到何處,本質就是一個url;

(2)method:提交form的方法,主要為post和get,預設為get;

(三)表單請求方式

表單請求方式,主要為post和get,預設為get;

(四)數據輸入的一般模式

 數據輸入模式,一般分為兩種模式:編輯-提交模式(Edit-and-Post)和選擇-編輯-提交模式(Selct-Edit-Post)

三 HTML輔助方法

基於ASP.NET MVC基架的HTML輔助方法,大致分為內置HTM輔助方法(也叫基於MVC基架的HTML輔助方法)和自定義HTML輔助方法。 

(一)基於MVC基架的HTML輔助方法

通過反彙編工具查看System.Web.Mvc.Html下的輔助方法,如下圖所以。

由於基於MVC基架的輔方法比較簡單,使用時只需調用即可,故本節不會花較大篇幅講解,只是大致提及一下。

1.我們隨便查看InputExtensions和LableExtensions輔助方法

InputExtensions

public static class InputExtensions
{
    // Methods
    public static MvcHtmlString CheckBox(this HtmlHelper htmlHelper, string name);
    public static MvcHtmlString CheckBox(this HtmlHelper htmlHelper, string name, bool isChecked);
    public static MvcHtmlString CheckBox(this HtmlHelper htmlHelper, string name, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString CheckBox(this HtmlHelper htmlHelper, string name, object htmlAttributes);
    public static MvcHtmlString CheckBox(this HtmlHelper htmlHelper, string name, bool isChecked, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString CheckBox(this HtmlHelper htmlHelper, string name, bool isChecked, object htmlAttributes);
    public static MvcHtmlString CheckBoxFor<TModel>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, bool>> expression);
    public static MvcHtmlString CheckBoxFor<TModel>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, bool>> expression, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString CheckBoxFor<TModel>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, bool>> expression, object htmlAttributes);
    private static MvcHtmlString CheckBoxHelper(HtmlHelper htmlHelper, ModelMetadata metadata, string name, bool? isChecked, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString Hidden(this HtmlHelper htmlHelper, string name);
    public static MvcHtmlString Hidden(this HtmlHelper htmlHelper, string name, object value);
    public static MvcHtmlString Hidden(this HtmlHelper htmlHelper, string name, object value, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString Hidden(this HtmlHelper htmlHelper, string name, object value, object htmlAttributes);
    public static MvcHtmlString HiddenFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression);
    public static MvcHtmlString HiddenFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString HiddenFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, object htmlAttributes);
    private static MvcHtmlString HiddenHelper(HtmlHelper htmlHelper, ModelMetadata metadata, object value, bool useViewData, string expression, IDictionary<string, object> htmlAttributes);
    private static MvcHtmlString InputHelper(HtmlHelper htmlHelper, InputType inputType, ModelMetadata metadata, string name, object value, bool useViewData, bool isChecked, bool setId, bool isExplicitValue, string format, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString Password(this HtmlHelper htmlHelper, string name);
    public static MvcHtmlString Password(this HtmlHelper htmlHelper, string name, object value);
    public static MvcHtmlString Password(this HtmlHelper htmlHelper, string name, object value, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString Password(this HtmlHelper htmlHelper, string name, object value, object htmlAttributes);
    public static MvcHtmlString PasswordFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression);
    public static MvcHtmlString PasswordFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString PasswordFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, object htmlAttributes);
    private static MvcHtmlString PasswordHelper(HtmlHelper htmlHelper, ModelMetadata metadata, string name, object value, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString RadioButton(this HtmlHelper htmlHelper, string name, object value);
    public static MvcHtmlString RadioButton(this HtmlHelper htmlHelper, string name, object value, bool isChecked);
    public static MvcHtmlString RadioButton(this HtmlHelper htmlHelper, string name, object value, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString RadioButton(this HtmlHelper htmlHelper, string name, object value, object htmlAttributes);
    public static MvcHtmlString RadioButton(this HtmlHelper htmlHelper, string name, object value, bool isChecked, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString RadioButton(this HtmlHelper htmlHelper, string name, object value, bool isChecked, object htmlAttributes);
    public static MvcHtmlString RadioButtonFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, object value);
    public static MvcHtmlString RadioButtonFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, object value, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString RadioButtonFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, object value, object htmlAttributes);
    private static MvcHtmlString RadioButtonHelper(HtmlHelper htmlHelper, ModelMetadata metadata, object model, string name, object value, bool? isChecked, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString TextBox(this HtmlHelper htmlHelper, string name);
    public static MvcHtmlString TextBox(this HtmlHelper htmlHelper, string name, object value);
    public static MvcHtmlString TextBox(this HtmlHelper htmlHelper, string name, object value, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString TextBox(this HtmlHelper htmlHelper, string name, object value, object htmlAttributes);
    public static MvcHtmlString TextBox(this HtmlHelper htmlHelper, string name, object value, string format);
    public static MvcHtmlString TextBox(this HtmlHelper htmlHelper, string name, object value, string format, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString TextBox(this HtmlHelper htmlHelper, string name, object value, string format, object htmlAttributes);
    public static MvcHtmlString TextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression);
    public static MvcHtmlString TextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString TextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, object htmlAttributes);
    public static MvcHtmlString TextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, string format);
    public static MvcHtmlString TextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, string format, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString TextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, string format, object htmlAttributes);
    private static MvcHtmlString TextBoxHelper(this HtmlHelper htmlHelper, ModelMetadata metadata, object model, string expression, string format, IDictionary<string, object> htmlAttributes);
    private static RouteValueDictionary ToRouteValueDictionary(IDictionary<string, object> dictionary);
}

LableExtensions

public static class LabelExtensions
{
    // Methods
    public static MvcHtmlString Label(this HtmlHelper html, string expression);
    public static MvcHtmlString Label(this HtmlHelper html, string expression, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString Label(this HtmlHelper html, string expression, object htmlAttributes);
    public static MvcHtmlString Label(this HtmlHelper html, string expression, string labelText);
    public static MvcHtmlString Label(this HtmlHelper html, string expression, string labelText, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString Label(this HtmlHelper html, string expression, string labelText, object htmlAttributes);
    internal static MvcHtmlString Label(this HtmlHelper html, string expression, string labelText, IDictionary<string, object> htmlAttributes, ModelMetadataProvider metadataProvider);
    internal static MvcHtmlString Label(this HtmlHelper html, string expression, string labelText, object htmlAttributes, ModelMetadataProvider metadataProvider);
    public static MvcHtmlString LabelFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression);
    public static MvcHtmlString LabelFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString LabelFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, object htmlAttributes);
    public static MvcHtmlString LabelFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, string labelText);
    public static MvcHtmlString LabelFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, string labelText, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString LabelFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, string labelText, object htmlAttributes);
    internal static MvcHtmlString LabelFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, string labelText, IDictionary<string, object> htmlAttributes, ModelMetadataProvider metadataProvider);
    internal static MvcHtmlString LabelFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, string labelText, object htmlAttributes, ModelMetadataProvider metadataProvider);
    public static MvcHtmlString LabelForModel(this HtmlHelper html);
    public static MvcHtmlString LabelForModel(this HtmlHelper html, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString LabelForModel(this HtmlHelper html, object htmlAttributes);
    public static MvcHtmlString LabelForModel(this HtmlHelper html, string labelText);
    public static MvcHtmlString LabelForModel(this HtmlHelper html, string labelText, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString LabelForModel(this HtmlHelper html, string labelText, object htmlAttributes);
    internal static MvcHtmlString LabelHelper(HtmlHelper html, ModelMetadata metadata, string htmlFieldName, string labelText = null, IDictionary<string, object> htmlAttributes = null);
}

2.在ASP.NET MVC5 高級編程(Jon Galloway,Brad Wilson,K.Scott Allen,David Matson 著 ,孫遠帥 譯) 中,作者將HTML輔助方法大致分為下圖幾類

(二)自定義的HTML輔助方法

關於自定義HTML輔助方法,主要從下圖五個角度講解。

1.為什麼要擴展輔助方法

(1)何為擴展?

從漢語字面意義理解,即在現有的基礎上進行修改(修改現有輔助方法)、增加(自定義MVC基架沒有的輔助方法)等操作。

(2)擴展的作用?

首先,從MVC基架現有的某些HTML輔助方法,其某些屬性,如樣式等無法滿足現有需求,需要擴展;

其次,現有需求的某些輔助方法,如Image輔助輔助方法,File輔助方法等,MVC基架並未提供,需要擴展;

最後,擴展的最終目的是提高代碼的復用,提高編碼效率;

2.用反彙編工具查看MVC源碼是如何擴展的

(1)我們查看MVC是如何定義強類型和弱類型的,以Html.Lable為例,我們容易得出三個結論:

1)程式集為System.Web.Mvc

2)命名空間為System.Web.Mvc.Html

3)弱類型方法名字直接為純html對應名字

4)強類型方法名字=若類型名字+For 

5)輔助方法的返回類型均為MvcHtmlString

(2)我們用反彙編工具查看一下

(3)總結

根據如上(1)(2)分析,我們知道定義一個HTML輔助方法的步驟

1)命名空間為System.Web.Mvc

2)弱類型方法名字直接為純html對應名字

3)強類型方法名字=若類型名字+For 

4)輔助方法的返回類型均為MvcHtmlString

3.擴展弱類型輔助方法

 1 //Image弱類型
 2 public static MvcHtmlString Image(this HtmlHelper helper, string id, string url, string width, string height, string alternateText, object htmlAttributes)
 3         {
 4             //創建img標簽
 5             TagBuilder imgTagBulider = new TagBuilder("img");
 6 
 7             //為img標簽添加屬性:id,url,alternateText,htmlAttributes
 8             imgTagBulider.GenerateId(id);
 9             imgTagBulider.MergeAttribute("src", url);
10             imgTagBulider.MergeAttribute("width", width);
11             imgTagBulider.MergeAttribute("height", height);
12             imgTagBulider.MergeAttribute("src", url);
13             imgTagBulider.MergeAttribute("alt", alternateText);
14             imgTagBulider.MergeAttributes(new RouteValueDictionary(htmlAttributes));
15 
16             // 輸出img標簽
17             return MvcHtmlString.Create(imgTagBulider.ToString());
18         }

4.擴展強類型輔助方法

 1  //Image強類型
 2 public static MvcHtmlString ImageFor<TModel, TValue>(this HtmlHelper<TModel> html,Expression<Func<TModel,TValue>> expression,string url, string width, string height, string alternateText, Dictionary<TModel, TValue> htmlAttributes)
 3         {
 4             string modelName = ExpressionHelper.GetExpressionText(expression);//從Lambda表達式中獲取模型對應屬性的名稱
 5             //創建img標簽
 6             TagBuilder imgTagBulider = new TagBuilder("img");
 7 
 8             //為img標簽添加屬性:id,url,alternateText,htmlAttributes
 9             imgTagBulider.GenerateId(modelName);
10             imgTagBulider.MergeAttribute("src", url);
11             imgTagBulider.MergeAttribute("width", width);
12             imgTagBulider.MergeAttribute("height", height);
13             imgTagBulider.MergeAttribute("src", url);
14             imgTagBulider.MergeAttribute("alt", alternateText);
15             imgTagBulider.MergeAttributes(new RouteValueDictionary(htmlAttributes));
16 
17             return MvcHtmlString.Create(imgTagBulider.ToString(TagRenderMode.SelfClosing));
18         }

 5.完整代碼

Index.cshtml

1 @model  HTMLHelperDemo.Models.UserInfo
2 
3 
4 <div>---------------Image弱類型擴展------------------</div>
5 <div>@Html.Image("ImageID", "/Images/hgspb.jpg", "300","300","自定義圖片",null)</div>
6 <div>---------------Image強類型擴展------------------</div>
7 <div>@Html.ImageFor(m=>m.UserName, "/Images/hgspb.jpg", "300", "300", "自定義圖片", null)</div>
8  
View Code

DefaultController

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.Mvc;
 6 
 7 namespace HTMLHelperDemo.Controllers
 8 {
 9     public class DefaultController : Controller
10     {
11         // GET: Default
12         public ActionResult Index()
13         {
14             return View();
15         }
16     }
17 }
View Code

MyHtmlHelperExtension.cs

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 
 6 using System.Web.Routing;
 7 using System.Linq.Expressions;
 8 namespace System.Web.Mvc
 9 {
10     public static class ImageExtensions
11     {
12         //Image弱類型
13         public static MvcHtmlString Image(this HtmlHelper helper, string id, string url, string width, string height, string alternateText, object htmlAttributes)
14         {
15             //創建img標簽
16             TagBuilder imgTagBulider = new TagBuilder("img");
17 
18             //為img標簽添加屬性:id,url,alternateText,htmlAttributes
19             imgTagBulider.GenerateId(id);
20             imgTagBulider.MergeAttribute("src", url);
21             imgTagBulider.MergeAttribute("width", width);
22             imgTagBulider.MergeAttribute("height", height);
23             imgTagBulider.MergeAttribute("src", url);
24             imgTagBulider.MergeAttribute("alt", alternateText);
25             imgTagBulider.MergeAttributes(new RouteValueDictionary(htmlAttributes));
26 
27             // 輸出img標簽
28             return MvcHtmlString.Create(imgTagBulider.ToString());
29         }
30         //Image強類型
31         public static MvcHtmlString ImageFor<TModel, TValue>(this HtmlHelper<TModel> html,Expression<Func<TModel,TValue>> expression,string url, string width, string height, string alternateText, Dictionary<TModel, TValue> htmlAttributes)
32         {
33             string modelName = ExpressionHelper.GetExpressionText(expression);//從Lambda表達式中獲取模型對應屬性的名稱
34             //創建img標簽
35             TagBuilder imgTagBulider = new TagBuilder("img");
36 
37             //為img標簽添加屬性:id,url,alternateText,htmlAttributes
38             imgTagBulider.GenerateId(modelName);
39             imgTagBulider.MergeAttribute("src", url);
40             imgTagBulider.MergeAttribute("width", width);
41             imgTagBulider.MergeAttribute("height", height);
42             imgTagBulider.MergeAttribute("src", url);
43             imgTagBulider.MergeAttribute("alt", alternateText);
44             imgTagBulider.MergeAttributes(new RouteValueDictionary(htmlAttributes));
45 
46             return MvcHtmlString.Create(imgTagBulider.ToString(TagRenderMode.SelfClosing));
47         }
48     }
49 }
50     
51  
View Code

圖解

 四  HTML輔助方法的工作原理

關於HTML輔助方法工做原理,這裡不做深入研討,只是描述一下工作原理的輪廓。

1.MVC中,View的尾碼為.cshtml,我們可以將其拆分為:.cshtml=.cs+html,即由後臺.cs代碼+html標簽構成;

2.既然View是由後臺代碼.cs+html標簽構成,那麼什麼標簽能滿足這兩個條件呢?HTML輔助方法。由此,我們知道HTML輔助方法扮演後臺代碼和前端HTML代碼的中間者,橋梁;

3.既然HTML代碼扮演後臺代碼和前端HTML橋梁,那麼其與後臺有哪些聯繫呢?

 (1)與Model的聯繫,如HTML強輔助方法,使用Lambda表達式

 (2)與Conteller聯繫,如Html.ActonLink

(3)與Route聯繫,如Html.RouteLink;

(4)與ModelState聯繫,如在驗證輸入值的合法性時,若驗證錯誤,錯誤消息存在模型狀態中,然後返回給Html相應的輔助方法

.......

4.我們知道了HTML輔助方法與後臺的聯繫,那麼與後臺聯繫之後,接下

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 其實這是一個偽標題,因為主要的重心不是安裝這個系統,而是怎樣讓它全屏顯示! 自己想在ubuntu下裝個Pycharm玩python,因此需要一個ubuntu系統鏡像,好吧,找路子去下載,但是別下各種來路不明的(可能有損壞!)。 很久沒用過這個虛擬機了,之前都是用的VMwork10,這次為了方便,用了 ...
  • 百度UMeditor富文本編輯器java使用 1.介紹 UMeditor 是一款輕量級的富文本編輯器,比UEditor要小得多,是為滿足廣大門戶網站對於簡單發帖框,或者回覆框需求所定製的線上富文本編輯器 2.下載 官網地址:http://ueditor.baidu.com/website/umedi ...
  • 上面只是做到讀取並寫入另一個文件,並沒有進行排序 下麵是排序的方法 ...
  • 題目描述 某人寫了n封信和n個信封,如果所有的信都裝錯了信封。求所有信都裝錯信封共有多少種不同情況。 輸入輸出格式 輸入格式: 一個信封數n(n<=20) 輸出格式: 一個整數,代表有多少種情況。 輸入輸出樣例 輸入樣例#1: 複製 2 輸出樣例#1: 複製 1 輸入樣例#1: 複製 2 輸出樣例# ...
  • Tomcat 是什麼 Tomcat 是由 Apache 開發的一個 Servlet 容器,實現了對 Servlet 和 JSP 的支持,並提供了作為Web伺服器的一些特有功能,如Tomcat管理和控制平臺、安全域管理和Tomcat閥等。 由於 Tomcat 本身也內含了一個 HTTP 伺服器,它也可 ...
  • 題目描述 HXY得到了一些卡片,這些卡片上標有數字0或5。現在她可以選擇其中一些卡片排成一列,使得排出的一列數字組成的數最大,且滿足被90整除這個條件。同時這個數不能含有前導0,即0不能作為這串數的首位。如果不能排出這樣的數,輸出“-1”。 輸入輸出格式 輸入格式: 第一行,卡片的個數n。 第二行, ...
  • 在當前的Java記憶體模型下,線程可以把變數保存在本地記憶體(比如機器的寄存器)中,而不是直接在主存中進行讀寫。這就可能造成一個線程在主存中修改了一個變數的值,而另外一個線程還繼續使用它在寄存器中的變數值的拷貝,造成數據的不一致。 在當前的Java記憶體模型下,線程可以把變數保存在本地記憶體(比如機器的寄存 ...
  • package com.swift; public class Bank_Customer_Test { public static void main(String[] args) { /* * 兩個客戶往一個銀行存錢,每人存三十次一次存一百。 模擬銀行存錢功能,時時銀行現金數。 */ Custo... ...
一周排行
    -Advertisement-
    Play Games
  • Dapr Outbox 是1.12中的功能。 本文只介紹Dapr Outbox 執行流程,Dapr Outbox基本用法請閱讀官方文檔 。本文中appID=order-processor,topic=orders 本文前提知識:熟悉Dapr狀態管理、Dapr發佈訂閱和Outbox 模式。 Outbo ...
  • 引言 在前幾章我們深度講解了單元測試和集成測試的基礎知識,這一章我們來講解一下代碼覆蓋率,代碼覆蓋率是單元測試運行的度量值,覆蓋率通常以百分比表示,用於衡量代碼被測試覆蓋的程度,幫助開發人員評估測試用例的質量和代碼的健壯性。常見的覆蓋率包括語句覆蓋率(Line Coverage)、分支覆蓋率(Bra ...
  • 前言 本文介紹瞭如何使用S7.NET庫實現對西門子PLC DB塊數據的讀寫,記錄了使用電腦模擬,模擬PLC,自至完成測試的詳細流程,並重點介紹了在這個過程中的易錯點,供參考。 用到的軟體: 1.Windows環境下鏈路層網路訪問的行業標準工具(WinPcap_4_1_3.exe)下載鏈接:http ...
  • 從依賴倒置原則(Dependency Inversion Principle, DIP)到控制反轉(Inversion of Control, IoC)再到依賴註入(Dependency Injection, DI)的演進過程,我們可以理解為一種逐步抽象和解耦的設計思想。這種思想在C#等面向對象的編 ...
  • 關於Python中的私有屬性和私有方法 Python對於類的成員沒有嚴格的訪問控制限制,這與其他面相對對象語言有區別。關於私有屬性和私有方法,有如下要點: 1、通常我們約定,兩個下劃線開頭的屬性是私有的(private)。其他為公共的(public); 2、類內部可以訪問私有屬性(方法); 3、類外 ...
  • C++ 訪問說明符 訪問說明符是 C++ 中控制類成員(屬性和方法)可訪問性的關鍵字。它們用於封裝類數據並保護其免受意外修改或濫用。 三種訪問說明符: public:允許從類外部的任何地方訪問成員。 private:僅允許在類內部訪問成員。 protected:允許在類內部及其派生類中訪問成員。 示 ...
  • 寫這個隨筆說一下C++的static_cast和dynamic_cast用在子類與父類的指針轉換時的一些事宜。首先,【static_cast,dynamic_cast】【父類指針,子類指針】,兩兩一組,共有4種組合:用 static_cast 父類轉子類、用 static_cast 子類轉父類、使用 ...
  • /******************************************************************************************************** * * * 設計雙向鏈表的介面 * * * * Copyright (c) 2023-2 ...
  • 相信接觸過spring做開發的小伙伴們一定使用過@ComponentScan註解 @ComponentScan("com.wangm.lifecycle") public class AppConfig { } @ComponentScan指定basePackage,將包下的類按照一定規則註冊成Be ...
  • 操作系統 :CentOS 7.6_x64 opensips版本: 2.4.9 python版本:2.7.5 python作為腳本語言,使用起來很方便,查了下opensips的文檔,支持使用python腳本寫邏輯代碼。今天整理下CentOS7環境下opensips2.4.9的python模塊筆記及使用 ...