Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Git
- IntelliJ
- Eclipse
- 코틀린
- 넥사크로
- 함수
- 방법
- oracle
- 생성
- Java
- 자바
- jquery
- JPA
- 알고리즘
- Spring
- GitHub
- mybatis
- Vue
- aws
- 에러
- error
- 시큐리티
- 쿼리
- kotlin
- 스프링
- Security
- 오라클
- 프로그래머스
- db
- JavaScript
Archives
- Today
- Total
송민준의 개발노트
mybatis procedure 사용법 본문
Spring 및 mybatis가 세팅이 되어 있다는 가정 하에 사용법이다.
(먼저 서비스단에서 DAO 가 DI 됨)
1. 서비스단
objectDAO.call("리소스이름", 파람데이터);
if(!"식별값".equals(파람데이터.get("에러코드")) {
throw 어떤Exception("~", 파람데이터.get("에러메시지").toString());
}
2. DAO
@Autowired
private SqlSessionTemplate sqlSession;
public Object call(String sql, Map(또는 커스텀Object) map) throws Exception {
return sqlSession.update(sql, map);
}
3. XML
<mapper namespace="식별명">
<resultMap id = "식별가능한 이름(패키지에서)" type="map"/>
<update id ="리소스명" statementType="CALLABLE" parameterType="map">
{call
프로시저명(
#{파람1, mode=IN, jdbcType=VARCHAR, javaType=string}
, #{파람2, mode=IN, jdbcType=VARCHAR, javaType=string}
, #{파람3, mode=IN, jdbcType=VARCHAR, javaType=string}
, #{파람4, mode=IN, jdbcType=VARCHAR, javaType=string}
, #{에러코드, mode=OUT,jdbcType=VARCHAR, javaType=string, resultMap=식별가능한 이름(패키지에서)}
, #{에러메시지, mode=OUT,jdbcType=VARCHAR, javaType=string, resultMap=식별가능한 이름(패키지에서)}
)
}
</update>
</mapper>
서비스단에서 파람으로 넣었던 object or map 에 프로시저 결과값(out)이 주입된다.
XML에서 resultMap으로 선언했던 값들은 고유해야 한다.
'웹 > Spring Framework' 카테고리의 다른 글
[406] path variable email을 사용하는 경우 에러 해결방안 (2) | 2020.11.11 |
---|---|
[spring] 테스트 중 Unable to initialize 'javax.el.ExpressionFactory' 해결하기 - validator 2.0.0(JSR-380) 적용 (0) | 2020.10.21 |
Spring transactional (0) | 2020.07.15 |
Mybatis Cause: java.lang.NumberFormatException: For input string: "Y" 에러 해결방법 (0) | 2020.04.14 |
(Spring) XSS 필터 - jsoup (0) | 2020.01.16 |