SpringBoot 在启动类 添加读取 Mapper 接口

//启动类上,添加 @MapperScan("com.liancui.mapper") 

@EnableScheduling
@EnableFileStorage
@ServletComponentScan
@SpringBootApplication
@MapperScan("com.jsh.erp.datasource.mappers")
@MapperScan("com.liancui.mapper")
public class ErpApplication{
    public static void main(String[] args) throws IOException {
        ConfigurableApplicationContext context = SpringApplication.run(ErpApplication.class, args);
        Environment environment = context.getBean(Environment.class);
        System.out.println("启动成功,后端服务API地址:http://" + ComputerInfo.getIpAddr() + ":"
                + environment.getProperty("server.port") + "/jshERP-boot/doc.html");
        System.out.println("您还需启动前端服务,启动命令:yarn run serve 或 npm run serve,测试用户:ttt,密码:777777");
    }
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Spring Boot中配置MyBatis需要以下步骤: 1. 添加MyBatis和MyBatis-Spring依赖 在pom.xml文件中添加以下依赖: ``` <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.2.0</version> </dependency> ``` 2. 配置数据源 在application.properties文件中配置数据源: ``` spring.datasource.url=jdbc:mysql://localhost:3306/test spring.datasource.username=root spring.datasource.password=root spring.datasource.driver-class-name=com.mysql.jdbc.Driver ``` 3. 配置MyBatis 在application.properties文件中配置MyBatis: ``` mybatis.mapper-locations=classpath:mapper/*.xml mybatis.type-aliases-package=com.example.demo.entity ``` 4. 创建Mapper接口和XML文件 创建Mapper接口和XML文件,例如: ``` package com.example.demo.mapper; import com.example.demo.entity.User; public interface UserMapper { User getUserById(Integer id); } ``` ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.example.demo.mapper.UserMapper"> <select id="getUserById" parameterType="java.lang.Integer" resultType="com.example.demo.entity.User"> select * from user where id = #{id} </select> </mapper> ``` 5. 注册Mapper接口启动中注册Mapper接口: ``` @SpringBootApplication @MapperScan("com.example.demo.mapper") public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } ``` 以上就是在Spring Boot中配置MyBatis的步骤。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

tengyuxin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值