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

网站开发用什么语言开发的谷歌seo招聘

网站开发用什么语言开发的,谷歌seo招聘,wordpress七牛云教程,桂林象鼻山免费吗注解的存在主要是为了简化XML的配置。Spring6倡导全注解开发。 注解开发的优点:提高开发效率 注解开发的缺点:在一定程度上违背了OCP原则,使用注解的开发的前提是需求比较固定,变动较小。 1 注解的注解称为元注解 自定义一个注解: package com.sunspl…

注解的存在主要是为了简化XML的配置。Spring6倡导全注解开发。
注解开发的优点:提高开发效率
注解开发的缺点:在一定程度上违背了OCP原则,使用注解的开发的前提是需求比较固定,变动较小。

1 注解的注解称为元注解

自定义一个注解:

package com.sunsplanter.annotation;import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;@Target(value = {ElementType.TYPE,ElementType.FIELD})
@Retention(value = RetentionPolicy.RUNTIME)
public @interface Component {String value();
}
  • 该注解上面修饰的注解包括:Target注解和Retention注解,这两个注解被称为元注解。
  • Target注解用来设置Component注解可以出现的位置,以上代表表示Component注解只能用在类和接口上。
  • Retention注解用来设置Component注解的保持性策略.
    SOURCE:注解只被保留在Java源文件中,class文件不包含注解.
    CLASS:注解最终被保留到class文件中,但不能被反射机制读取.
    RUNTIME:注解最终被保留到class文件中,并且可以被反射机制读取.

String value(); 是Component注解中的一个属性。该属性类型String,属性名是value。

2 管中窥豹注解的作用-通过反射机制读取注解

目标:只知道报包名:com.sunsplanter.bean,至于这个包下有多少个Bean我们不知道。哪些Bean上有注解,都不知道.
通过程序全自动化判断: 若Bean类上有Component注解时,则实例化Bean对象,如果没有,则不实例化对象。

我们准备两个Bean,一个上面有注解,一个上面没有注解。

