SpringBoot2 黑马B站版 -06 SpringBoot的SSMP整合案例

SpringBoot2 黑马B站版 -06 SpringBoot的SSMP整合案例,第1张

SpringBoot2 黑马B站版 -06 SpringBoot的SSMP整合案例

文章目录
  • 技术
  • 新建工程
  • 修改Pom配置文件
  • 实体类LomBok简单使用
  • application.yml文件配置
  • Dao层
  • 测试类
  • 数据库
  • 可能遇到的问题
    • CLIENT_PLUGIN_AUTH is required

MyBatisPlus使用时候,要求你的数据库的名字与表名一致,不然找不到


技术
- 实体类开发 LomBok
- Dao开发 MyBatisPlus
- Service开发
- Controller开发   Restful
- 页面开发  Vue+ElementUI
- 项目异常处理
- 分页展示
新建工程


修改Pom配置文件


    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.6.1
         
    
    com.abc
    learn
    0.0.1-SNAPSHOT




    
        1.8
    
    


        
        
            com.alibaba
            druid-spring-boot-starter
            1.2.8
        



        
        
            com.baomidou
            mybatis-plus-boot-starter
            3.4.3.4
        

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

        
        
            mysql
            mysql-connector-java
            runtime
        

        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    

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


实体类LomBok简单使用

https://blog.csdn.net/qq_44627608/article/details/121975611

application.yml文件配置
# 服务器端口号
server:
  port: 80

# SQL驱动
spring:
  datasource:
    druid:
      driver-class-name: com.mysql.jdbc.Driver
      url: jdbc:mysql://localhost:3306/learn_sql
      username: root
      password: 123456

# MyBatisPlus配置数据库表名的前后缀
mybatis-plus:
  global-config:
    db-config:
      table-prefix: learn_
Dao层
@Mapper
public interface StudentDao extends baseMapper {


}

测试类
package com.abc;

import com.abc.dao.StudentDao;
import com.abc.entity.Student;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
class LearnApplicationTests {


    @Autowired
    private StudentDao dao;





    @Test
    void contextLoads() {

        List lists=dao.selectList(null);
        for (Student entity : lists) {
            System.out.println(entity.toString());
        }


    }

}

数据库

可能遇到的问题 CLIENT_PLUGIN_AUTH is required

更换pom配置文件里的SQL驱动版本

        
        
            mysql
            mysql-connector-java
            runtime
            加入下面这一行,多试几个就ok了。
            5.1.49
        

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5672905.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存