自定义持久层框架的代码实现一

Terwer...大约 4 分钟MyBatis后端开发开源框架配置文件项目结构具体代码

项目结构

.
├── IPersistence
│   ├── IPersistence.iml
│   ├── pom.xml
│   └── src
└── IPersistence_test
    ├── IPersistence_test.iml
    ├── pom.xml
    ├── src
    └── target

具体代码

sqlMapperConfig.xml配置文件

<configuration>
    <!-- 存放数据库配置信息 -->
    <dataSource>
        <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/zdy_mybatis"></property>
        <property name="username" value="root"></property>
        <property name="password" value="123456"></property>
    </dataSource>

    <!-- 存放mapper.xml全路径 -->
    <mapper resource="UserMapper.xml" />
</configuration>

UserMapper.xml配置文件

<mapper namespace="user">
    <!-- sql的唯一标识:namespace.id组合:statementId -->
    <select id="selectList" resultType="com.terwergreen.pojo.User">
        select * from user
    </select>
    <select id="selectOne" resultType="com.terwergreen.pojo.User" parameterType="com.terwergreen.pojo.User">
        select * from user where id = #{id} and username = #{username}
    </select>
</mapper>

读取资源处理,Resources类

SqlSessionFactoryBuider工厂构建对象

配置文件解析

mapper映射文件解析

SqlSession的具体实现

文章更新历史

2022/05/08 feat:增加Kotlin实现。

评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v2.14.9