第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

發(fā)現(xiàn) MODEL 層 很是 麻煩,所以改寫了下,代碼如下,不曉得合適不,求指點(diǎn)

發(fā)現(xiàn) MODEL 層 很是 麻煩,所以改寫了下,代碼如下,不曉得合適不,求指點(diǎn)

千巷貓影 2018-12-06 22:53:17
MODE 層 代碼 namespace MODEL{ public class Article { int _ID=0; int _CID=0;//類別ID string _Title="";//標(biāo)題 DateTime _AddDate=DateTime.Now;//添加日期 string _Content="";//內(nèi)容 int _Hits=0;//點(diǎn)擊次數(shù) int _Count=0;//評論次數(shù) public Article() { } //數(shù)據(jù)庫記錄實(shí)例化為 Article,這個地方 從數(shù)據(jù)庫 讀出一條記錄后 可以 直接實(shí)例化 MODEL,不需要 在 一個個去寫 public Article(DataRow dataRow) { DataColumnCollection DCC = dataRow.Table.Columns; if (DCC.Contains("id")) { _ID = DataHelper.Int(dataRow["id"]); } if (DCC.Contains("cid")) { _CID = DataHelper.Int(dataRow["cid"]); } if (DCC.Contains("hits")) { _Hits = DataHelper.Int(dataRow["hits"]); } if (DCC.Contains("count")) { _Count = DataHelper.Int(dataRow["count"]); } if (DCC.Contains("adddate")) { _AddDate = DataHelper.dateTime(dataRow["adddate"]); } if (DCC.Contains("title")) { _Title = DataHelper.String(dataRow["title"] ); } if (DCC.Contains("content")) { _Content =DataHelper.String( dataRow["content"] ); } } //外部接受過來的數(shù)據(jù)實(shí)例化類 使用 hashTable 構(gòu)造 類 public Article(Hashtable hashtable) { if (hashtable.Contains("id")) { _ID = DataHelper.Int(hashtable["id"]); } if (hashtable.Contains("cid")) { _CID = DataHelper.Int(hashtable["cid"]); } if (hashtable.Contains("hits")) { _Hits = DataHelper.Int(hashtable["hits"]); } if (hashtable.Contains("count")) { _Count = DataHelper.Int(hashtable["count"]); } if (hashtable.Contains("adddate")) { _AddDate = DataHelper.dateTime(hashtable["adddate"]); } if (hashtable.Contains("title")) { _Title = DataHelper.String(hashtable["title"] ); } if (hashtable.Contains("content")) { _Content = DataHelper.String(hashtable["content"] ); } } public Article(int id,int cid,string title,DateTime addDate,string content,int hits,int count) { _ID = id; _CID = cid; _Title = title; _AddDate = addDate; _Content = content; _Hits = hits; _Count = count; } public Article(int cid, string title, DateTime addDate, string content, int hits, int count) { _CID = cid; _Title = title; _AddDate = addDate; _Content = content; _Hits = hits; _Count = count; } public Article( int cid, string title, string content) { _CID = cid; _Title = title; _Content = content; } public Article(int id, int cid, string title, string content) { _ID = id; _CID = cid; _Title = title; _Content = content; } public int ID { get { return _ID; } set { _ID = value; } } public int CID { get { return _CID; } set { _CID = value; } } public string Title { get { return _Title; } set { _Title = value; } } public DateTime AddDate { get { return _AddDate; } set { _AddDate = value; } } public string Content { get { return _Content; } set { _Content = value; } } public int Hits { get { return _Hits; } set { _Hits = value; } } public int Count { get { return _Count; } set { _Count = value; } } }} RequestData 類:代替 Request.Form; 上面用到的,作用是 把?Request.Form;里面的 name value 保存到一個 hashTable 里面 using System;using System.Collections;using System.Collections.Generic;using System.Collections.Specialized;using System.Web;/// <summary>///RequestData 的摘要說明/// </summary>public class RequestData{ public RequestData() { // //TODO: 在此處添加構(gòu)造函數(shù)邏輯 // } public static Hashtable Get() { Hashtable _Hashtable = new Hashtable(); NameValueCollection NVC = HttpContext.Current.Request.Form; for (int i = 0; i < NVC.Count; i++) { _Hashtable.Add(NVC.Keys[i].ToString().ToLower(), NVC[NVC.Keys[i]]); } return _Hashtable; }} UI: ArticleAdd.aspx <html xmlns="http://www.w3.org/1999/xhtml"><head> <title></title></head><body><form action="?action=save" method="post"> 標(biāo)題:<input type="text" value="134" name="Title" /><br /> 內(nèi)容:<input type="text" value="134" name="Content" /><br /> 日期:<input type="text" value="1989 07 18" name="AddDate" /><br /> 類別ID:<input type="text" value="134" name="CID" /><br /> <input type="submit" value="submit" /></form></body></html> ArticleAdd.aspx.cs using System;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Collections;using MODEL;public partial class _Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { Hashtable Has = RequestData.Get(); Article ArticleMOD=new Article(Has); //實(shí)例化 MODEL }}
查看完整描述

7 回答

?
慕森卡

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超8個贊

太麻煩了。建議使用下反射吧。

NameValueCollection本來就是KV6的格式的 為什么還要轉(zhuǎn)換成HashTable呢?

直接反射 保持鍵和Model中的屬性值相同的就可以了。

查看完整回答
反對 回復(fù) 2019-01-21
?
largeQ

TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個贊

? 看了好一會才明白,這個方法蠻不錯,謝謝!

查看完整回答
反對 回復(fù) 2019-01-21
?
白豬掌柜的

TA貢獻(xiàn)1893條經(jīng)驗(yàn) 獲得超10個贊

兄弟 幫我問問,這樣寫有什么弊端
查看完整回答
反對 回復(fù) 2019-01-21
?
函數(shù)式編程

TA貢獻(xiàn)1807條經(jīng)驗(yàn) 獲得超9個贊

這樣寫,ui層和DAO層耦合度太高啦

查看完整回答
反對 回復(fù) 2019-01-21
?
蝴蝶刀刀

TA貢獻(xiàn)1801條經(jīng)驗(yàn) 獲得超8個贊

這樣 耦合度高的話,會有哪些影響呢?
我能想到的是 當(dāng) 數(shù)據(jù)庫 加字段 刪除字段的時候 可能會 麻煩
還有就是 按照常規(guī)的寫法,數(shù)據(jù)庫 刪除字段 或者添加 字段 基本上 也要改個遍
但是這個 我寫了一個 代碼生成工具 ,根據(jù)數(shù)據(jù)庫 結(jié)構(gòu)生成 的 所以 也不是麻煩
查看完整回答
反對 回復(fù) 2019-01-21
?
眼眸繁星

TA貢獻(xiàn)1873條經(jīng)驗(yàn) 獲得超9個贊

代碼生成工具固然方便。但是它是在項目開始時使用。到了項目迭代時:你不可能通過代碼生成工具來大批量生成Code。因?yàn)橛行I(yè)務(wù)邏輯是工具無法完成的
查看完整回答
反對 回復(fù) 2019-01-21
?
至尊寶的傳說

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超10個贊

其實(shí)技術(shù)的應(yīng)用:就是在你項目中權(quán)衡你的需求。
查看完整回答
反對 回復(fù) 2019-01-21
  • 7 回答
  • 0 關(guān)注
  • 434 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號