๋กœ์ผ“๐Ÿพ
article thumbnail

 

<choose> ํƒœ๊ทธ๋Š” switch๋ฌธ๊ณผ ๋น„์Šทํ•œ ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค.


l <choose> ํƒœ๊ทธ

 

<select id="selectCHOOSE" parameterType="memberVO" resultType="memberVO">
	SELECT
		*
	FROM TEST_TABLE
	WHERE 1=1
		<choose>
			<when test="id !='' and id !=null and name!='' and name!=null">
				AND NAME=#{name} AND ID=#{id}
			</when>
			<when test="name!='' and name!=null">
				AND NAME='ํ™์ง€์›'
			</when>
			<when test="id!='' and id!=null">
				AND ID='ํ™์ง€์›'
			</when>
		</choose>
</select>

 

switch์˜ case ๋ฌธ์ฒ˜๋Ÿผ choose๋ฌธ์—์„œ๋Š” when ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์กฐ๊ฑด์•ž์—๋Š” ํ•ญ์ƒ test๋ฅผ ๋ถ™์—ฌ์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์œ„ ์ฝ”๋“œ์—์„œ๋Š” ๋งŒ์•ฝ name, id๊ฐ€ ์žˆ์œผ๋ฉด ์ฒซ๋ฒˆ์งธ when์ด, name๋งŒ ์žˆ์œผ๋ฉด ๋‘๋ฒˆ์งธ when์ด, id๋งŒ ์žˆ์œผ๋ฉด ์„ธ๋ฒˆ์งธ when ์‹คํ–‰๋˜๋Š” ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.

 

public MemberVO selectIF() {
	sqlMapper = getInstance();
	SqlSession session = sqlMapper.openSession();
	MemberVO memberVo = new MemberVO();
	MemberVO result = new MemberVO();
	
	//memberVo.setId("๊น€๋ณ‘์ค€");
	memberVo.setName("๊น€๋ณ‘์ค€");
	
	
	result = session.selectOne("mapper.member.selectCHOOSE", memberVo);
	
	return result;
}

 

setId๊ฐ€ ์—†์œผ๋ฉด ๋‘๋ฒˆ์งธ ์กฐ๊ฑด์ธ AND NAME='ํ™์ง€์›'์ด ์‹คํ–‰๋œ ๊ฑธ ๋ณด์‹ค์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ถœ๋ ฅ ๊ฒฐ๊ณผ

 

 

 

์ฝ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

์งˆ๋ฌธ์€ ์–ธ์ œ๋‚˜ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค.

 

"๋‚œ ๋ฐ˜๋“œ์‹œ ๋ฐฑ์—”๋“œ ์™•์ด ๋ ๊ฑฐ์•ผ"

profile on loading

Loading...