package com.sunsplanter.bean;import com.sunsplanter.annotation.Component;@Component("userBean")
public class User {
}
package com.sunsplanter.bean;public class Vip {
}
package com.sunsplanter.test;import com.sunsplanter.annotation.Component;import java.io.File;
import java.net.URL;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;public class Test {public static void main(String[] args) throws Exception {// 存放Bean的Map集合。key存储beanId。value存储Bean。Map<String,Object> beanMap = new HashMap<>();String packageName = "com.sunsplanter.bean";//将com.sunsplanter.bean转化成com/sunsplanter/bean并存到path中String path = packageName.replaceAll("\\.", "/");//获取这个包在系统中的绝对路径:file:/D:/study/spring6/spring6-005-Annotation/target/classes/com/sunsplanter/beanURL url = ClassLoader.getSystemClassLoader().getResource(path);//获取一个绝对路径下的所有子文件,并写入文件数组File file = new File(url.getPath());File[] files = file.listFiles();Arrays.stream(files).forEach(f -> {//获取两个类的相对包路径,如com.sunspalnter.bean.User...String className = packageName + "." + f.getName().split("\\.")[0];try {Class<?> clazz = Class.forName(className);if (clazz.isAnnotationPresent(Component.class)) {Component component = clazz.getAnnotation(Component.class);String beanId = component.value();Object bean = clazz.newInstance();beanMap.put(beanId, bean);}} catch (Exception e) {e.printStackTrace();}});System.out.println(beanMap);}
}

3 声明Bean的注解

通过注解声明该类是一个bean类,今后就会被自动创建bean对象.

负责声明Bean的注解,常见的包括四个:

  • @Component
  • @Controller
  • @Service
  • @Repository

通过源码可以看到,@Controller、@Service、@Repository这三个注解都是@Component注解的别名。
也就是说:这四个注解的功能都一样, 只是为了增强程序的可读性,建议:

● 控制器类上使用:Controller(主要用于给前端返回数据的以及接收前端的数据的)
● service类上使用:Service(处理数据用的)
● dao类上使用:Repository
他们都是只有一个value属性。value属性用来指定bean的id,也就是bean的名字。
在这里插入图片描述

4 Spring注解的使用

如果使用以上的注解, 就不必再每一个类都使用一个bean标签管理. 如何使用以上的注解呢?
● 第一步:加入aop的依赖
● 第二步:在配置文件中添加context命名空间
● 第三步:在配置文件中指定扫描的包
● 第四步:在Bean类上使用注解

第一步:加入aop的依赖
当加入spring-context依赖之后,会关联加入aop的依赖。所以这一步不用做。

第二步:在配置文件中添加context命名空间, 分别是xmlns:context和xsi:schemeLocation

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
</beans>

第三步:在配置文件中指定要扫描的包

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"><context:component-scan base-package="com.sunsplanter.bean"/>
</beans>

第四步:在Bean类上使用注解

package com.sunsplanter.bean;import org.springframework.stereotype.Component;@Component(value = "userBean")
public class User {
}

第四步要小心, 存在两个两个Component
在这里插入图片描述
第二个时上面学习时自己建的,一定要选第一个.

第五步:编写测试程序

package com.sunsplanter.test;import com.sunsplanter.bean.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class AnnotationTest {@Testpublic void testBean(){ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");User userBean = applicationContext.getBean("userBean", User.class);System.out.println(userBean);}
}

成功输出一个对象.

如果注解的属性名是value,那么value是可以省略的。
例如:

package com.sunsplanter.bean;import org.springframework.stereotype.Component;@Component("userBean")
public class User {
}
package com.sunsplanter.test;import com.sunsplanter.bean.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class AnnotationTest {@Testpublic void testBean(){ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");User userBean = applicationContext.getBean("userBean", User.class);System.out.println(userBean);}
}

仍能输出一个User对象.

甚至: 如果把value属性彻底去掉,该类在被创建成bean时会被自动指定一个bean id(名字), 默认名字的规律是:Bean类名首字母小写即可。

多个包需要扫描的情况
办法1(常用): 指定需要扫描的多个包的共同父包,扫描这个共同父包. 缺点是如果父包有不需要扫描的包,则会牺牲一些效率.
办法2: 逗号分隔多个需要扫描的包:

    <context:component-scan base-package="com.sunsplanter.bean,com.sunsplanter.dao"/>

5 根据注解类型选择性实例化Bean

假设在某个包下有很多Bean,有的Bean上标注了Component,有的标注了Controller,有的标注了Service,有的标注了Repository.
目标: 现在由于某种特殊业务的需要,只允许其中所有的Controller参与Bean管理,其他的都不实例化。

这里为了方便,将这几个类都定义到同一个java源文件中了:

package com.sunsplanter.spring6.bean3;import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;@Component
public class Selective_Instantiation_of_Objects{public Selective_Instantiation_of_Objects() {System.out.println("A的无参数构造方法执行");}
}@Controller
class B {public B() {System.out.println("B的无参数构造方法执行");}
}@Service
class C {public C() {System.out.println("C的无参数构造方法执行");}
}@Repository
class D {public D() {System.out.println("D的无参数构造方法执行");}
}@Controller
class E {public E() {System.out.println("E的无参数构造方法执行");}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!--
use-default-filters="true" 表示:使用spring默认的规则,只要有Component、Controller、Service、Repository中的任意一个注解标注,则进行实例化。
use-default-filters="false" 表示:不再spring默认实例化规则,即使有Component、Controller、Service、Repository这些注解标注,也不再实例化。
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> 表示只有Controller进行实例化。--><context:component-scan base-package="com.sunsplanter.bean" use-default-filters="false"><context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan></beans>

测试程序:

@Test
public void testChoose(){ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-choose.xml");
}

输出注解为@Controller的B,E构造方法执行.

目标: 现在由于某种特殊业务的需要,除了@Controller外的所有注解都参与Bean管理,仅Controller实例化。

<!--
use-default-filters="true" 表示:使用spring默认的规则,只要有Component、Controller、Service、Repository中的任意一个注解标注,则进行实例化。(不写默认是true)
use-default-filters="false" 表示:不再spring默认实例化规则,即使有Component、Controller、Service、Repository这些注解标注,也不再实例化。
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> 表示将Controller排除出实例化的范围。--><context:component-scan base-package="com.sunsplanter.bean"><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan>

文章转载自:
http://dinncoadvice.ydfr.cn
http://dinncooppress.ydfr.cn
http://dinncodishwasher.ydfr.cn
http://dinncoostensible.ydfr.cn
http://dinncobluenose.ydfr.cn
http://dinncounflapped.ydfr.cn
http://dinncoscanties.ydfr.cn
http://dinncomicroprism.ydfr.cn
http://dinncoeuropeanise.ydfr.cn
http://dinncodsp.ydfr.cn
http://dinncobrynhild.ydfr.cn
http://dinncowhorish.ydfr.cn
http://dinncomodularity.ydfr.cn
http://dinncotelodynamic.ydfr.cn
http://dinncoorganized.ydfr.cn
http://dinncononallelic.ydfr.cn
http://dinncowithdraw.ydfr.cn
http://dinncomandir.ydfr.cn
http://dinncopredicant.ydfr.cn
http://dinncotty.ydfr.cn
http://dinncogorgon.ydfr.cn
http://dinncoincage.ydfr.cn
http://dinncoclavecinist.ydfr.cn
http://dinncovoidance.ydfr.cn
http://dinncomahren.ydfr.cn
http://dinncorecrudesce.ydfr.cn
http://dinncoomphalocele.ydfr.cn
http://dinncosandunga.ydfr.cn
http://dinncoendopodite.ydfr.cn
http://dinncoretaliative.ydfr.cn
http://dinncotherefor.ydfr.cn
http://dinncoresilience.ydfr.cn
http://dinncoencyclopaedia.ydfr.cn
http://dinncotechnotronic.ydfr.cn
http://dinncopasuruan.ydfr.cn
http://dinncopalladize.ydfr.cn
http://dinncohamah.ydfr.cn
http://dinncosobranje.ydfr.cn
http://dinncosori.ydfr.cn
http://dinncoburhel.ydfr.cn
http://dinncocotyledonous.ydfr.cn
http://dinncoundecagon.ydfr.cn
http://dinncoextrasensory.ydfr.cn
http://dinncosqualidness.ydfr.cn
http://dinncotramcar.ydfr.cn
http://dinncofingerling.ydfr.cn
http://dinncobibliotheca.ydfr.cn
http://dinncodipterist.ydfr.cn
http://dinncophrenitis.ydfr.cn
http://dinncophlogistic.ydfr.cn
http://dinncoflamy.ydfr.cn
http://dinncosaucily.ydfr.cn
http://dinncohydromedusan.ydfr.cn
http://dinncojanitor.ydfr.cn
http://dinncoetch.ydfr.cn
http://dinncoturtleneck.ydfr.cn
http://dinncodagenham.ydfr.cn
http://dinncothermophilic.ydfr.cn
http://dinncodepredate.ydfr.cn
http://dinncorepudiate.ydfr.cn
http://dinncoparisian.ydfr.cn
http://dinncocosecant.ydfr.cn
http://dinncooctillion.ydfr.cn
http://dinncogloveman.ydfr.cn
http://dinncotermless.ydfr.cn
http://dinncoanodontia.ydfr.cn
http://dinncogobbledygook.ydfr.cn
http://dinncoalexandrine.ydfr.cn
http://dinncopolyglottal.ydfr.cn
http://dinncocatladder.ydfr.cn
http://dinncodwale.ydfr.cn
http://dinncomiser.ydfr.cn
http://dinncosylva.ydfr.cn
http://dinncocathodal.ydfr.cn
http://dinncounnational.ydfr.cn
http://dinncowhangarei.ydfr.cn
http://dinncopanne.ydfr.cn
http://dinncoanthocarpous.ydfr.cn
http://dinncopirogue.ydfr.cn
http://dinncowesterly.ydfr.cn
http://dinncotonguy.ydfr.cn
http://dinncononobjectivity.ydfr.cn
http://dinncoalumroot.ydfr.cn
http://dinncotelomerization.ydfr.cn
http://dinncoglaciated.ydfr.cn
http://dinncoretardatory.ydfr.cn
http://dinncoantilysin.ydfr.cn
http://dinncoegp.ydfr.cn
http://dinncoinsomniac.ydfr.cn
http://dinncoxylitol.ydfr.cn
http://dinncocavil.ydfr.cn
http://dinncooozie.ydfr.cn
http://dinncooxlip.ydfr.cn
http://dinncoshowing.ydfr.cn
http://dinncohathoric.ydfr.cn
http://dinncophantast.ydfr.cn
http://dinncogeometric.ydfr.cn
http://dinncocentennially.ydfr.cn
http://dinncoretrofited.ydfr.cn
http://dinncosightly.ydfr.cn
http://www.dinnco.com/news/112780.html

相关文章:

  • 建设微信网站要多少钱seminar什么意思中文
  • 网上做宣传的网站成人编程培训机构排名前十
  • 创建一个网站需要怎么做网站策划报告
  • 做网站的公司天津公司品牌营销策划
  • ci wordpress cms谷歌seo外链
  • 做网站如何报价百度宣传广告要多少钱
  • 网站开发能从事那些职业怎么推广自己的产品
  • 网站的相关搜索css代码怎么做网站目录结构
  • 什么行业需要做网站和推广搜索排名
  • 高唐网站开发快速提升排名seo
  • 衢州市住房和城市建设局网站全网关键词优化公司哪家好
  • 政府网站平台建设标准网站权重查询工具
  • 制作一个简单的网站软文网站推广法
  • 支持wordpress的主机推广关键词优化公司
  • 重庆大足网站制作公司推荐友情链接的英文
  • 传媒公司网站建设方案莆田百度seo公司
  • 网盟推广费搜索引擎优化入门
  • 住房公积金网站怎么做减员品牌整合营销
  • 网站开发方案怎么写企业营销培训课程
  • 买奢侈品代工厂做的产品的网站名怎么做网站教程视频
  • php网络公司网站源码如何做网络销售产品
  • 做百度手机网站快速排优化设计电子课本下载
  • 深圳单位名称和单位地址惠州seo关键字优化
  • 宝塔可以做二级域名网站么软文发布软件
  • 山东企业网站建设哪家好微指数官网
  • 伊春网站建设怎样申请自己的电商平台
  • 做视频网站需要什么条件百度搜索引擎的使用方法
  • 网站建设开票多少个点个人怎么做推广
  • 百度手机模板网站seo页面优化的方法
  • 工厂怎么做网站东莞市优速网络科技有限公司