中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

草包做視頻網(wǎng)站北京今日重大新聞

草包做視頻網(wǎng)站,北京今日重大新聞,化德網(wǎng)站建設(shè),如何申請建設(shè)網(wǎng)站域名Java傳輸對象模式 實現(xiàn)范例 傳輸對象模式(Transfer Object Pattern)用于從客戶端向服務(wù)器一次性傳遞帶有多個屬性的數(shù)據(jù)傳輸對象也被稱為數(shù)值對象,沒有任何行為傳輸對象是一個具有 getter/setter 方法的簡單的 POJO 類,它是可序列…

Java傳輸對象模式

    • 實現(xiàn)
    • 范例

  • 傳輸對象模式(Transfer Object Pattern)用于從客戶端向服務(wù)器一次性傳遞帶有多個屬性的數(shù)據(jù)
  • 傳輸對象也被稱為數(shù)值對象,沒有任何行為
  • 傳輸對象是一個具有 getter/setter 方法的簡單的 POJO 類,它是可序列化的,所以它可以通過網(wǎng)絡(luò)傳輸
  • 服務(wù)器端的業(yè)務(wù)類通常從數(shù)據(jù)庫讀取數(shù)據(jù),然后填充 POJO,并把它發(fā)送到客戶端或按值傳遞它
  • 對于客戶端,傳輸對象是只讀的
  • 客戶端可以創(chuàng)建自己的傳輸對象,并把它傳遞給服務(wù)器,以便一次性更新數(shù)據(jù)庫中的數(shù)值
  • 以下是這種設(shè)計模式的實體:
    • 業(yè)務(wù)對象(Business Object) - 為傳輸對象填充數(shù)據(jù)的業(yè)務(wù)服務(wù)
    • 傳輸對象(Transfer Object) - 簡單的 POJO,只有設(shè)置/獲取屬性的方法
    • 客戶端(Client) - 客戶端可以發(fā)送請求或者發(fā)送傳輸對象到業(yè)務(wù)對象

實現(xiàn)

在這里插入圖片描述

  • 創(chuàng)建一個作為業(yè)務(wù)對象的 StudentBO 和作為傳輸對象的 StudentVO ,它們都代表了我們的實體
  • TransferObjectPatternDemo ,我們的演示類在這里是作為一個客戶端,將使用 StudentBO 和 Student 來演示傳輸對象設(shè)計模式

范例

1. 創(chuàng)建傳輸對象 StudentVO

StudentVO.java

package com.demo.gof;
public class StudentVO{private String name;private int rollNo;StudentVO(String name, int rollNo){this.name = name;this.rollNo = rollNo;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getRollNo() {return rollNo;}public void setRollNo(int rollNo) {this.rollNo = rollNo;}
}

2. 創(chuàng)建業(yè)務(wù)對象 StudentBO

StudentBO.java

package com.demo.gof;
import java.util.ArrayList;
import java.util.List;public class StudentBO {//列表是當(dāng)作一個數(shù)據(jù)庫List<StudentVO> students;public StudentBO(){students = new ArrayList<StudentVO>();StudentVO student1 = new StudentVO("Robert",0);StudentVO student2 = new StudentVO("John",1);students.add(student1);students.add(student2);       }public void deleteStudent(StudentVO student) {students.remove(student.getRollNo());System.out.println("Student: Roll No " + student.getRollNo() +", deleted from database");}//從數(shù)據(jù)庫中檢索學(xué)生名單public List<StudentVO> getAllStudents() {return students;}public StudentVO getStudent(int rollNo) {return students.get(rollNo);}public void updateStudent(StudentVO student) {students.get(student.getRollNo()).setName(student.getName());System.out.println("Student: Roll No " + student.getRollNo() +", updated in the database");}
}

3. 使用 StudentBO 來演示傳輸對象設(shè)計模式

TransferObjectPatternDemo.java

package com.demo.gof;
public class TransferObjectPatternDemo {public static void main(String[] args) {StudentBO studentBusinessObject = new StudentBO();//輸出所有的學(xué)生for (StudentVO student : studentBusinessObject.getAllStudents()) {System.out.println("Student: [RollNo : "+student.getRollNo()+", Name : "+student.getName()+" ]");}//更新學(xué)生StudentVO student =studentBusinessObject.getAllStudents().get(0);student.setName("Michael");studentBusinessObject.updateStudent(student);//獲取學(xué)生studentBusinessObject.getStudent(0);System.out.println("Student: [RollNo : "+student.getRollNo()+", Name : "+student.getName()+" ]");}
}

編譯運(yùn)行以上 Java 范例,輸出結(jié)果如下

$ javac -d . src/main/com.demo/gof/TransferObjectPatternDemo.java
$ java  com.ddkk.demo.TransferObjectPatternDemo
Student: [RollNo : 0, Name : Robert ]
Student: [RollNo : 1, Name : John ]
Student: Roll No 0, updated in the database
Student: [RollNo : 0, Name : Michael ]
http://www.risenshineclean.com/news/48505.html

相關(guān)文章:

  • 做衣服外單網(wǎng)站百度識圖在線識別網(wǎng)頁版
  • gta5資產(chǎn)網(wǎng)站正在建設(shè)現(xiàn)在陽性最新情況
  • 橙子建站輸入了驗證碼有危險嗎sem工具是什么
  • 建筑工程招聘信息網(wǎng)seo優(yōu)化工具
  • 類似behance的設(shè)計網(wǎng)站seo顧問張智偉
  • 手機(jī)網(wǎng)站cms手機(jī)百度助手
  • 服務(wù)器能放多少個網(wǎng)站廣州最新新聞
  • 國外扁平化網(wǎng)站設(shè)計欣賞優(yōu)化大師使用心得
  • 煙臺產(chǎn)品網(wǎng)站建設(shè)百度seo如何做
  • dw做網(wǎng)站上海百度推廣官方電話
  • 拼多多的網(wǎng)站建設(shè)海淀區(qū)seo引擎優(yōu)化
  • 做個網(wǎng)站要多久百度指數(shù)的各項功能
  • 重慶企業(yè)網(wǎng)站建設(shè)聯(lián)系電話青島seo網(wǎng)站關(guān)鍵詞優(yōu)化
  • 梅州網(wǎng)站制作百度搜索引擎優(yōu)化詳解
  • 天眼查官方網(wǎng)站黃岡網(wǎng)站推廣
  • 哪個網(wǎng)站幫別人做ppt上海推廣seo
  • 垂直行業(yè)門戶網(wǎng)站建設(shè)方案百度權(quán)重怎么提高
  • 做直播網(wǎng)站vps可以嗎技術(shù)培訓(xùn)機(jī)構(gòu)
  • 免費(fèi)建商城網(wǎng)站網(wǎng)址查詢
  • 私彩票網(wǎng)站建設(shè)網(wǎng)站seo優(yōu)化排名
  • 做模具的網(wǎng)站seo智能優(yōu)化
  • wordpress用戶排行榜廈門seo服務(wù)
  • 做亞馬遜網(wǎng)站費(fèi)用嗎必應(yīng)收錄提交入口
  • 一個網(wǎng)站可以做多少個關(guān)鍵詞百度網(wǎng)頁排名怎么提升
  • wordpress首頁截斷seo白帽優(yōu)化
  • php動態(tài)網(wǎng)站開發(fā)簡介網(wǎng)站制作平臺
  • 自己怎么做系統(tǒng)網(wǎng)站能打開的a站
  • 共享辦公室 設(shè)計網(wǎng)站性能優(yōu)化
  • 鐵漢生態(tài)建設(shè)有限公司網(wǎng)站最新黑帽seo培訓(xùn)
  • 如何做屬于自己的領(lǐng)券網(wǎng)站廈門人才網(wǎng)最新招聘信息