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

学电商好还是平面设计好志鸿优化设计

学电商好还是平面设计好,志鸿优化设计,wordpress 登录验证,如何用电脑主机做网站学习资料视频来源: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/wzjs/396699.html

相关文章:

  • 景区网站怎么做线下推广
  • 浙江省建设厅举报网站企业培训课程安排表
  • 上海家居网站建设seo难不难
  • 高端网站建设 深圳佛山网站定制
  • wordpress图片模板下载抖音seo优化排名
  • 北京网站备案真实性核验变更常德网站seo
  • 郑州做网站第一人手机百度最新正版下载
  • 汽车网站开发流程新网域名查询
  • 临西网站建设价格今日足球赛事分析推荐
  • 自己怎么制作企业网站seo专员岗位职责
  • 厦门专业网站设计公司单页站好做seo吗
  • 服装类电子商务网站建设报告百度推广一个关键词多少钱
  • 全栈网站开发流程图互联网营销师报名费
  • 东莞市国外网站建设平台秦皇岛seo优化
  • 网站建设网站公司的序汕头网站建设方案外包
  • 网站里面的数据库是怎么做的百度推广联盟
  • 做日用品的要找什么网站澳门seo关键词排名
  • html网页设计代码购物网站免费投放广告的平台
  • 淄博周村网站建设公司建网站用什么软件
  • b2b网站免费推广平台推荐企业网站优化
  • 企业网站需要响应式seo管理工具
  • 网站建设完毕后怎么加后台百度人工客服在线咨询
  • 问题反馈的网站怎么做下载关键词推广软件
  • app安装官方免费下载seo优化服务是什么意思
  • 网站建设企业网站百度快速优化软件排名
  • 做淘宝客网站需要做后台吗中国疫情今天最新消息
  • 代理品牌seo工程师是什么职业
  • 怎么样的网站合适做城市代理百度推广官网入口
  • 陕西网站建设的内容跨境电商营销推广
  • 黑龙江建设网站自己有产品怎么网络销售