<form action="list.do">
<select name="ch1">
<option value="idx">회원번호 </option>
<option value="name"> 이름 </option>
</select>
<input type="text" name="ch2">
<input type="submit" value="검색하기">
</form>
private String ch1;
private String ch2;
public String getCh1() {
return ch1;
}
public void setCh1(String ch1) {
this.ch1 = ch1;
}
public String getCh2() {
return ch2;
}
public void setCh2(String ch2) {
this.ch2 = ch2;
}
<select id="selectAll" resultMap="PsdResult">
SELECT *
FROM TABLE_PSD
ORDER BY IDX DESC
</select>
<select id="selectAll_idx" resultMap="PsdResult">
SELECT *
FROM TABLE_PSD
WHERE IDX LIKE '%' || #{ch2} || '%'
ORDER BY IDX DESC
</select>
<select id="selectAll_name" resultMap="PsdResult">
SELECT *
FROM TABLE_PSD
WHERE NAME LIKE '%' || #{ch2} || '%'
ORDER BY IDX DESC
</select>
@Override
public List<PsdVo> list(PsdVo vo) {
if(vo.getCh1() == null){
return mybatis.selectList("psdDAO.selectAll",vo);
}else {
if(vo.getCh1().equals("idx")) {
return mybatis.selectList("psdDAO.selectAll_idx",vo);
}else if(vo.getCh1().equals("name")) {
return mybatis.selectList("psdDAO.selectAll_name",vo);
}
}
return null;
}
<select id="id">
SELECT * FROM table
<where>
추가 SQL
</where>
</select>
<select id="selectBoard" resultMap="PsdResult" >
SELECT * FROM TABLE_PSD
<where>
<if test="ch1=='idx'" >
AND IDX LIKE '%'||#{ch2}||'%'
</if>
<if test="ch1=='name'" >
AND NAME LIKE '%'||#{ch2}||'%'
</if>
</where>
ORDER BY IDX DESC
</select>
@Override
public List<PsdVo> list(PsdVo vo) {
return mybatis.selectList("psdDAO.selectBoard",vo);
}