当前位置: 首页 > news >正文

网站软文代写凡客生活官网

网站软文代写,凡客生活官网,golang做网站怎么样,seo关键词是怎么优化的学习资料视频来源:https://www.bilibili.com/video/BV1R14y1W7yS 文章目录 1. 项目介绍1.1 项目结构1.2 项目依赖(1) ipersistent依赖(2) ipersistent-test依赖 1.3 配置文件(1) 核心配置文件(2) 映射配置文件 2. 核心源码类2.1 ipersistentResourcesConfiguration…

学习资料视频来源:https://www.bilibili.com/video/BV1R14y1W7yS

文章目录

  • 1. 项目介绍
    • 1.1 项目结构
    • 1.2 项目依赖
      • (1) ipersistent依赖
      • (2) ipersistent-test依赖
    • 1.3 配置文件
      • (1) 核心配置文件
      • (2) 映射配置文件
  • 2. 核心源码类
    • 2.1 ipersistent
      • Resources
      • Configuration
      • MappedStatement
      • XMLConfigBuilder
      • XMLMapperBuilder
      • SqlSessionFactoryBuilder
      • SqlSessionFactory
      • DefaultSqlSessionFactory
    • 2.2 ipersistent-test
      • 测试类

1. 项目介绍

1.1 项目结构

项目分为2个模块,ipersistent 和ipersistent-test。ipersistent为框架,ipersistent-test为框架使用端,ipersistent-test依赖ipersistent。视频里是使用maven管理项目,我这里是使用gradle管理项目。目录结构如下:
在这里插入图片描述

1.2 项目依赖

(1) ipersistent依赖

plugins {id 'java-library'
}group = 'com.mql'repositories {maven {url 'https://maven.aliyun.com/nexus/content/groups/public/'}mavenCentral()
}dependencies {testImplementation platform('org.junit:junit-bom:5.10.0')testImplementation 'org.junit.jupiter:junit-jupiter'// 引入dom4j依赖,用于解析xml文件api 'dom4j:dom4j:1.6.1'runtimeOnly 'mysql:mysql-connector-java:5.1.40'//阿里德鲁伊数据库连接池implementation ('com.alibaba:druid:1.2.8') implementation 'jaxen:jaxen:1.2.0' annotationProcessor 'org.projectlombok:lombok:1.18.20'compileOnly 'org.projectlombok:lombok:1.18.20'
}

(2) ipersistent-test依赖

plugins {id 'java'
}group = 'com.mql'repositories {mavenCentral()
}dependencies {testImplementation platform('org.junit:junit-bom:5.10.0')testImplementation 'org.junit.jupiter:junit-jupiter'// 引用ipersistentimplementation project(':ipersistent')implementation 'org.apache.logging.log4j:log4j-core:2.14.1'implementation 'org.apache.logging.log4j:log4j-api:2.14.1'
}test {useJUnitPlatform()
}

1.3 配置文件

核心配置文件映射配置文件,都是在ipersistent-test提供。

(1) 核心配置文件

<configuration><!-- 数据源配置 --><datasource><property name="driverClassName" value="com.mysql.jdbc.Driver"/><property name="url" value="jdbc:mysql://localhost:3306/test"/><property name="username" value="root"/><property name="password" value="root"/></datasource><mappers><mapper resource="mapper/UserMapper.xml"/></mappers>
</configuration>

(2) 映射配置文件

<mapper namespace="user"><!--    唯一标识: namespace.id--><!-- 查询所有用户 --><select id="selectList" resultType="com.mqlyes.pojo.User">select * from user</select><!-- 按条件查询用户 --><!--    --><select id="selectOne" resultType="com.mqlyes.pojo.User" parameterType="com.mqlyes.pojo.User">select * from user where id = #{id} and username = #{username}</select>
</mapper>

2. 核心源码类

2.1 ipersistent

Resources

作用:根据路径,加载配置文件,并转换成字节流,比较简单。

public class Resources {/*** 根据配置文件的路径加载配置文件存到内存中* @param path* @return*/public static InputStream getResource(String path) {return Resources.class.getClassLoader().getResourceAsStream(path);}
}

Configuration

作用:Configuration存储核心配置和映射配置文件解析出的配置信息。分别对应dataSource和mappedStatementMap。


/*** 存数据库配置信息 从sqlMapper.xml中解析出的东西*/
public class Configuration {// 数据源对象private DataSource dataSource;// key为 statementIDprivate Map<String, MappedStatement> mappedStatementMap = new HashMap<>();public DataSource getDataSource() {return dataSource;}public void setDataSource(DataSource dataSource) {this.dataSource = dataSource;}public Map<String, MappedStatement> getMappedStatementMap() {return mappedStatementMap;}public void setMappedStatementMap(Map<String, MappedStatement> mappedStatementMap) {this.mappedStatementMap = mappedStatementMap;}
}

MappedStatement

作用:存储映射配置文件中解析出信息,一个MappedStatement对应一个xxxmapper.xml文件

public class MappedStatement {// 唯一标识private String StatementID;private String resultType;private String parameterType;private String sql;public String getStatementID() {return StatementID;}public void setStatementID(String statementID) {StatementID = statementID;}public String getResultType() {return resultType;}public void setResultType(String resultType) {this.resultType = resultType;}public String getParameterType() {return parameterType;}public void setParameterType(String parameterType) {this.parameterType = parameterType;}public String getSql() {return sql;}public void setSql(String sql) {this.sql = sql;}
}

