发表于: 2017-12-20 20:24:18

1 600


编辑日报内容...

今天完成的事情:今天算是彻底解决了任务一的第十七步。


完成通过mybatis对数据库进行增删改查。


InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");//加载mybatis-config.xml里面的配置
//获取并开启数据库链接和SQL执行方法
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
SqlSession session = sqlSessionFactory.openSession();

明天计划的事情:

明天开始完成任务十九到二十一。

然后回头把关于springmybatis的流程与心得整理一下。

 

遇到的问题:


1.关于系统找不到UserMapper.xmlXML的异常。

 

如上图,首先是程序里和xml里注册的路径必须保持一致,不一致就会报错。

然后,在mybatis-config.xml中对文件进行注册时,需要用斜杠分开而不是用点分开。然后IDEA建议把所有的资源配置文件放在resources文件夹下。


2. 关于mybatis-config.xml中配置mysql数据源的异常。

方法有两种,第一种是把数据库的链接单独作为资源文件并在mybatis-config.xml中注册。第二种就是直接在mybatis-config.xml中写好。

<configuration>
<properties resource="JDBC.properties"></properties>
<settings>

<environments default="mysql">
<environment id="mysql">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>

</dataSource>

<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/mybatis"/>
<property name="username" value="root"/>
<property name="password" value="lucifer"/>
</dataSource>


3.log4j该如何配置。

照着网上的教程配置了好多,但是总是只有警告而没有程序具体的操作,期间似乎成功过一次,但是一到别的程序上,就行不通了。


4.配置日志文件总会输出这个,翻译说是非法反射。要怎么才能解决。

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.ibatis.reflection.Reflector (file:/C:/Users/lucifer/.m2/repository/org/mybatis/mybatis/3.3.0/mybatis-3.3.0.jar) to method java.lang.Class.checkPackageAccess(java.lang.SecurityManager,java.lang.ClassLoader,boolean)
WARNING: Please consider reporting this to the maintainers of org.apache.ibatis.reflection.Reflector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release


收获:


1.如何将JDBC数据源独立出mybatis-config.xml。


2.利用list将mybatis读取的数据输出出来。


3.mybatis果然是神器啊,这么简单的程序就可以完成对数据库的操作,写程序真的变成了一种享受,虽然有一些配置比较复杂,但是熟悉之后感觉也没什么。



进度:任务一的第十七步算是彻底结束,总算是迈过了学习的第一大门槛。

http://task.ptteng.com/zentao/project-task-490.html




返回列表 返回列表
评论

    分享到