zoukankan      html  css  js  c++  java
  • 解决spring boot jpa查询,语句正确,返回为空问题

    JPA(Hibernate),拥有很强大的能力,极大简化DAO层的开发

    Spring Boot实现的是一站式全包,但是数据库是比较特殊的存在,在开发时可以使用Embedded数据库如DerBy等,但是实际环境下,都会把数据库分离到另一台专用服务器,在连接的时候,可能会出现和开发时不一样的各种BUG

     调用查询接口,结果如下:

    [
        {},
        {},
        {}
    ]

    在调用它的时候会返回null

    原因有2

    1.传进去的参数可能不正确

    需要我们debug或输出,细细查看

    2.查询字符串有中文

    原因可能是字符集的锅,在windows上的MySQL数据库默认使用UTF-8,而linux上通过apt安装的MySQL默认是latin
    application.properties文件database 的 url后面加上?useUnicode=true&characterEncoding=utf-8声明,此次连接使用utf-8字符集

    spring.datasource.url=jdbc:mysql://localhost:3306/students?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8

    再来查询:

    参考文章:

    https://www.jianshu.com/p/d001a62ecdaa




  • 相关阅读:
    分治
    #include<algorithm>
    c++标准模板库的使用
    mysql_day03
    mysql_day02
    mysql_day01
    mongodb的安装
    迭代器和生成器简单介绍
    File文件操作
    数据类型
  • 原文地址:https://www.cnblogs.com/longronglang/p/12232718.html
Copyright © 2011-2022 走看看