Mybatis在springboot中的mapper.xml文件开头如何书写

Mybatis在springboot中的mapper.xml文件开头如何书写 stuSelectMapper.java 文件 @Repository@Ma

Mybatis在springboot中的mapper.xml文件开头如何书写

stuSelectMapper.java 文件

@Repository
@Mapper
public interface stuSelectMapper {/*** 返回女孩* @return*/List findGirls();
}

stuSelectMapper.xml 文件




其中:

    namespace:对应Mapper文件所在"地址",即Mapper文件所在包名.Mapper名.务必要写正确!!!insert/delete/updata/select id: 对应要实现的方法的名称.resultType: 返回值的类型. 实体类名称.返回的是List,只需要写stu即可,stu是一个类。完整的写法应该是             resultType="com.ylyang.learning.app.entity.stu"。但是在yml文件中配置时我们配置了type- aliases-package: com.ylyang.learning.app.entity,指明了实体类所在位置。因此,此时可简写resultType="stu"insert、update、delete 使用的是 parameterType.select 使用的是 resultType.-->

注:namespace中必须为stuSelectMapper类的完整命名,这样stuSelectMapper类就和stuSelectMapper.xml文件绑定到一起了。

这样就可以看作是:stuSelectMapper中声明了要实现什么功能;stuSelectMapper.xml中告知具体怎么实现这个功能。