Skip to content

Instantly share code, notes, and snippets.

@m-reza-rahman
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save m-reza-rahman/1b6600d3c500d9f86bde to your computer and use it in GitHub Desktop.

Select an option

Save m-reza-rahman/1b6600d3c500d9f86bde to your computer and use it in GitHub Desktop.
MyBatis-CDI Example
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