MyBatis-Plus实现业务层

MyBatis-Plus实现业务层

  1. 添加依赖

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.7.17</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
  <!--springBoot的依赖-->
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  <dependency>
    <!--mySql的依赖-->
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
  </dependency>
  <!-- Druid 数据库连接池的自动配置和集成支持-->
  <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>1.2.16</version>
  </dependency>
  <!--lomBok-->
  <dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
  </dependency>
  <!--MyBatisPlus-->
  <dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.5.5</version>
  </dependency>

  1. 修改application.yml

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/t311
    username: root
    password: root
    driver-class-name: com.mysql.cj.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource
mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    map-underscore-to-camel-case: false  #使用驼峰命名法

  1. 在dao层

package com.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.entity.Emp;

/**
 * 接口继承基础接口
 */

public interface EmpDao extends BaseMapper<Emp> {

}

  1. 在实体类中

package com.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;

import java.io.Serializable;

@Data
public class Emp implements Serializable {
    private Integer empno;
    private String ename;
    private String job;
    private Integer mgr;
    private String hiredate;
    private Double sal;
    private Double comm;
   private Integer deptno;
}

  1. 在service和impl层

public interface EmpService extends IService<Emp> {
}

@Service
public class EmpServiceimpl extends ServiceImpl<EmpDao, Emp>  implements EmpService {
}

  1. 在controller层

@RestController
public class EmpController {

    @Resource
    private EmpService empService;

    @RequestMapping("showEmps")
    public Object showEmps(){
        return  empService.list();
    }
}

运行后

  • 19
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值