兩畝三分地

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            17 隨筆 :: 20 文章 :: 2 評論 :: 0 Trackbacks
          項目開發(fā)的準備工作已經差不多了,現在需要的是與數據表對應的數據類。
          1. 數據類
          按照編程習慣首先創(chuàng)建package,項目名稱右鍵選擇New->Java package; package name填寫com.blog

          在com.blog下面創(chuàng)建與數據表對應的Blog,Comment,Category以及User這4個類
          blog.java
           1 /*
           2  * To change this template, choose Tools | Templates
           3  * and open the template in the editor.
           4  */
           5 
           6 package com.blog;
           7 
           8 import java.util.Date;
           9 
          10 /**
          11  *
          12  * @author Chucky
          13  */
          14 public class Blog {
          15     private int id;
          16     private String title;
          17     private String content;
          18     private Date date;
          19     private int categoryId;
          20     private String category;
          21 
          22     public String getCategory() {
          23         return category;
          24     }
          25 
          26     public void setCategory(String category) {
          27         this.category = category;
          28     }
          29 
          30     public int getCategoryId() {
          31         return categoryId;
          32     }
          33 
          34     public void setCategoryId(int categoryId) {
          35         this.categoryId = categoryId;
          36     }
          37 
          38     public String getContent() {
          39         return content;
          40     }
          41 
          42     public void setContent(String content) {
          43         this.content = content;
          44     }
          45 
          46     public Date getDate() {
          47         return date;
          48     }
          49 
          50     public void setDate(Date date) {
          51         this.date = date;
          52     }
          53 
          54     public int getId() {
          55         return id;
          56     }
          57 
          58     public void setId(int id) {
          59         this.id = id;
          60     }
          61 
          62     public String getTitle() {
          63         return title;
          64     }
          65 
          66     public void setTitle(String title) {
          67         this.title = title;
          68     }
          69     
          70 }
          71 
          Category.java
           1 /*
           2  * To change this template, choose Tools | Templates
           3  * and open the template in the editor.
           4  */
           5 
           6 package com.blog;
           7 
           8 /**
           9  * This is category class which records id and name
          10  * @author Chucky
          11  */
          12 public class Category {
          13     private int id;
          14     private String name;
          15 
          16     public int getId() {
          17         return id;
          18     }
          19 
          20     public void setId(int id) {
          21         this.id = id;
          22     }
          23 
          24     public String getName() {
          25         return name;
          26     }
          27 
          28     public void setName(String name) {
          29         this.name = name;
          30     }
          31     
          32 }
          33 
          Comment.java
           1 /*
           2  * To change this template, choose Tools | Templates
           3  * and open the template in the editor.
           4  */
           5 
           6 package com.blog;
           7 
           8 import java.util.Date;
           9 
          10 /**
          11  * this is comment class which records id,name,content,date and blog_id
          12  * @author Chucky
          13  */
          14 public class Comment {
          15     private int id;
          16     private String name;
          17     private String content;
          18     private Date date;
          19     private int blog_id;
          20 
          21     public int getBlog_id() {
          22         return blog_id;
          23     }
          24 
          25     public void setBlog_id(int blog_id) {
          26         this.blog_id = blog_id;
          27     }
          28 
          29     public String getContent() {
          30         return content;
          31     }
          32 
          33     public void setContent(String content) {
          34         this.content = content;
          35     }
          36 
          37     public Date getDate() {
          38         return date;
          39     }
          40 
          41     public void setDate(Date date) {
          42         this.date = date;
          43     }
          44 
          45     public int getId() {
          46         return id;
          47     }
          48 
          49     public void setId(int id) {
          50         this.id = id;
          51     }
          52 
          53     public String getName() {
          54         return name;
          55     }
          56 
          57     public void setName(String name) {
          58         this.name = name;
          59     }
          60     
          61 }
          62 
          User.java
           1 /*
           2  * To change this template, choose Tools | Templates
           3  * and open the template in the editor.
           4  */
           5 
           6 package com.blog;
           7 
           8 /**
           9  *
          10  * @author Chucky
          11  */
          12 public class User {
          13     private int id;
          14     private String userName;
          15     private String password;
          16 
          17     public int getId() {
          18         return id;
          19     }
          20 
          21     public void setId(int id) {
          22         this.id = id;
          23     }
          24 
          25     public String getPassword() {
          26         return password;
          27     }
          28 
          29     public void setPassword(String password) {
          30         this.password = password;
          31     }
          32 
          33     public String getUserName() {
          34         return userName;
          35     }
          36 
          37     public void setUserName(String userName) {
          38         this.userName = userName;
          39     }
          40 
          41 }
          42 
          值得注意的是為了開發(fā)的方便,在Blog.java里與數據表不同,多了一個category屬性。


          2. Servlet
          考慮到如果按照以后jsp的功能來寫servlet的話,文件多了既混亂也不便于管理,所以按照數據類創(chuàng)建
          BlogServlet(與blog相關的Servlet,如:添加,刪除,修改,瀏覽,查詢), CommentServlet, CategoryServlet和UserServlet,4個Servlet。


          因為默認添加servlet信息到deployment文件,所以打開web.xml,相應的servlet信息已經被添加進去了。

          posted on 2009-09-28 15:41 Chucky 閱讀(122) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 阿拉善盟| 吕梁市| 东辽县| 龙口市| 云霄县| 郁南县| 依兰县| 蕉岭县| 永定县| 得荣县| 长子县| 江北区| 富顺县| 贵南县| 会理县| 贡觉县| 北海市| 华蓥市| 巫山县| 临清市| 桐梓县| 威海市| 广饶县| 邯郸市| 台南市| 涟水县| 和硕县| 镇康县| 东平县| 岚皋县| 西峡县| 永寿县| 金溪县| 甘肃省| 盘锦市| 梁平县| 林周县| 富民县| 龙胜| 陇南市| 巍山|