发表于: 2018-04-09 22:56:04

1 646


今日完成的事情:

         完成了mybatis连接数据库。
          经过师兄的指导:终于跑通了数据库:

这是最后的输出结果,最后两个没出来是因为昨天报错太多,然后重新弄结果把数据库也弄没了。

 1. 我在翻看昨天日报时mybatis的配置文件这个其实是对的,然后被我改错了。

 2.昨天日报在UserMapper里这个配置错了,最后被我改过来了。

说明对映射文件不够清楚。

然后查了下映射文件

全局配置文件SqlMapConfig.xml是MyBatis的全局配置文件,它的名称可以任意命名的

MyBatis映射器配置的四种方式:


这里有很详细的介绍:https://baijiahao.baidu.com/s?id=1570270238830534&wfr=spider&for=pc

明天计划的事情:

      spring整合mybatis

遇到的问题:

         今天在spring框架中遇到个问题不是很懂:

            spring的依赖注入是靠bean 来实现

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
                       http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                       http://www.springframework.org/schema/context
                       http://www.springframework.org/schema/context/spring-context-3.1.xsd
                       http://www.springframework.org/schema/mvc
                       http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

        而spring官网只给了  

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd">

那么多出来是jar的配置?从而创造“工厂”?

最后Junit测试文件调用

以前通过New,由程序本身操作,

 SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);

然后spring loc的控制反转直接给一个null.

这个实现过程很蒙,所以代码写到测试时不知道怎么写了。


收获:

能理解前几天看的内容了,但是实际操作不知道怎么赋值调用了。


返回列表 返回列表
评论

    分享到