JDK 1.8
mysql 5.7--经典
maven 3.6.1
回顾:
JDBC
Mysql
java基础
Maven知识
junit
SSM框架:配置文件,最好的方式是看官网文档:https://mybatis.org/mybatis-3/zh/index.html
简介
1. 什么是mybatis
优秀的持久层框架
2. 为什么需要mybatis
如何获得mybatis
什么是持久层?
持久化,就是将程序的数据在持久状态和瞬时状态转化的过程,存到数据库里
持久状态:数据库
瞬时状态:内存--断电即失
把内存中的数据持久化
持久化方式:
数据库--jdbc IO文件持久化(耗资源)
为什么持久化?
1. 内存贵 2. 有些对象不能丢失
使用的人多---
第一个mybatis程序
1. 搭建环境
2. 导入jar包
3. 编写代码
4. 测试
1. 搭建环境:数据库
2. 新建项目
3. 导入pom依赖
4. 新建模块
5. 编写mybatis-config.xml
6.编写mybatis工具类
7. 编写代码:实体类,Dao接口,接口实现类
8. 测试
注意点:
org.apache.ibatis.binding.BindingException: Type interface com.kuang.dao.UserDao is not known to the MapperRegistry.
java.lang.ExceptionInInitializerError
at com.kuang.dao.UserDaoTest.test(UserDaoTest.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### The error may exist in com/kuang/dao/UserMapper.xml
作业--工厂模式