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

西安网站建设哪家好企业营销策划方案范文

西安网站建设哪家好,企业营销策划方案范文,wordpress弹幕视频主题,广州越秀区怎么样一、介绍从 Java 5 开始,Java 增加了对注解(Annotation)的支持,它是代码中的一种特殊标记,可以在编译、类加载和运行时被读取,执行相应的处理。开发人员可以通过注解在不改变原有代码和逻辑的情况下&#x…

一、介绍

从 Java 5 开始,Java 增加了对注解(Annotation)的支持,它是代码中的一种特殊标记,可以在编译、类加载和运行时被读取,执行相应的处理。开发人员可以通过注解在不改变原有代码和逻辑的情况下,在源代码中嵌入补充信息。
Spring 从 2.5 版本开始提供了对注解技术的全面支持,我们可以使用注解来实现自动装配,简化 Spring 的 XML 配置。
Spring 通过注解实现自动装配的步骤如下:
引入依赖
开启组件扫描
使用注解定义 Bean
依赖注入

二、子模块spring6-ioc-annotation

**①搭建模块**搭建方式如:spring6-ioc-xml**②引入配置文件**引入spring-ioc-xml模块日志log4j2.xml**③添加依赖**```xml
<dependencies><!--spring context依赖--><!--当你引入Spring Context依赖之后,表示将Spring的基础依赖引入了--><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>6.0.3</version></dependency><!--junit5测试--><dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-api</artifactId></dependency><!--log4j2的依赖--><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-core</artifactId><version>2.19.0</version></dependency><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-slf4j2-impl</artifactId><version>2.19.0</version></dependency>
</dependencies>
```

三、开启组件扫描

Spring 默认不使用注解装配 Bean,因此我们需要在 Spring 的 XML 配置中,通过 context:component-scan 元素开启 Spring Beans的自动扫描功能。开启此功能后,Spring 会自动从扫描指定的包(base-package 属性设置)及其子包下的所有类,如果类上使用了 @Component 注解,就将该类装配到容器中。
<?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/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd"><!--开启组件扫描功能--><context:component-scan base-package="com.wsy"></context:component-scan>
</beans
**情况一:最基本的扫描方式**```xml
<context:component-scan base-package="com.wsy">
</context:component-scan>
```**情况二:指定要排除的组件**```xml
<context:component-scan base-package="com.atguigu.spring6"><!-- context:exclude-filter标签:指定排除规则 --><!-- type:设置排除或包含的依据type="annotation",根据注解排除,expression中设置要排除的注解的全类名type="assignable",根据类型排除,expression中设置要排除的类型的全类名--><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/><!--<context:exclude-filter type="assignable" expression="com.wsy.controller.UserController"/>-->
</context:component-scan>
```**情况三:仅扫描指定组件**```xml
<context:component-scan base-package="com.atguigu" use-default-filters="false"><!-- context:include-filter标签:指定在原有扫描规则的基础上追加的规则 --><!-- use-default-filters属性:取值false表示关闭默认扫描规则 --><!-- 此时必须设置use-default-filters="false",因为默认规则即扫描指定包下所有类 --><!-- type:设置排除或包含的依据type="annotation",根据注解排除,expression中设置要排除的注解的全类名type="assignable",根据类型排除,expression中设置要排除的类型的全类名--><context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/><!--<context:include-filter type="assignable" expression="com.wsy.controller.UserController"/>-->
</context:component-scan>
```

四、使用注解定义 Bean

Spring 提供了以下多个注解,这些注解可以直接标注在 Java 类上,将它们定义成 Spring Bean。

注解

说明

@Component

该注解用于描述 Spring 中的 Bean,它是一个泛化的概念,仅仅表示容器中的一个组件(Bean),并且可以作用在应用的任何层次,例如 Service 层、Dao 层等。 使用时只需将该注解标注在相应类上即可。

@Repository

该注解用于将数据访问层(Dao 层)的类标识为 Spring 中的 Bean,其功能与 @Component 相同。

@Service

该注解通常作用在业务层(Service 层),用于将业务层的类标识为 Spring 中的 Bean,其功能与 @Component 相同。

@Controller

该注解通常作用在控制层(如SpringMVC 的 Controller),用于将控制层的类标识为 Spring 中的 Bean,其功能与 @Component 相同。

4.1实验一:@Autowired注入

①场景一:属性注入

创建UserDao接口


​
publicinterfaceUserDao {
​publicvoidprint();
}

创建UserDaoImpl实现

importorg.springframework.stereotype.Repository;
​
@Repository
publicclassUserDaoImplimplementsUserDao {
​@Overridepublicvoidprint() {System.out.println("Dao层执行结束");}
}

