代码改变世界

mybatis-spring

2016-07-30 23:39  微服务专家  阅读(122)  评论(0编辑  收藏  举报

现成的中文文档

 

首先,项目依赖 

<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.1.1</version>
</dependency>

对象和sql的映射关系

@Mapper
public interface CityMapper {

    @Select("SELECT * FROM CITY WHERE state = #{state}")
    City findByState(@Param("state") String state);

}

 

使用sqlSession调用

@Component
public class CityDao {

    @Autowired
    private SqlSession sqlSession;

    public City selectCityById(long id) {
        return this.sqlSession.selectOne("selectCityById", id);
    }

}