Mybatis-Plus XML文件不放在Resource而放在Dao之后

如果你不想将存放sql的xml文件放入resource目录下,而是想和dao放在同一级目录下,推荐使用下面的方式(个人觉得结构更加清晰)
在这里插入图片描述

依赖导入

导入mybatis-plus的依赖

		 <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.2</version>
        </dependency>

Dao(Mapper)配置

在这里插入图片描述
在这里插入图片描述

Service配置

在这里插入图片描述
在这里插入图片描述

pom文件配置

在这里插入图片描述

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Spring Boot项目中使用MyBatis-Plus,需要先添加相应的依赖。可以在项目的pom.xml文件中添加以下依赖: ```xml <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.3.1</version> </dependency> ``` 添加依赖后,在application.properties或application.yml文件中配置数据库连接信息。 然后,在项目中创建MyBatis-Plus的mapper接口和xml文件。mapper接口需要继承BaseMapper接口,xml文件中按照MyBatis的语法编写SQL语句。 接下来,需要在启动类中添加MyBatis-Plus的配置。可以使用MybatisPlusAutoConfiguration类来自动配置MyBatis-Plus,也可以手动配置。以下是手动配置的示例: ```java @Configuration @MapperScan("com.example.demo.mapper") public class MybatisPlusConfig { @Bean public PaginationInterceptor paginationInterceptor() { return new PaginationInterceptor(); } } ``` 以上代码中,我们配置了分页插件PaginationInterceptor。同时,使用@MapperScan注解指定mapper接口所在的包路径。 最后,在xml文件中使用mapper标签来映射mapper接口。例如: ```xml <mapper namespace="com.example.demo.mapper.UserMapper"> <resultMap id="BaseResultMap" type="com.example.demo.entity.User"> <id column="id" property="id"/> <result column="name" property="name"/> <result column="age" property="age"/> </resultMap> <select id="getUserById" resultMap="BaseResultMap"> select id,name,age from user where id=#{id} </select> <insert id="insertUser" parameterType="com.example.demo.entity.User"> insert into user(name,age) values(#{name},#{age}) </insert> <update id="updateUserById" parameterType="com.example.demo.entity.User"> update user set name=#{name},age=#{age} where id=#{id} </update> <delete id="deleteUserById" parameterType="int"> delete from user where id=#{id} </delete> </mapper> ``` 以上是MyBatis-Plus的基本配置和使用方法。如果需要更详细的配置和使用说明,可以参考MyBatis-Plus的官方文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值