Created
November 27, 2012 08:05
-
-
Save need4spd/4153070 to your computer and use it in GitHub Desktop.
mybatis mapper 설명
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//xml에 설정한 statement가 호출 | |
session.select("com.tistory.devyongsik.mapper.DualMapper.selectAll", new ResultHandler() { | |
public void handleResult(ResultContext arg0) { | |
System.out.println(arg0.getResultObject()); | |
} | |
}); | |
//mapper interface의 selectAll2 메서드가 호출 | |
session.select("com.tistory.devyongsik.mapper.DualMapper.selectAll2", new ResultHandler() { | |
public void handleResult(ResultContext arg0) { | |
System.out.println(arg0.getResultObject()); | |
} | |
}); | |
//mapper interface의 selectAll2 메서드 직접 호출 | |
session.getMapper(DualMapper.class).selectAll2(new ResultHandler() { | |
public void handleResult(ResultContext context) { | |
System.out.println(context.getResultObject()); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tistory.devyongsik.domain; | |
/** | |
* @author need4spd, need4spd@11st.co.kr, 2012. 10. 11. | |
* | |
*/ | |
public class Dual { | |
private String r; | |
public String getR() { | |
return r; | |
} | |
public void setR(String r) { | |
this.r = r; | |
} | |
@Override | |
public String toString() { | |
return "Dual [r=" + r + "]"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tistory.devyongsik.mapper; | |
import org.apache.ibatis.annotations.ResultMap; | |
import org.apache.ibatis.annotations.Select; | |
import org.apache.ibatis.session.ResultHandler; | |
/** | |
* @author need4spd, need4spd@11st.co.kr, 2012. 10. 11. | |
* | |
*/ | |
public interface DualMapper { | |
@Select("select 2 as keyword from dual") | |
@ResultMap(value="dualResultMap") | |
public void selectAll2(ResultHandler handler); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--?xml version="1.0" encoding="UTF-8" ?--> | |
<mapper namespace="com.tistory.devyongsik.mapper.DualMapper"> | |
<resultmap id="dualResultMap" type="DualDomain"> | |
<result column="keyword" property="r" jdbctype="VARCHAR"> | |
</result></resultmap> | |
<select id="selectAll" resultmap="dualResultMap"> | |
select 1 as keyword from dual | |
</select> | |
</mapper> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
session.getMapper(Mapper.class).selectAll(new ResultHandler() { | |
public void handleResult(ResultContext context) { | |
//do something.. | |
System.out.println(context); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SqlSesssion session = sqlSessionFactory.openSession(); | |
session.select("selectALL", new ResultHandler() { | |
public void handleResult(ResultContext context) { | |
//do something.. | |
System.out.println(context); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment