쿼리를 구현하기 위해, 우리는 먼저 CityAreaid가 외국 키 인 아래에 표시된 것처럼 데이터베이스를 먼저 가질 것입니다.
아래 지점은 이름과 주소 속성이있는 내 엔티티 클래스입니다.
인터페이스의 메소드 :
public list <branches> findongtai (@param ( "name") 문자열 이름,@param ( "add") 문자열 주소); // 동적 공개 목록 <branches> findlike (@param ( "name") 문자열 이름,@param ( "add") 문자열 주소); // funny
MyBatis의 인터페이스 매핑 파일 코드 :
동적 쿼리 :
< "findongtai"resulttype = "com.wj.entity.branches"> select * select * select * select * where 1 = 1 <if test = "name! = ''및 name! = null"> 및 name =#{name} </if> <test = "add! = ''및 address =#{ad} </if> </if> </if> </if> <퍼지 쿼리 :
<select id = "find like"resulttype = "com.wj.entity.branches"> "%"#{name} "%"와 같은 이름과 "%"#{add} "%"</select "와 같은 주소가있는 분기에서 선택 * 선택 *그런 다음 주요 방법이 구현됩니다.
목록 <branches> list = new Branchesimpl (). findongtai ( "China Construction Bank", ""); for (branches branches : list) {system.out.println ( "name :"+branches.getName ()+"/t ---/taddress :"+branches.getAddress ()); } list <branches> list = new branchesimpl (). find -like ( "서브 브랜치", "도로"); for (branches branches : list) {system.out.println ( "name :"+branches.getName ()+"/t-/taddress :"+branches.getAddress ()); }결과는입니다. . .
동적 쿼리 :
퍼지 쿼리 :
요약
위는 편집기가 소개 한 동적 쿼리 및 퍼지 쿼리 기능의 MyBatis 구현입니다. 모든 사람에게 도움이되기를 바랍니다. 궁금한 점이 있으면 메시지를 남겨 주시면 편집자가 제 시간에 모든 사람에게 답장을 드리겠습니다. Wulin.com 웹 사이트를 지원해 주셔서 대단히 감사합니다!