mybatis的通用mapper的配置与使用

it2023-09-03  77

pom.xml文件中导入依赖包如下:

<!-- 通用mapper --> <dependency>   <groupId>tk.mybatis</groupId>   <artifactId>mapper</artifactId>   <version>3.5.2</version> </dependency>

 

mapper接口继承BaseMapper

BaseMapper<Student>中的Student指的是要通过StudentMapper接口获取到的实体类的类型

也就是与数据库表对应的那个pojo类

int类型的数据要用包装类,通用mapper默认只识别String类型(总之不识别int类型),最好习惯性的都写包装类

@Table(name="要查询的表名字")

service层调用mapper

通用的mapper中的方法:(sm指的是mapper接口的对象)

然后就可以实现之前手动mapper.xml文件中的索然无味的增删改查

最新回复(0)