문제

I am writing a web application and I am using MyBatis framework for persistence. I want to use CDI to inject the mappers easily and to manage the transaction declaratively.

도움이 되었습니까?

해결책

MyBatis has official CDI support:

Mapper declaration:

@Mapper
public interface UserMapper {
  @Select("SELECT * FROM users WHERE id = #{userId}")
  User getUser(@Param("userId") String userId);
} 

Mapper Usage:

public class MyService {

    @Inject UserMapper userMapper;

    public User doSomeStuff(String userId) {
       return this.userMapper.getUser(userId);
    }
}

More information in docs: http://mybatis.org/cdi/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top