zoukankan      html  css  js  c++  java
  • Mybatis 搭建遇到的坑

    1.

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="com">
    <select id = "findById" parameterType="int" resultType="User">
    SELECT * FROM Book WHERE id=#{id}
    </select>
    </mapper>

    提示下面飘红不可用,导致在其他类里面引用:

    import org.apache.ibatis.io.Resources;

    import org.apache.ibatis.*,未能找到
    我还以为是缺少jar ibatis ,在pom.xml中 配置ibatis也不能成功,花费了不少时间.
    解决办法:
    在 File->Settings->Schemas and DTDs 中配置不信任链接

    2. SqlSession session = sqlMapper.openSession(); 获取不到session值,为null

    @font-face{ font-family:"Times New Roman"; } @font-face{ font-family:"宋体"; } @font-face{ font-family:"Calibri"; } @font-face{ font-family:"SimSun"; } p.MsoNormal{ mso-style-name:Normal; mso-style-parent:""; margin:0pt; margin-bottom:.0001pt; font-family:Calibri; mso-fareast-font-family:SimSun; mso-bidi-font-family:'Times New Roman'; } span.msoIns{ mso-style-type:export-only; mso-style-name:""; text-decoration:underline; text-underline:single; color:blue; } span.msoDel{ mso-style-type:export-only; mso-style-name:""; text-decoration:line-through; color:red; } @page{mso-page-border-surround-header:no; mso-page-border-surround-footer:no;}@page Section0{ } div.Section0{page:Section0;}

    Caused by: java.lang.NullPointerException

    at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:95)

    ... 2 more

    出错原因:
    一开始按照教程操作,在配置mybatis-config.xml的时候 <environments default="development">

    调试发现session 为null,
    找到这篇解释,出自: https://blog.csdn.net/u012972315/article/details/51725646
    下面为引用内容:

    后来查看mybatis文档才了解到,在mybatis配置时,可能由于我们开发时的数据库环境和最终上线时的数据库环境不同,因此可以在配置文件中配置多个数据库环境;
    即在 < enviroments >标签下可以配置多个< enviroment>标签,每一个< enviroment >标签对应一个数据库环境
    而不同的数据库环境通过< enviroment > 标签的 id 属性用以区分
    那么具体开发时如果知道使用的是哪一个环境呢?
    在< envirments> 标签里有一个default属性,该属性对应的是下面的不同的< enviroment > 的id属性
    default的值为哪一个id,则代表此时使用的是哪一个environment数据库环境

    解决办法: <environments default="book">,default= 需要使用数据库的id.
    <!-- 对事务管理和连接池配置 -->
    <environments default="book">
    <environment id="book">
    <transactionManager type="JDBC"/>
    <dataSource type="POOLED">
    <property name="driver" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/gossip"/>
    <property name="username" value="root"/>
    <property name="password" value="123456"/>
    </dataSource>
    </environment>
    </environments>
    3.
    WARN: Establishing SSL connection without server's identity verification is not recommended.
    According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set.
    For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'.
    You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore
    for server certificate verification.
    出错原因:
    mybatis-config.xml 配置中需要增加一句 &useSSL=false,
    <property name="url" value="jdbc:mysql://localhost:3306/gossip?autoReconnect=true&amp;useSSL=false"/>
    注意 在xml中,
    & : &amp;
    < : &lt;
    > : &gt;
    " : &quot;
    ' : &apos;
  • 相关阅读:
    go语言从零学起(三) -- chat实现的思考
    go语言从零学起(二)--list循环删除元素(转载)
    go语言从零学起(一) -- 文档教程篇
    Spring框架事务支持模型的优势
    Thymeleaf
    社保到底是多交好,还是少交好?
    使用静态工厂方法而不是构造器
    EJB、RMI、XMLRPC、Hessian、Thrift 、Protobuf
    MySQL存储过程
    MySQL常用功能语句分类总结
  • 原文地址:https://www.cnblogs.com/changlili/p/10123689.html
Copyright © 2011-2022 走看看