首先,项目依赖
<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);
} }