

mybatis学习日志(一)
source link: https://blog.csdn.net/lanlantanglan/article/details/115572493
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

- 使用的编译器-IDEA 2020
1.项目建立
新建一个maven空项目吗,点击next
给项目取名,确定目录位置
GroupID按照个人喜好取
例如:com.公司名.项目名
等待项目创建完毕
2.maven配置
在pom.xml里面配置
配置代码
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sari.studyMybatis</groupId>
<artifactId>study_01mybatis</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>14</maven.compiler.source>
<maven.compiler.target>14</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.5</version>
</dependency>
<!--链接的是mysql数据库-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.35</version>
</dependency>
<!--日志-->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
</dependency>
<!--单元测试-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
- 其中日志log4j暂无配置教程,等待后续更新
- 点击编译器上面出现的小图标,即可开始下载
3.mybatis配置文件
文件架构如下(这个文件夹需要自己建立,其中java下一定要建package)
- resource:资源文件目录,也就是我们相关配置的文件区域
- java:核心代码区
配置sqlMapConfig.xml,名字自拟,但需要规整
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<!-- mybatis的主配置文件 -->
<configuration>
<!-- 配置环境 -->
<environments default="mysql">
<!-- 配置mysql文件 -->
<environment id="mysql">
<!-- 配置事务类型 -->
<transactionManager type="JDBC"></transactionManager>
<!-- 配置数据源连接池 -->
<dataSource type="POOLED">
<!-- 配置链接数据库的4个基本数据 -->
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/mybatis01?characterEncoding=utf8"/>
<property name="username" value="root"/>
<property name="password" value="LLTL520"/>
</dataSource>
</environment>
</environments>
<!-- 配个DAO的映射配置文件 -->
<mappers>
<mapper class="com.sari.DAO.IUser"/>
</mappers>
<!-- TODO log4j的配置数据文件 -->
</configuration>
- mappers配置下次说
目前仓库还未建立
Recommend
-
72
MyBatis学习笔记(1)—使用篇 MyBatis学习笔记(2)—映射关系篇 MyBatis学习笔记(3)—高级映射之一对一映射 Mybatis学习笔记(4)-高级映射之一对多映射 Mybatis学习笔记(5)-高级映射之多对多映射 Mybatis一项强大的
-
19
Mybatis原理学习
-
59
程序员应该将核心关注点放在业务上,而不应该将时间过多的浪费在CRUD中,多数的ORM框架都把增加、修改与删除做得非常不错了,然后数据库中查询无疑是使用频次最高、复杂度大、与性能密切相关的操作,我们希望
-
19
目录 一、根据XML配置文件构建SqlSessionFactory 二、通过SqlSessionFactory创建SqlSession 三、getMapper获取动态代理对象 一、根据XML配置文件构建...
-
31
一、背景 很久以前听说过ibatis,后来知道ibatis改名mybatis了,之前只是简单的接触过mybatis,没有使用太多,不是太了解。所以趁着周末看了看。 本文主要参考网站: https://mybatis.org/mybatis-3/zh/index.ht...
-
5
mybatis的创建SqlSession的过程:Mybatis使用代理Dao的执行过程:Mybatis只需提供一个Dao接口,就可以实现与数据库的CRUD交互,这种情形,我们很容易想到用JDK动...
-
6
Mybatis在执行Sql查询和更新时,无法知道具体的sql执行时间,是否存在慢查询等问题。需要在执行Sql时能对Sql进行监控,并定位到慢查询的问题发生的位置MybatisSpringSpringBootSpringMVC实现Interceptor接...
-
13
Lemon-CSMyBatis-Plus 入门学习笔记发表于 2020-07-28|更新于 2...
-
3
【MyBatis】MyBatis配置、使用MyBatis操作数据库、开启SQL日志打印 推荐 原创
-
5
V2EX › Java mybatis-plus 有什么办法可以不展示很长的 sql 日志输出吗
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK