Last active
August 29, 2015 14:08
-
-
Save m-reza-rahman/1b6600d3c500d9f86bde to your computer and use it in GitHub Desktop.
MyBatis-CDI Example
This file contains hidden or 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
| public class SqlSessionFactoryProvider { | |
| @Produces @ApplicationScoped | |
| public SqlSessionFactory produceFactory() { | |
| String resource = "org/mybatis/example/mybatis-config.xml"; | |
| InputStream inputStream = Resources.getResourceAsStream(resource); | |
| SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); | |
| return sqlSessionFactory; | |
| } | |
| } | |
| public interface UserMapper { | |
| @Select("SELECT * FROM users WHERE id = #{userId}") | |
| User getUser(@Param("userId") String userId); | |
| } | |
| public class FooServiceImpl implements FooService { | |
| @Inject @Mapper private UserMapper userMapper; | |
| public User doSomeStuff(String userId) { | |
| return this.userMapper.getUser(userId); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment