“善意的謊言、美麗的錯誤”,這些事情在我們的生活及工作經(jīng)常都在發(fā)生。最近花了三天多的時間學(xué)習(xí)了EasyJF開源官網(wǎng)的Blog程序源碼,振奮人心之處就不說了,看過的都知道。同時也存在很多的錯誤,這些錯誤有的是由我不知何時親自導(dǎo)演,這里就撿一些“美麗”的錯誤及Bub來說說,為了自己以后不再犯這樣錯誤。
技術(shù)構(gòu)架:
EasyJWeb+Spring2+JPA 視圖模板使用:Velocity
1、很Cool的循環(huán)
來自:Blog的圈子顯示 錯誤等級★★★★★
#foreach($!subList?in?$!CommUtil.toRowChildList($myOnweCircle,2))
??
<
tr
>
?#foreach($!info?in?$subList)
?
<
td
>
$!info.title
</
td
>
?#end
<
tr
>
?#end
其中$myOnwerCircle是從后臺傳過來的一個List。這個程序是遍歷一個列集合,把集合的元素循環(huán)顯示到<tr>中,第行最多顯示兩列<td>。
但無論如何,都無法得到想要的結(jié)果,由于準(zhǔn)備換成類似$BlogQuery.circleQuery.user($blog.owner).number(-1).list這樣的標(biāo)簽來查詢數(shù)據(jù),所以一直認(rèn)為是標(biāo)簽設(shè)計的問題。經(jīng)過后來的一陣折騰證明是腳本寫法的問題,你知道是哪些地方出的問題了嗎?先說明:$!CommUtil.toRowChildList這個標(biāo)簽沒任何問題。
2、easy的echo
來自:Blog的圈子顯示 錯誤等級★★★★★☆
頁面內(nèi)容:
<
span?
class
="strong0"
>
$!info.title($!info.blogs.size())
</
span
><
br
>
這里打算顯示圈子的主題以及圈子下面的blog數(shù)量。但如果不親身體會,鬼都不知道他會給你顯示什么出來。你知道嗎?
3、非菜鳥的equals
來自:文章及照片評論
String?user?
=!
""
.equals(obj.getInputUser())?
?
?obj.getInputUser().getName()?:?
"
匿名用戶
"
;?
數(shù)據(jù)結(jié)構(gòu)永遠(yuǎn)就比算法重要,這個是不容質(zhì)疑的,可以搞出很漂亮的算法,但沒有一個好的模型,你就瞎忙吧。你覺得上面的代碼哪兒錯了?
4、一不小心就OO及ORM
來自:評論系統(tǒng)設(shè)計 ★★☆
@Entity
@javax.persistence.Inheritance(strategy?
=
?javax.persistence.InheritanceType.JOINED)
@Cache(usage
=
CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@FormPO(inject?
=
?
"
sequence,content,owner
"
)
public
?
abstract
?
class
?Review?
implements
?java.io.Serializable?
...
{
?@Id
?@GeneratedValue(strategy?
=
?GenerationType.TABLE)
?
private
?Long?id;
//
?主鍵
..}
@FormPO(inject
=
"
blogOwner,inputUser
"
)
@Entity
@javax.persistence.MappedSuperclass
public
?
class
?BlogReview?
extends
?Review?
implements
?IBlogComponment?
...
{
?@POLoad(name
=
"
userId
"
)
?@ManyToOne
?
private
?User?blogOwner;
?
private
?String?inputUser;
}
@FormPO(inject
=
"
newsDoc
"
)
@Entity
public
?
class
?BlogNewsReview?
extends
?BlogReview?
...
{
?@POLoad(name?
=
?
"
docId
"
)
?@ManyToOne
?@JoinColumn
?
private
?BlogNewsDoc?newsDoc;
//
?評論的對象
}
public
?
interface
?IBlogReviewDAO??
extends
?GenericDAO
<
BlogReview
>
?
...
{
}
?
private
?IBlogReviewDAO?dao;
????
public
?BlogReview?getBlogReview(Long?id)?
...
{
??
return
?
this
.dao.get(id);
?}
評論系統(tǒng),管理員能管理所有評論,能對Blog文章、像冊等進(jìn)行評論。
這個示例要是搞好了可以當(dāng)成是一個比較經(jīng)典的OO及ORM示例,但是現(xiàn)在這樣的寫法你知道JPA會創(chuàng)建幾張表嗎,各個表之間關(guān)聯(lián)字段是是什么? Service中的getBlogReview返回什么?答對了有獎。
4、有事無事的事務(wù)
來自blog信息發(fā)表?
??
<!--
事務(wù)配置
-->
?
<
aop:config
>
??
<
aop:pointcut?id
=
"
saveMethods
"
???expression
=
"
execution(*?com.easyjf.blog.service.BlogNewsDocService.*(..))
"
?
/>
???
<
aop:advisor?advice
-
ref
=
"
txBlogServiceAdvice
"
???pointcut
-
ref
=
"
saveMethods
"
?
/>
?
?
</
aop:config
>
?
<
tx:advice?id
=
"
txBlogServiceAdvice
"
??transaction
-
manager
=
"
transactionManager
"
>
??
<
tx:attributes
>
???
<
tx:method?name
=
"
wirteBlog*
"
?propagation
=
"
REQUIRES_NEW
"
?
/>
???
<
tx:method?name
=
"
update*
"
?propagation
=
"
REQUIRES_NEW
"
?
/>
???
<
tx:method?name
=
"
get*
"
?propagation
=
"
SUPPORTS
"
????read
-
only
=
"
true
"
?
/>
???
<
tx:method?name
=
"
query*
"
?propagation
=
"
SUPPORTS
"
????read
-
only
=
"
true
"
?
/>
???
<
tx:method?name
=
"
*
"
?propagation
=
"
REQUIRED
"
?
/>
??
</
tx:attributes
>
?
</
tx:advice
>
代碼:
this
.service.addBlogReview(review);
?
if
?(review?
instanceof
?BlogNewsReview)?
...
{
???BlogNewsReview?r?
=
?(BlogNewsReview)?review;
???
//
this.docService.updateBlogNewsDoc(r.getNewsDoc());
???
this
.htmlGenerator.process(r.getNewsDoc());
???r.getNewsDoc().getReviews().remove(r);
//
?很怪也滑稽的設(shè)計
???
return
?
new
?Page(
"
html
"
,?r.getNewsDoc().getStaticUrl(),?
"
html
"
);
?}
? 為什么Blog更新后出來的html頁面還是上一次更新的內(nèi)容?為什么在添加新聞的評論里面要加一句r.getNewsDoc().getReviews().remove(r),是無奈還是真的滑稽。
5、究竟是要IP、IQ還是IC卡
來自:blog首頁 ☆
后臺Action代碼
public
?Page?doInit(WebForm?form,?Module?module)?
...
{
??form.addResult(
"
blogInfoService
"
,?
this
.blogInfoService);
??form.addResult(
"
bqu
"
,?bqu);
??form.addResult(
"
bdqu
"
,?bdqu);
??form.addResult(
"
bcqu
"
,?bcqu);
form.addResult(
"
bb”?bb);
??
if
?(UserContext.getUser()?
!=
?
null
)?
...
{
???form.addResult(
"
user
"
,?
"
true
"
);
??}
??
return
?
new
?Page(
"
index
"
,?
"
/blog/index.html
"
);
?}
前臺頁面
#foreach($info?in?$bcu.thisYear.doc.list)
$info.title
#end
這段代碼是想把一些實用工具比如bb,bq,bcqu,bdqu等暴露給頁面,由頁面人員根據(jù)自己的喜愛想要展示什么數(shù)據(jù)就展示什么數(shù)據(jù)。嚴(yán)格來說,這沒什么錯,只是害苦了美工MM而已,難怪她們不喜歡呆辦公室。
7、真空還是沒空(is NULL or EMPTY)
來自Blog發(fā)布程序
業(yè)務(wù)層代碼:
QueryObject?query?
=
?
new
?QueryObject();
java.util.Calendar?ca?
=
?java.util.Calendar.getInstance();
ca.setTimeInMillis(ca.getTimeInMillis()?
-
?blogIntervals?
*
?
1000
);??
query.addQuery(
"
(obj.updateTime<??or?obj.updateTime?is?EMPTY)
"
,
new
?Object[]
...
{ca.getTime()}
);
query.setPageSize(
-
1
);??
List?list?
=
?
this
.blogService.getBlogInfo(query).getResult();
知道執(zhí)行這段代碼生成的SQL嗎?一定會讓你大吃一驚,把EMPTY改成NULL難道是我們想要的?
8、F想要干什么
來自:blog新聞管理
?
Javascript腳本代碼:
function
?init()
...
{
???F
=
new
?FORM(
"
blogNewsDoc.ejf
"
,
"
ListForm
"
);
???windowInit();
??}
??window.onload
=
init;??
??F.doList?
=
?F.doOneCommand(
"
listDoc
"
);
古老的new FORM曾經(jīng)讓我們非常欣喜,但為什么現(xiàn)在換來的卻是大家抱怨呢?代碼有時候也是有生命的,你如何都不用心好好對待他,他怎么會一直按部就班的運(yùn)轉(zhuǎn)呢?
9.想擦掉js給你留下的傷疤嗎
來自blog管理后臺
Html代碼
<
form?name
=
”ListForm”?id
=
”ListForm”
/>
<
input?type
=
"
button
"
?name
=
"
submit
"
?value
=
"
徹底刪除
"
?onClick
=
"
F.doRemove();
"
?class
=
"
pushbutton
"
?style
=
"
cursor:pointer?
"
>
</
form
>
?????F.doRemove()里面會執(zhí)行類似$(“ListForm”).submit()這樣的代碼來提交表單。
你覺得這段代碼能讓你真正的徹底刪除掉js曾經(jīng)留給你的諸多痛苦回憶嗎?你繼續(xù)痛哭吧,呵呵。其實我們只要仔細(xì)看一看就知道問題了。w3c可不是war3,不能隨便亂來的。
10.你擁有什么?
來自Blog域?qū)ο?
?
@FormPO(disInject
=
"
id,owner,inputTime,readTimes,status,elite,updated,docNum,photoNum
"
)
@MappedSuperclass
public
?
class
?AbstractBlog?
implements
?Serializable?
...
{?
?@Id
?@GeneratedValue(strategy?
=
?GenerationType.TABLE)
?
protected
?Long?id;
?
?@OneToOne
?
protected
?User?onwer;
?
?@Column(length?
=
?
200
)
?
protected
?String?title;
//
?標(biāo)題
?@Column(length?
=
?
200
)
?
protected
?String?subtitle;
//
?副標(biāo)題
}
頁面標(biāo)簽:
#foreach($info?$BlogQuery.photoQuery.blogOwner($blog.owner).number(
6
).orderBy(
"
inputTime
"
).desc().list)
#end
呵呵,今天就這么多了,先聽聽大家的高見!下次發(fā)幾個能讓人眼前一亮的。
?
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1921072