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

建设企业网站一般多少钱网站建设的分类

建设企业网站一般多少钱,网站建设的分类,南宁百度关键词优化,高密市赏旋网站设计有限公司简单手写SpringIOC框架 环境搭建基于XML方式项目结构项目代码运行结果 基于注解方式项目结构项目代码运行结果 简单手写SpringIOC框架核心原理基于XML方式原理项目结构项目代码运行结果 基于注解方式原理项目结构项目代码运行结果 环境搭建 基于XML方式 项目结构 项目代码 p… 简单手写SpringIOC框架 环境搭建基于XML方式项目结构项目代码运行结果 基于注解方式项目结构项目代码运行结果 简单手写SpringIOC框架核心原理基于XML方式原理项目结构项目代码运行结果 基于注解方式原理项目结构项目代码运行结果 环境搭建 基于XML方式 项目结构 项目代码 pom.xml ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom/groupIdartifactIdspring/artifactIdversion1.0-SNAPSHOT/versionpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.target/propertiesdependenciesdependencygroupIdorg.springframework/groupIdartifactIdspring-core/artifactIdversion5.2.1.RELEASE/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-beans/artifactIdversion5.2.1.RELEASE/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion5.2.1.RELEASE/version/dependency/dependencies/projectUserBean.java package com.spring.bean;/*** author honey* date 2023-08-08 14:58:16*/ public class UserBean { }spring.xml ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdbean iduserBean classcom.spring.bean.UserBean//beansSpringTest01.java package com.spring.test;import com.spring.bean.UserBean; import org.springframework.context.support.ClassPathXmlApplicationContext;/*** author honey* date 2023-08-08 14:59:56*/ public class SpringTest01 {public static void main(String[] args) {// 读取spring.xmlClassPathXmlApplicationContext applicationContext new ClassPathXmlApplicationContext(spring.xml);// 从IOC容器中读取对象UserBean userBean applicationContext.getBean(userBean, UserBean.class);System.out.println(userBean);} }运行结果 基于注解方式 项目结构 项目代码 ScanBean.java package com.spring.bean.scan;import org.springframework.stereotype.Component;/*** author honey* date 2023-08-08 16:37:26*/ Component public class ScanBean { }SpringConfig.java package com.spring.config;import com.spring.bean.UserBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration;/*** author honey* date 2023-08-08 16:30:21*/ Configuration ComponentScan(value {com.spring.bean.scan}) public class SpringConfig {Bean(name user)public UserBean userBean() {return new UserBean();} }SpringTest02.java package com.spring.test;import com.spring.bean.UserBean; import com.spring.bean.scan.ScanBean; import com.spring.config.SpringConfig; import org.springframework.context.annotation.AnnotationConfigApplicationContext;/*** author honey* date 2023-08-08 16:31:25*/ public class SpringTest02 {public static void main(String[] args) {// 加载SpringConfigAnnotationConfigApplicationContext applicationContext new AnnotationConfigApplicationContext(SpringConfig.class);// 从IOC容器中读取对象UserBean userBean applicationContext.getBean(user, UserBean.class);System.out.println(userBean);ScanBean scanBean applicationContext.getBean(scanBean, ScanBean.class);System.out.println(scanBean);} }运行结果 简单手写SpringIOC框架 核心原理 底层使用map集合管理对象keybeanIdvalue实例对象 private final MapString, Object beanMap new ConcurrentHashMap();基于XML方式 原理 基于反射工厂模式DOM技术 使用DOM技术解析spring.xml文件获取bean的id和class属性根据类的完整路径使用反射技术初始化对象使用工厂模式管理初始化对象 项目结构 项目代码 pom.xml ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom/groupIdartifactIdext-spring-ioc/artifactIdversion1.0-SNAPSHOT/versionpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.target/propertiesdependenciesdependencygroupIdorg.springframework/groupIdartifactIdspring-core/artifactIdversion5.2.1.RELEASE/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-beans/artifactIdversion5.2.1.RELEASE/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion5.2.1.RELEASE/version/dependencydependencygroupIddom4j/groupIdartifactIddom4j/artifactIdversion1.6.1/version/dependency/dependencies/projectUserBean.java package com.spring.bean;/*** author honey* date 2023-08-08 16:56:32*/ public class UserBean { }spring.xml ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdbean iduserBean classcom.spring.bean.UserBean//beansSpringIocXml.java package com.spring.ext;import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader; import org.springframework.core.io.ClassPathResource;import java.io.File; import java.io.IOException; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap;/*** author honey* date 2023-08-08 16:57:17*/ public class SpringIocXml {private final MapString, Object beanMap new ConcurrentHashMap();public SpringIocXml() throws IOException, DocumentException {init();}public T T getBean(String name) {return (T) beanMap.get(name);}/*** 初始化IOC容器*/private void init() throws IOException, DocumentException {// 解析spring.xml配置ClassPathResource classPathResource new ClassPathResource(spring.xml);File xmlFile classPathResource.getFile();SAXReader saxReader new SAXReader();Document doc saxReader.read(xmlFile);// 获取根节点Element rootElement doc.getRootElement();// 获取bean节点信息ListElement beans rootElement.elements(bean);for (Element bean : beans) {try {String beanId bean.attribute(id).getValue();String classPath bean.attribute(class).getValue();// 使用反射机制初始化对象并将对象存入Map集合Class? clazz Class.forName(classPath);Object object clazz.newInstance();beanMap.put(beanId, object);} catch (Exception e) {e.printStackTrace();}}}}SpringTest01.java package com.spring.test;import com.spring.bean.UserBean; import com.spring.ext.SpringIocXml; import org.dom4j.DocumentException;import java.io.IOException;/*** author honey* date 2023-08-08 17:04:35*/ public class SpringTest01 {public static void main(String[] args) throws DocumentException, IOException {SpringIocXml springIocXml new SpringIocXml();UserBean userBean springIocXml.getBean(userBean);System.out.println(userBean);} }运行结果 基于注解方式 原理 基于反射工厂模式实现 判断配置类上是否有Configuration注解获取配置类中的所有方法判断方法上是否有Bean注解如果有则获取方法的返回值作为实例对象判断配置类上是否有ComponentScan注解如果有则扫描指定包下的所有类并判断类上是否有Component注解如果有则通过反射技术初始化对象使用工厂模式管理初始化对象/实例对象 项目结构 项目代码 pom.xml dependencygroupIdcn.hutool/groupIdartifactIdhutool-all/artifactIdversion5.7.7/version /dependencyScanBean.java package com.spring.bean.scan;import org.springframework.stereotype.Component;/*** author honey* date 2023-08-09 14:28:33*/ Component public class ScanBean { }SpringConfig.java package com.spring.config;import com.spring.bean.UserBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration;/*** author honey* date 2023-08-09 14:26:40*/ Configuration ComponentScan(value {com.spring.bean.scan}) public class SpringConfig {Beanpublic UserBean userBean() {return new UserBean();} }SpringIocAnnotation.java package com.spring.ext;import cn.hutool.core.lang.ClassScanner; import cn.hutool.core.util.StrUtil; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component;import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap;/*** author honey* date 2023-08-09 14:12:21*/ public class SpringIocAnnotation {private final Object config;private final MapString, Object beanMap new ConcurrentHashMap();public SpringIocAnnotation(Object config) {this.config config;init();}/*** 初始化IOC容器*/public void init() {// 判断配置类上是否有Configuration注解Configuration configuration this.config.getClass().getDeclaredAnnotation(Configuration.class);if (configuration null) {return;}// 处理Bean注解Class? clazz config.getClass();Method[] declaredMethods clazz.getDeclaredMethods();for (Method method : declaredMethods) {// 判断方法上是否有Bean注解Bean bean method.getDeclaredAnnotation(Bean.class);if (bean ! null) {try {// 获取beanIdString[] value bean.value();String beanId value.length 0 ? value[0] : method.getName();// 获取方法的返回值Object object method.invoke(config);beanMap.put(beanId, object);} catch (Exception e) {e.printStackTrace();}}}// 处理Component注解ComponentScan componentScan clazz.getDeclaredAnnotation(ComponentScan.class);if (componentScan ! null) {for (String packageName : componentScan.value()) {try {// 扫描指定包下的所有类SetClass? classes ClassScanner.scanPackage(packageName);for (Class? c : classes) {// 判断类上是否有Component注解Annotation component c.getDeclaredAnnotation(Component.class);if (component ! null) {try {// 获取beanIdString beanId StrUtil.lowerFirst(c.getSimpleName());// 通过反射技术初始化对象Object beanObject c.newInstance();beanMap.put(beanId, beanObject);} catch (Exception e) {e.printStackTrace();}}}} catch (Exception e) {e.printStackTrace();}}}}public T T getBean(String name) {return (T) beanMap.get(name);} }SpringTest02.java package com.spring.test;import com.spring.bean.UserBean; import com.spring.bean.scan.ScanBean; import com.spring.config.SpringConfig; import com.spring.ext.SpringIocAnnotation;/*** author honey* date 2023-08-09 14:24:36*/ public class SpringTest02 {public static void main(String[] args) {SpringIocAnnotation springIocAnnotation new SpringIocAnnotation(new SpringConfig());UserBean userBean springIocAnnotation.getBean(userBean);System.out.println(userBean);ScanBean scanBean springIocAnnotation.getBean(scanBean);System.out.println(scanBean);} }运行结果
http://www.zqtcl.cn/news/610058/

