Spring boot 后端业务流程1链接测试数据库

       配置pom文件

<dependencies>
    <!-- springframework       -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web-services</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

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

    <!--        druid-springboot 数据库连接池-->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.2.4</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

        配置yml文件

spring:
  datasource:
    druid:
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://127.0.0.1:3306/自己的数据库?serverTimezone = GMT
      username: root
      password: root

server:
  port: 80
  servlet:
    context-path: 

创建实体类存储数据库获取的数据

user实体类代码:

@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {

    @TableId(type= IdType.AUTO)
    private int uid;
    private String username;
    private String pwd;

}

步骤导入注解

@Data
@NoArgsConstructor
@AllArgsConstructor

填写属性,然后给属性加注解

编写Mapper

@Mapper
public interface UserMapper extends BaseMapper<User> {
}

编写测试类,测试是否链接数据库成功(每走一步测一步,不要全部写完在测试)

@Autowired
UserMapper mapper;

@Test
public void getAllUserTest(){
    System.out.println(mapper.selectList(null));
}

mapper有红色波浪线很正常,因为idea检测不到实体类中的getset等方法,但是注解已经自动加载了

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值