Springboot整合mysql 5.7 实现增删改查

文章讲述了在SpringBoot项目中遇到的无法解析mysql类和包的问题,以及解决这个问题的方法,涉及到JDBC连接失败和MySQL驱动版本不匹配的情况。同时提到了useSSL配置参数的影响,并给出了POM.xml文件中的相关依赖配置示例,包括SpringBoot版本、MySQL驱动版本的选择。此外,还提及了Server层和Mapper层的注解使用,以及批量修改和新增数据的示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

出现 Cannot resolve class or package ‘mysql’处理方法
https://blog.youkuaiyun.com/zhouhan_0509/article/details/127319458

这个是因为连接mysql的版本的关系,cj是8.0的

Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsExc

https://blog.youkuaiyun.com/RavenWE/article/details/121482923

useSSL=false和true的区别
https://blog.youkuaiyun.com/sungancd/article/details/119183605

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>kafka</artifactId>
    <version>1.0-SNAPSHOT</version>

    <!--springboot启动类依赖导入-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.2.RELEASE</version>
        <relativePath/>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.71</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.38</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.1</version>
        </dependency>

    </dependencies>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

</project>

SpringBoot中Server层以及Mapper层常用注解

SpringBoot项目连接MySQL数据库

IDEA创建Mapper.xml文件

mapper层
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
批量修改或者新增
在这里插入图片描述

@Controller
@RequestMapping("/hello")
public class Test1Controller {

    @Autowired
    private OrderServiceImpl orderServiceImpl;

    @RequestMapping("/h")
    public void test(){
       // System.out.println(orderService.findById());

        /*Order order = new Order();
        order.setOrderName("圣女果");
        order.setOrderId(4L);
        order.setFeature("贵且好吃");
        System.out.println(order);
        //orderService.updateById(order);
        System.out.println(orderServiceImpl.saveOrUpdate(order));*/

        List <Order> orderList = new ArrayList<>();
        orderList.add(new Order().setOrderId(1L).setOrderName("批量修改"));
        orderList.add(new Order().setOrderId(5L).setOrderName("新增水果").setNumber("100005").setFeature("批量新增或者修改测试"));
        System.out.println(orderServiceImpl.saveOrUpdateBatch(orderList));
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凌晨里的无聊人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值