XMLConfigBuilder

作用:先解析核心配置文件中数据库配置信息,封装成Datasource。再解析mapper文件所有路径
调用XMLMapperBuilder解析mapper文件,并封装进MappedStatement。解析二者的过程中,把Datasource和MappedStatement封装进Configuration。

public class XMLConfigBuilder {private Configuration configuration;public XMLConfigBuilder() {this.configuration = new Configuration();}/*** 解析配置文件 封装到Configuration中** @param inputStream* @return*/public Configuration parse(InputStream inputStream) throws DocumentException {Document document = new SAXReader().read(inputStream);Element rootElement = document.getRootElement();List<Element> list = rootElement.selectNodes("//property");Properties properties = new Properties();for (Element element : list) {String name = element.attributeValue("name");String value = element.attributeValue("value");properties.put(name, value);}// 创建数据源对象DruidDataSource druidDataSource = new DruidDataSource();druidDataSource.setDriverClassName(properties.getProperty("driver"));druidDataSource.setUrl(properties.getProperty("url"));druidDataSource.setUsername(properties.getProperty("username"));druidDataSource.setPassword(properties.getProperty("password"));configuration.setDataSource(druidDataSource);// 获取映射配置文件路径List<Element> mapperList = rootElement.selectNodes("//mapper");for (Element element : mapperList) {String mapperPath = element.attributeValue("resource");InputStream resource = Resources.getResource(mapperPath);XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(configuration);xmlMapperBuilder.parse(resource);}return configuration;}
}

XMLMapperBuilder


public class XMLMapperBuilder {private Configuration configuration;public XMLMapperBuilder(Configuration configuration) {this.configuration = configuration;}public   void parse(InputStream inputStream) throws DocumentException {Document document = new SAXReader().read(inputStream);Element rootElement = document.getRootElement();String namespace = rootElement.attributeValue("namespace");List<Element> elements = rootElement.selectNodes("//select");for (Element element : elements) {String id = element.attributeValue("id");String resultType = element.attributeValue("resultType");String parameterType = element.attributeValue("parameterType");String sql = element.getTextTrim();MappedStatement mappedStatement = new MappedStatement();mappedStatement.setStatementID(namespace + "." + id);mappedStatement.setSql(sql);mappedStatement.setResultType(resultType);mappedStatement.setParameterType(parameterType);configuration.getMappedStatementMap().put(mappedStatement.getStatementID(), mappedStatement);}}
}

SqlSessionFactoryBuilder

public class SqlSessionFactoryBuilder {public SqlSessionFactory build(InputStream inputStream) throws DocumentException {XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();Configuration configuration = xmlConfigBuilder.parse(inputStream);// 创建SqlSessionFactory工厂对想DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);return defaultSqlSessionFactory;}}

SqlSessionFactory

public interface SqlSessionFactory {
}

DefaultSqlSessionFactory


public class DefaultSqlSessionFactory implements SqlSessionFactory {private Configuration configuration;public DefaultSqlSessionFactory(Configuration configuration) {this.configuration = configuration;}
}

2.2 ipersistent-test

测试类

使用端目前只有一个测试类,看返回结果中的configuration对象信息是否完整。

public class IpersistentTest {@Testpublic void test1() throws Exception {InputStream resource = Resources.getResource("sqlMapConfig.xml");SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resource);System.out.println(build);}
}
http://www.dtcms.com/a/502518.html

相关文章:

  • 最好的品牌设计网站建设手机网站微信支付接口开发教程
  • 重庆品质网站建设销售亚马逊网站建设做什么
  • 网站优化关键词排名海外网站推广公司
  • 在线设计工具的网站怎么做重庆网站租赁空间
  • 西安网站建设xs029立即优化在哪里
  • 最专业网站建设公网站谁建设的
  • 朔州网站建设价格网站布局怎么写
  • minisite网站案例怎样做响应式网站
  • 电商网站建设的核心是什么对电子政务网站建设的建议
  • 台州市建设项目规划网站企业网站建设有什么
  • 匿名聊天网站怎么做今科网站建设公司
  • 早教网站建设方案腾云网站建设
  • 价格网站广告传媒公司注册费用
  • 南昌网站优化国内服装电商平台
  • 怎样做服装网站北京市信息网
  • 单位建设网站的意义如何在网站做推广
  • 一线城市做网站工资有多少钱做外贸网站建设
  • 网站建设意义和作用成都小程序开发公司找哪家
  • wwe中文官网站专业的企业网站制作
  • 数据来源网站怎么做脚注个人建站怎么做网站好
  • 网站负责人核验现场拍摄照片电子件温州城乡建设官网
  • 成为网站有哪些网址?网站页脚模板
  • 互联网怎么做网站服装网站建设策划书的基本结构
  • 什么叫网站地图搜狗站长平台主动提交
  • wordpress 本地建站教程心雨在线高端网站建设网页设计
  • 服务器做多个网站网站模版库
  • 江苏企业建网站排名优化深圳关键词自动排名
  • 工装设计网站案例vi设计的基本要素
  • 石岩做网站哪家好建筑工程类招聘网站
  • 苏州知名高端网站建设在discuz做网站