SpringBoot-Mybatis整合

1.主程序
package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**

  • @Description:
  • @author: YuanTong-ZXY
  • @Date: 2019/2/19 15:15
    */
    @SpringBootApplication
    public class DemoApplication {
    public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class,args);
    }
    }

2.controller层
package com.example.demo.controller;

import com.example.demo.service.UserServiceImpl;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**

  • @Description:

  • @author: YuanTong-ZXY

  • @Date: 2019/2/19 15:09
    */
    @RestController
    @RequestMapping("/testboot")
    public class TestBootController {
    @Resource
    private UserServiceImpl userService;

    @RequestMapping("getuser")
    public Integer getUser() {
    Integer userById = userService.getUserById();
    return userById;
    }
    }
    3、service层
    package com.example.demo.service;
    /**

  • @Description:

  • @author: YuanTong-ZXY

  • @Date: 2019/2/19 15:59
    /
    import com.example.demo.mapper.UserDao;
    import org.springframework.stereotype.Service;
    import javax.annotation.Resource;
    @Service("userService")
    public class UserServiceImpl{
    @Resource
    private UserDao userDao;
    public Integer getUserById() {
    return userDao.selectCount();
    }
    }
    4.mapper
    package com.example.demo.mapper;
    /
    *

  • @Description:

  • @author: YuanTong-ZXY

  • @Date: 2019/2/19 15:54
    /
    import org.apache.ibatis.annotations.Mapper;
    @Mapper
    public interface UserDao {
    Integer selectCount();
    }
    5.mapper.xml




6.application.yml
spring:
profiles:
active: dev
datasource:
url: jdbc:mysql://localhost:3306/saasboard
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
7.pom.xml 文件

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0

org.springframework.boot
spring-boot-starter-parent
2.1.3.RELEASE


com.example
demo
0.0.1-SNAPSHOT
demo
Demo project for Spring Boot

1.8




org.springframework.boot
spring-boot-starter-web


org.mybatis.spring.boot
mybatis-spring-boot-starter
2.0.0

    
        org.springframework.boot
        spring-boot-starter-test
        test
    
    
    
        mysql
        mysql-connector-java
        5.1.47
    
    
        com.alibaba
        druid
        1.0.18
    


    
        
            org.springframework.boot
            spring-boot-maven-plugin
        
    

你可能感兴趣的:(SpringBoot-Mybatis整合)