设为首页 加入收藏

TOP

springboot2.1.7整合mybati3.5.2与mysql8.0.13(一)
2019-09-06 00:27:58 】 浏览:18
Tags:springboot2.1.7 整合 mybati3.5.2 mysql8.0.13

springboot2.x已经发布一段时间,博主在这里使用springboot2.1.7整合mybatis3.5.2,使用的数据库为mysql8.0.13

1. 导入依赖

<!--mysql-->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.13</version>
</dependency>    
<!--mybatis-spring-boot-starter-->
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.1.0</version>
</dependency>

2. 在application.properties配置数据源(此文件会被springboot自动扫描)

spring.datasource.url=jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=*********
#mysql8以上版本使用这个
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#mybatis读取根目录下mapper文件夹下的所有以.xml结尾的文件
mybatis.mapper-locations=classpath:/mapper/*.xml

3. 编写controller,service,dao,mapper.xml

AdminController:

package com.gl.pin.web.controller;

import com.gl.pin.service.api.system.entity.AdminEntity;
import com.gl.pin.service.api.system.res.DubboRes;
import com.gl.pin.service.api.system.service.AdminServiceI;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: zjk
 * @Date: 2019/9/3
 * @Description:
 */

@ResponseBody
@Controller
@RequestMapping(value = "/admin")
public class AdminController {

    @Autowired
    AdminServiceI adminServiceI;

    @PostMapping(value = "/login")
    public AdminEntity login(@RequestParam(value = "userName") String userName , @RequestParam (value = "password") String password){
         return adminServiceI.login(userName,password);
    }

}

 AdminService:(AdminServiceI 自行脑补)

package com.gl.pin.service.system.service;

import com.gl.pin.service.api.system.entity.AdminEntity;
import com.gl.pin.service.api.system.res.DubboRes;
import com.gl.pin.service.api.system.service.AdminServiceI;
import com.gl.pin.service.system.dao.AdminDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Auther: zjk
 * @Date: 2019/9/4
 * @Description:
 */
@Service
public class AdminService implements AdminServiceI {

    @Autowired
    AdminDao adminDao;

    @Override
    public AdminEntity login(String userName , String password) {
        return adminDao.login(userName,password);
    }
}

 AdminDao:

package com.gl.pin.service.system.dao;

import com.gl.pin.service.api.system.entity.AdminEntity;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

/**
 * @Auther: zjk
 * @Date: 2019/9/4
 * @De  
		
springboot2.1.7整合mybati3.5.2与mysql8.0.13(一) https://www.cppentry.com/bencandy.php?fid=76&id=250252

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇XML中的XPATH和DTD 下一篇面试官:判断一个数是否为2的整数..