๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
FOR SW ENGINEER๐Ÿ‘ฉ‍๐Ÿ’ป/JSP

JSP - ์ž๋ฐ”๋นˆ(JavaBeans)

by ์”จ๋‹ˆ 2021. 11. 23.
728x90

์ž๋ฐ”๋นˆ(JavaBeans)

- JSP ๊ธฐ๋ฐ˜ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์ •๋ณด๋ฅผ ํ‘œํ˜„ํ•  ๋–„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ ์ค‘ ํ•˜๋‚˜.

- ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ• ๋•Œ, ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๊ณ  ์žˆ๋Š” ๊ฐ์ฒด(์ €์žฅ์†Œ)

- ์ž๋ฐ”๋นˆ์€ ์†์„ฑ(๋ฐ์ดํ„ฐ), ๋ณ€๊ฒฝ ์ด๋ฒคํŠธ, ๊ฐ์ฒด ์ง๋ ฌํ™”๋ฅผ ์œ„ํ•œ ํ‘œ์ค€์ด๋‹ค. ์ด ์ค‘์—์„œ JSP์—์„œ๋Š” ์†์„ฑ์„ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•œ ์šฉ๋„๋กœ ์‚ฌ์šฉ๋จ.

- ์ž๋ฐ”๋นˆ์€ ๋ณดํ†ต ์ž๋ฐ” class๋กœ ์ž‘์„ฑ, ์ž๋ฐ” ๊ทธ ์ž์ฒด๋ผ๊ณ  ๋ด๋„ ๋ฌด๋ฐฉ.

- java๋ฉ”์„œ๋“œ๋ฅผ ์„ ์–ธํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ์ž‘์„ฑ(ํ•„๋“œ, ์ƒ์„ฑ์ž, getset๋ฉ”์„œ๋“œ๋กœ ์ด๋ฃจ์–ด์ง)

 

<์ž๋ฐ”๋นˆ ์˜ˆ์‹œ>

package javabean;

public class Bean{
	
    //๊ฐ’์„ ์ €์žฅํ•˜๋Š” ํ•„๋“œ
    private String val1;
    private int val2;
    
    //Bean์˜ ๊ธฐ๋ณธ ์ƒ์„ฑ์ž
    public Bean(String val1, int val2){
    	super();
        this.val1 = val1;
        this.val2 = val2;
    }
    
    //ํ•„๋“œ์˜ ๊ฐ’ ์ฝ์–ด์˜ค๋Š” ๊ฐ’
    public String getVal1(){
    	return val1;
    }
    public int getVal2(){
    	return val2;
    }
    
    //ํ•„๋“œ์˜ ๊ฐ’์„ ๋ณ€๊ฒฝํ•˜๋Š” ๊ฐ’
    public String setVal1(){
    	this.val1 = val1;
    }
    public int setVal2(){
    	this.val2 = val2;
    }
}

 

++ java bean ์†์„ฑ(Property)์ค‘ booleanํƒ€์ž…์ผ ๊ฒฝ์šฐ get๋ฉ”์†Œ๋“œ๋ช… is๋กœ ์‹œ์ž‘ํ•  ์ˆ˜ ์žˆ์Œ.

728x90