创建UserService接口

packagecom.atguigu.spring6.service;
​
publicinterfaceUserService {
​publicvoidout();
}

创建UserServiceImpl实现类

importorg.springframework.beans.factory.annotation.Autowired;
importorg.springframework.stereotype.Service;
​
@Service
publicclassUserServiceImplimplementsUserService {
​@AutowiredprivateUserDaouserDao;
​@Overridepublicvoidout() {userDao.print();System.out.println("Service层执行结束");}
}

创建UserController类


importorg.springframework.beans.factory.annotation.Autowired;
importorg.springframework.stereotype.Controller;
​
@Controller
publicclassUserController {
​@AutowiredprivateUserServiceuserService;
​publicvoidout() {userService.out();System.out.println("Controller层执行结束。");}
​
}

测试一

    @Testpublic void testAutowired(){ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");UserController userController = ac.getBean("userController",UserController.class);userController.addController();}

测试结果:

②场景二:set注入
 @Autowiredprivate UserService userService;

改造

 private UserService userService;@Autowiredpublic void setUserService(UserService userService) {this.userService = userService;}
③场景三:构造方法注入
 private UserService userService;@Autowiredpublic UserController(UserService userService) {this.userService = userService;}
④场景四:形参上注入
 public UserController(@Autowired UserService userService) {this.userService = userService;}
⑤场景五:只有一个构造函数,无注解
    private UserDao userDao;public UserServiceImpl(UserDao userDao) {this.userDao = userDao;}
⑥场景六:@Autowired注解和@Qualifier注解联合
多个实现类,使用@qualifier进行注入
@Autowired
@Qualifier("userDaoImpl") // 指定bean的名字
private UserDao userDao;

4.2实验二:@Resource注入

@Resource注解也可以完成属性注入。那它和@Autowired注解有什么区别?

  • @Resource注解是JDK扩展包中的,也就是说属于JDK的一部分。所以该注解是标准注解,更加具有通用性。(JSR-250标准中制定的注解类型。JSR是Java规范提案。)

  • @Autowired注解是Spring框架自己的。

  • @Resource注解默认根据名称装配byName,未指定name时,使用属性名作为name。通过name找不到的话会自动启动通过类型byType装配。

  • @Autowired注解默认根据类型装配byType,如果想根据名称装配,需要配合@Qualifier注解一起用。

  • @Resource注解用在属性上、setter方法上。

  • @Autowired注解用在属性上、setter方法上、构造方法上、构造方法参数上。

@Resource注解属于JDK扩展包,所以不在JDK当中,需要额外引入以下依赖:【如果是JDK8的话不需要额外引入依赖。高于JDK11或低于JDK8需要引入以下依赖。

<dependency><groupId>jakarta.annotation</groupId><artifactId>jakarta.annotation-api</artifactId><version>2.1.1</version>
</dependency>
@Resource注解:默认byName注入,没有指定name时把属性名当做name,根据name找不到时,才会byType注入。byType注入时,某种类型的Bean只能有一个


文章转载自:
http://dinncoshameful.ydfr.cn
http://dinncoazeotrope.ydfr.cn
http://dinncoorcein.ydfr.cn
http://dinncorecall.ydfr.cn
http://dinncoeuglena.ydfr.cn
http://dinncothrenetic.ydfr.cn
http://dinncopolygamous.ydfr.cn
http://dinncopresumably.ydfr.cn
http://dinncochauffeur.ydfr.cn
http://dinncocounterpoise.ydfr.cn
http://dinncopluralize.ydfr.cn
http://dinncosomatostatin.ydfr.cn
http://dinncoclosed.ydfr.cn
http://dinncobeefcakery.ydfr.cn
http://dinncosystematical.ydfr.cn
http://dinncocrooked.ydfr.cn
http://dinncofistula.ydfr.cn
http://dinncobuxom.ydfr.cn
http://dinncoregion.ydfr.cn
http://dinncooveruse.ydfr.cn
http://dinncogan.ydfr.cn
http://dinncoboskage.ydfr.cn
http://dinncosolarize.ydfr.cn
http://dinncolucre.ydfr.cn
http://dinncoindependent.ydfr.cn
http://dinncoparliament.ydfr.cn
http://dinncoimmovability.ydfr.cn
http://dinncocubane.ydfr.cn
http://dinncostrainer.ydfr.cn
http://dinnconondescript.ydfr.cn
http://dinncopeashooter.ydfr.cn
http://dinncolayabout.ydfr.cn
http://dinncoachromate.ydfr.cn
http://dinncosofty.ydfr.cn
http://dinncodevildom.ydfr.cn
http://dinncoguideline.ydfr.cn
http://dinncoantrum.ydfr.cn
http://dinncogemot.ydfr.cn
http://dinncodrone.ydfr.cn
http://dinncohorsetail.ydfr.cn
http://dinncoaraeostyle.ydfr.cn
http://dinncoinveigle.ydfr.cn
http://dinncoafrikanerdom.ydfr.cn
http://dinncocolleging.ydfr.cn
http://dinncohexachlorocyclohexane.ydfr.cn
http://dinncorecherche.ydfr.cn
http://dinncodiagonally.ydfr.cn
http://dinnconetting.ydfr.cn
http://dinncopallet.ydfr.cn
http://dinncodefrayment.ydfr.cn
http://dinncofledgy.ydfr.cn
http://dinncocambrian.ydfr.cn
http://dinncocompany.ydfr.cn
http://dinncolekvar.ydfr.cn
http://dinncofabianist.ydfr.cn
http://dinncocism.ydfr.cn
http://dinncohorntail.ydfr.cn
http://dinncoyyz.ydfr.cn
http://dinncogennemic.ydfr.cn
http://dinncoosbert.ydfr.cn
http://dinncobraincase.ydfr.cn
http://dinncophonomotor.ydfr.cn
http://dinncohaleb.ydfr.cn
http://dinncoautotrophy.ydfr.cn
http://dinncogerminability.ydfr.cn
http://dinncotorpex.ydfr.cn
http://dinncogestalt.ydfr.cn
http://dinncopna.ydfr.cn
http://dinnconeuron.ydfr.cn
http://dinncocaprifoliaceous.ydfr.cn
http://dinncochanceless.ydfr.cn
http://dinncoforespeak.ydfr.cn
http://dinncomaintainability.ydfr.cn
http://dinncoknowledge.ydfr.cn
http://dinnconeoglaciation.ydfr.cn
http://dinncocockchafer.ydfr.cn
http://dinncosteelyard.ydfr.cn
http://dinncoichnographic.ydfr.cn
http://dinncoseparation.ydfr.cn
http://dinncounguinous.ydfr.cn
http://dinncodrophead.ydfr.cn
http://dinncobroadish.ydfr.cn
http://dinncosagacity.ydfr.cn
http://dinncothessaly.ydfr.cn
http://dinncotrihydrate.ydfr.cn
http://dinncofloatation.ydfr.cn
http://dinncoastucious.ydfr.cn
http://dinncocrown.ydfr.cn
http://dinncosophistical.ydfr.cn
http://dinncoadobe.ydfr.cn
http://dinncowrack.ydfr.cn
http://dinncosyncopate.ydfr.cn
http://dinncopforzheim.ydfr.cn
http://dinncoveneration.ydfr.cn
http://dinncoinexistent.ydfr.cn
http://dinncoshapka.ydfr.cn
http://dinncocoypu.ydfr.cn
http://dinncohoyt.ydfr.cn
http://dinncomyelinated.ydfr.cn
http://dinncovisualization.ydfr.cn
http://www.dinnco.com/news/98085.html

相关文章:

  • 请人做网站后台密码北海seo快速排名
  • 网站建设及制作b站是哪个网站
  • 做网站的合同范文seo优化几个关键词
  • 塘下建设银行网站小程序推广50个方法
  • 为什么有网网站打不开怎么回事网站怎么建设
  • 乌尔禾区做网站哪里好广告公司
  • sql与网站开发产品推广文章
  • 易企秀怎么做网站链接网络seo软件
  • 软件外包平台忠实服务2020 惠州seo服务
  • 上海外贸网站建设公司长沙网站设计拓谋网络
  • 可以做分析图的地图网站营销软文800字范文
  • 苏州企业网站建设电销外包团队在哪找
  • 南宁建站青岛网站建设运营推广
  • b2c网站维护整合营销理论主要是指
  • iis 创建网站万维网域名注册查询
  • 网站建设毕业论文参考文献互联网营销外包公司
  • 公司网站制作视频湖南专业seo优化
  • 铜陵做网站的公司公司网络营销推广软件
  • 建设银行企业信息门户网站seo的研究对象
  • 建设电影网站的目的企业网站推广外包
  • 做网站的教学视频谷歌浏览器网页版
  • python3的网站开发学生网页设计模板
  • 山西推广型网站开发实时积分榜
  • 315网站专题怎么做沈阳网络营销推广的公司
  • 网站备案ip更换一份完整的活动策划方案
  • 百度网站 收录游戏推广员平台
  • 学校网站建设开发方案书如何做好企业推广
  • 用asp.net做后台网站网络服务商电话
  • 下载的字体如何安装到wordpress深圳网站建设推广优化公司
  • 做黄金的经常看什么网站网站怎么制作免费的