網(wǎng)站程序員如何應對web標準(1)
本文討論的是在web標準普及的形勢下,網(wǎng)站程序員的定位以及如何與設(shè)計師配合開發(fā)符合web標準的網(wǎng)站項目。本文適合的讀者是傳統(tǒng)table布局下分工不是非常明晰的程序員。1:學習web標準,讓你的工作變得更加簡單。web標準是大勢所趨,所以作為網(wǎng)站程序員。你必須洗腦,必須去學習web標準。去重新認識html標簽,去了解如何讓程序輸出頁面需要的代碼。比如: 上邊是美工出來的效果圖,下邊是符合標準的程序代碼:dim ohtmlset rs=server.createobject("adodb.recordset")sql = "select top 10 id,title from tbl_news order by id desc"rs.open sql,conn,1,1ohtml="<ul>"do while not rs.eofohtml=ohtml & "<li><a href=""shownews.asp?id=" & rs("id") & """ title=""" & rs("title") & """>" & rs("title") & "</a></li>"rs.movenextloopohtml=ohtml & "</ul>"rs.closeset rs=nothingresponse.write (ohtml)而如果是傳統(tǒng)的table布局下,程序員要寫的html代碼就會多很多,要寫出table、要判斷什么時候輸出tr來換行、要在每條新聞的前邊加個一個img來輸出小圖標、要用程序去控制輸出的標題長度。所有的工作都需要先出頁面代碼,程序員才能去寫出這段程序。對于程序員而言,你應該把web標準當成是一種福音,你應該把它當圣經(jīng)一樣去讀,去了解頁面代碼到底需要什么,明白之后你就會發(fā)現(xiàn)。你比以前要輕松多了。由于web標準注重的是表現(xiàn)與內(nèi)容相脫離,而程序只負責內(nèi)容數(shù)據(jù)。從此你就不再需要考慮用程序代碼如何控制隔行換色、一行分幾列輸出等等。你需要去做的,就是向頁面輸出最直接的內(nèi)容,沒有任何裝飾的內(nèi)容。當然如果你是用.net開發(fā)的話,你就可以更徹底一點了。你可以完全將工作重點放在建立對象、類庫、數(shù)據(jù)訪問等,向表現(xiàn)層提供方法即可。下邊的例子是我以前做項目的,應該有點參考價值。2:網(wǎng)站程序員,別讓html標簽阻擋了你的視線。如果你覺得你真的非常討厭繁瑣的html標簽,而且自己的學習方向也不在網(wǎng)站的表現(xiàn)層,那你就和html標簽徹底地說再見吧。我曾經(jīng)在傳統(tǒng)桌面軟件開發(fā)的公司工作,程序員都不會html,網(wǎng)站項目緊的時候又不得不讓他們來幫忙。我們就拿著visual studio .net 2003自帶的幾個例子仔細分析,按照面向?qū)ο蟮慕Y(jié)構(gòu)化分層開發(fā)模式,也能非常好的進行配合。以新聞模塊的開發(fā)為例:第一步:網(wǎng)站程序員可以按需求分析進行數(shù)據(jù)庫設(shè)計,你可以負責建表、編寫存儲過程。這類的事情程序員都非常的熟悉。第二步:定義對象。將網(wǎng)站的信息對象化,比如:public class newsprotected _id as integerprotected _typeid as integerprotected _title as stringprotected _author as stringprotected _original as stringprotected _updatetime as datetimeprotected _content as stringprotected _clickcount as integerpublic property id() as integergetreturn _idend getset(byval value as integer)_id = valueend setend propertypublic property typeid() as integergetreturn _typeidend getset(byval value as integer)_typeid = valueend setend propertypublic property title() as stringend propertypublic property author() as stringend propertypublic property original() as stringend propertypublic property updatetime() as datetimeend propertypublic property content() as stringend propertypublic property clickcount() as integerend propertyend class就像這樣,把網(wǎng)站里所有的表都試著對象化。然后再定義對象相關(guān)的記錄集,上邊定義的是單個的新聞對象,再定義一個新聞的記錄集。public class newss......end class