隨筆 - 115  文章 - 481  trackbacks - 0
          <2007年12月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          常用鏈接

          留言簿(19)

          隨筆檔案(115)

          文章檔案(4)

          新聞檔案(1)

          成員連接

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

            “善意的謊言、美麗的錯誤”,這些事情在我們的生活及工作經(jīng)常都在發(fā)生。最近花了三天多的時間學習了EasyJF開源官網(wǎng)的Blog程序源碼,振奮人心之處就不說了,看過的都知道。同時也存在很多的錯誤,這些錯誤有的是由我不知何時親自導演,這里就撿一些“美麗”的錯誤及Bug來說說,為了自己以后不再犯這樣錯誤。

            技術構架: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)顯示到 中,第行最多顯示兩列       。

            但無論如何,都無法得到想要的結果,由于準備換成類似$BlogQuery.circleQuery.user($blog.owner).number(-1).list這樣的標簽來查詢數(shù)據(jù),所以一直認為是標簽設計的問題。經(jīng)過后來的一陣折騰證明是腳本寫法的問題,你知道是哪些地方出的問題了嗎?先說明:$!CommUtil.toRowChildList這個標簽沒任何問題。

          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ù)結構永遠就比算法重要,這個是不容質疑的,可以搞出很漂亮的算法,但沒有一個好的模型,你就瞎忙吧。你覺得上面的代碼哪兒錯了?

           4、一不小心就OO及ORM 來自:評論系統(tǒng)設計 ★★☆

          @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īng)典的OO及ORM示例,但是現(xiàn)在這樣的寫法你知道JPA會創(chuàng)建幾張表嗎,各個表之間關聯(lián)字段是是什么? Service中的getBlogReview返回什么?答對了有獎。


           4、有事無事的事務 來自blog信息發(fā)表 
            


           
          <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);
          // 很怪也滑稽的設計
             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ù)。嚴格來說,這沒什么錯,只是害苦了美工MM而已,難怪她們不喜歡呆辦公室。

           7、真空還是沒空(is NULL or EMPTY) 來自Blog發(fā)布程序

          業(yè)務層代碼:
          QueryObject query 
          = new QueryObject();
          java.util.Calendar ca 
          = java.util.Calendar.getInstance();
          ca.setTimeInMillis(ca.getTimeInMillis() 
          - blogIntervals * 1000);  
          query.addQuery(
          "(obj.updateTime",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)在換來的卻是大家抱怨呢?代碼有時候也是有生命的,你如何都不用心好好對待他,他怎么會一直按部就班的運轉呢?

           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ù)痛哭吧,呵呵。其實我們只要仔細看一看就知道問題了。w3c可不是war3,不能隨便亂來的。

          10.你擁有什么? 來自Blog域對象 
           
            

          @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;// 標題

           @Column(length 
          = 200)
           
          protected String subtitle;// 副標題

          }

          頁面標簽:
          #foreach($info $BlogQuery.photoQuery.blogOwner($blog.owner).number(
          6).orderBy("inputTime").desc().list)

          #end

            呵呵,今天就這么多了,先聽聽大家的高見!下次發(fā)幾個能讓人眼前一亮的。

          posted on 2007-12-06 16:16 簡易java框架 閱讀(286) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 宁强县| 甘孜县| 休宁县| 福州市| 时尚| 凤庆县| 连江县| 南岸区| 墨脱县| 改则县| 竹北市| 柞水县| 彰化县| 盐边县| 黄冈市| 普陀区| 南涧| 宜宾县| 孟村| 田林县| 长岭县| 凤冈县| 上杭县| 邢台县| 北碚区| 旬邑县| 临城县| 铁力市| 新津县| 镇康县| 昌都县| 惠安县| 双牌县| 大名县| 漾濞| 扶风县| 桐柏县| 穆棱市| 深泽县| 威信县| 广元市|