MyBatis 映射SQL的几种方式
2017-05-15 21:58
253 查看
1配置文件方式:
ex:
1.1 SQL映射文件
<mapper namespace="com.test.dao.EmployeeMapper">
<select id="getEmpById" resultType="com.test.beans.Employee">
select id,last_name lastName,email,gender from tb1_emplyee where id = #{id}
</select>
</mapper>
1.2全局配置文件:
使用Mapper标签进行绑定:
<mappers>
<mapper resource="EmployeeMapper.xml" />
</mappers>2.注解方式:
定义一个接口:
public interface EmployeeMapperAnnotation {
@Select("select id,last_name lastName,email,gender from tb1_emplyee where id = #{id}")
public Employee getEmpById(Integer id);
}
然后在全局配置文件中进行注册:
<mappers>
<mapper class="com.test.dao.EmployeeMapperAnnotation"></mapper>
</mappers>3.批量注册
<mappers>
<package name="com.atguigu.mybatis.dao"/>
</mappers>
tips:
映射文件名必须和接口同名,并且放在与接口同一目录下,不然注册不了。
ex:
1.1 SQL映射文件
<mapper namespace="com.test.dao.EmployeeMapper">
<select id="getEmpById" resultType="com.test.beans.Employee">
select id,last_name lastName,email,gender from tb1_emplyee where id = #{id}
</select>
</mapper>
1.2全局配置文件:
使用Mapper标签进行绑定:
<mappers>
<mapper resource="EmployeeMapper.xml" />
</mappers>2.注解方式:
定义一个接口:
public interface EmployeeMapperAnnotation {
@Select("select id,last_name lastName,email,gender from tb1_emplyee where id = #{id}")
public Employee getEmpById(Integer id);
}
然后在全局配置文件中进行注册:
<mappers>
<mapper class="com.test.dao.EmployeeMapperAnnotation"></mapper>
</mappers>3.批量注册
<mappers>
<package name="com.atguigu.mybatis.dao"/>
</mappers>
tips:
映射文件名必须和接口同名,并且放在与接口同一目录下,不然注册不了。
相关文章推荐
- mybatis 构建SqlSessionFactory的几种方式 以及调用sql映射语句的几种方式
- MyBatis mapper.xml配置一对一关系映射的几种方式整理
- mybatis的sql中字段两种映射(映射到实体)方式
- MyBatis SqlSessionFactory的几种常见创建方式
- mybatis和spring整合的几种方式及使用注解简化sql(不使用xml方式写sql)
- myBatis中的语句映射几种特别方式
- mybatis中注册映射sql的Mapper的三种方式详解
- MyBatis SqlSessionFactory的几种常见创建方式
- Mybatis SQL语句的两种映射方式 mapper的xml配置和接口两种方式
- javaWeb项目SpringMVC3.2.1与Mybatis3.0.4整合实例(Mybaits-spring配置文件的几种方式)之一SqlSessionDaoSupport方式
- MyBatis学习 之 二、SQL语句映射文件(1)resultMap
- 几种常见SQL分页方式效率比较
- 几种常见SQL分页方式效率比较
- spring加载hibernate映射文件的几种方式
- LocalSessionFactoryBean加载Hibernate 映射的几种方式及区别
- sqlplus的几种登陆方式
- MyBatis学习 之 二、SQL语句映射文件(2)增删改查、参数、缓存
- 几种常见SQL分页方式效率比较
- 几种常见SQL分页方式效率比较
- Mybatis学习笔记三(Mybatis SQL映射文件)