spring框架学习之mybatis

1.mybatis是什么?

说通俗点就是简化简单重复麻烦的sql语句

2.如何运行简单的mybatis实例?

思路:

(1)连接数据库,以MySQL为例,大致实现如下效果

(2)上官网:https://mybatis.org/mybatis-3/zh/getting-started.html

了解组成,需要创建的配置文件和依赖

    <dependencies>
        <!-- mybatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.6</version>
        </dependency>
        <!-- mysql-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.22</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.1</version>
            <scope>test</scope>
        </dependency>
        <!-- 简化实体类工具包 -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.16</version>
            <scope>provided</scope>
        </dependency>



    </dependencies>

(3)按照官网配置mybatis-config.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">
<configuration>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.cj.jdbc.Driver"/>#驱动
                <property name="url" value="jdbc:mysql://localhost:3306/test?userSSL=true&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=UTC"/>
                <property name="username" value="root"/>#用户名
                <property name="password" value="123456"/>#密码
            </dataSource>
        </environment>
    </environments>
    <mappers>
        <mapper resource="com/liang/dao/UserDaoMapper.xml"/>
    </mappers>
</configuration>

(4)上网找一个简单的入门实例或者看视频即可

推荐:https://www.cnblogs.com/henuliulei/p/14466732.html

总结:任何知识都不难,入门很容易,重在平时多练!

posted @ 2021-09-11 17:53  程序员亮亮丫!!  阅读(46)  评论(0编辑  收藏  举报