新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Eclipse自動生成Getter、Setter和構(gòu)造方法
(1)POJO類自動生成Getter和Setter方法:

Persion.java原來的代碼:
在上面代碼的空白處點(diǎn)右鍵,或者在Person類名上點(diǎn)右鍵 —> Source –> Generate Getters and Setters,如下圖:
接著,在Generate Getters and Setters對話框中,將Persion的屬性id和name鉤上,或直接點(diǎn)擊“Select All”按鈕將所有屬性選中,點(diǎn)OK即行。
我們再看看Person.java類的代碼:
可見,Getter方法和Setter方法自動生成了,比一個(gè)一個(gè)去敲代碼便捷多了。
(2)自動生成構(gòu)造方法(構(gòu)造函數(shù)):
在類代碼的空白處點(diǎn)右鍵,或者在類名上點(diǎn)右鍵 —> Source –> Generate Constructor using Fields,如下圖:
在Generate Constructor using Fields對話框中, 將Persion類的全部屬性或部分屬性鉤上,點(diǎn)OK即行。如下圖:
下來,來看看自己生成的構(gòu)造方法,見下圖選中部分:
【編輯推薦】
- 淺談如何大幅優(yōu)化MyEclipse速度
- MyEclipse 7.1發(fā)布(附下載地址)
- MyEclipse 7.0的漢化
- 淺談如何用MyEclipse連接MySQL
- MyEclipse 6.0安裝及配置
本文題目:Eclipse自動生成Getter、Setter和構(gòu)造方法
鏈接分享:http://fisionsoft.com.cn/article/dpjehic.html


咨詢
建站咨詢
