👀 검색기능 : like 사용
- customer_dto.java
package kr.co.sen;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class customer_dto {
Integer c_idx;
String c_id,c_name,c_hp,c_email,c_tel,c_post;
String c_road,c_address,c_level,c_area,c_join;
}
- mapper.xml
<!-- mybatis + oracle에서 like 사용하는 방식 -->
<select id="customer_one" resultType="kr.co.sen.customer_dto" parameterType="String">
select * from customer where c_name like '%'||#{c_name}||'%' order by c_idx desc
</select>
=> ⭐ Oracle 에서는 mybatis에서 like 사용시 || 와 함께 사용
- mysql은 concat('%',#{c_idx},'%')
- MSSQL 은 like '%'+#{c_idx}+'%'
- member_repo.java (interface)
package kr.co.sen;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface member_repo {
//customer data 검색
List<customer_dto> customer_one(String c_name);
}
- member_service.java (interface)
package kr.co.sen;
import java.util.List;
public interface member_service {
public List<customer_dto> customer_one(String c_name);
}
- memberServiceImpl.java
package kr.co.sen;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class memberServiceImpl implements member_service{
@Autowired
private member_repo member_repo;
//oracle like를 이용한 사용자 이름 검색
@Override
public List<customer_dto> customer_one(String c_name) {
List<customer_dto> all = member_repo.customer_one(c_name);
return all;
}
}
- controller
@GetMapping("/serach_name.do")
public String search_name() {
String username ="방문석";
List<customer_dto> all = member_service.customer_one(username);
System.out.println(all.get(0).getC_email());
return null;
}
//잘찍힘ㅎ
'CLASS > DATABASE' 카테고리의 다른 글
database 보안.. (0) | 2024.10.14 |
---|---|
Oracle 정리 (2) | 2024.09.06 |
#6-2/ Oracle - sequence reset, ROW_NUMBER(),view+join (0) | 2024.09.06 |
#6-1 / Oracle - data 미러링 , table 제작 상세내역 확인 , trigger (2) | 2024.09.06 |
#5-1 / Oracle - Excel 파일 data입력 , 파일로 저장 (3) | 2024.09.05 |