相关文章:

  • 傻瓜式网站建设软件保险预约
  • 网站 备案规定自己做简单网站
  • 网站上怎么做支付接口南乐网站建设
  • 咸阳网站建设公司电话做个公司网站大概多少钱
  • 网站如何做关键词排名点子网创意网
  • 浙江建设培训考试网站河源东莞网站建设
  • 网站移动端做pc端的301跳转哪些网站是增值网
  • wordpress新闻站浙江耀华建设集团网站
  • 网站开发代理企业网站推广技巧和方法
  • 俄语网站开发用模板做的网站多少钱
  • 丽水网站建设公司广州网络公司
  • 做基金的网站哪个好针对大学生推广引流
  • 国外对旅游网站的建设互联网推广和互联网营销
  • 海南省建设厅网站首页有什么做设计的兼职网站
  • 网站导航功能苏州市高新区建设局网站
  • jsp网站 值班多语种网站开发
  • 公司网站英文做电商
  • 合肥企业网站建设公司哪家好卖产品怎么做网站
  • 网站建设公司86215中国中小企业网站
  • 做网站 如何 挣钱游戏网站开发协议
  • 网站建设发展wordpress比较慢
  • 收费网站推广动漫制作就业方向
  • 湖北优化网站建设设计公司需要什么资质
  • 个人网站怎么制作wordpress创意小工具
  • 网站管理维护怎么做在线oa
  • vue做企业网站wordpress 不发送邮件
  • 深圳做网站哪家便宜邮政编码html编写
  • 黑龙江营商环境建设局网站门户网站整改报告
  • 是不是做推广都得有网站深圳网站建设新闻
  • 旅游做视频网站关于建设网站的书本