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

上海网站建设推营销型网站的类型

上海网站建设推,营销型网站的类型,局域网网站,建网站发信息做推广Spring针对Bean管理中创建对象提供的注解有哪些?Component:普通Service:业务逻辑层Controller:controller层Repository:dao层用注解的方式是为什么?简化xml方式开发,只需要注解就可以完成在配置…

Spring针对Bean管理中创建对象提供的注解有哪些?

@Component:普通

@Service:业务逻辑层

@Controller:controller层

@Repository:dao层

用注解的方式是为什么?

简化xml方式开发,只需要注解就可以完成在配置文件中的配置

如何实现注解开发?

创建对象

组件扫描

package com.atguigu.spring5.ComponentScan;import org.springframework.stereotype.Component;/*** @BelongsProject: 02-Spring* @BelongsPackage: com.atguigu.spring5* @Author: dengLiMei* @CreateTime: 2023-02-04  16:56* @Description: TODO* @Version: 1.0*/
//value可以不写,如果不写默认是类名的首字母小写
@Component(value = "user")
public class User {public void add() {System.out.println("aaaa");}
}
package com.atguigu.spring5.ComponentScan;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;/*** @BelongsProject: 02-Spring* @BelongsPackage: com.atguigu.spring5.ComponentScan* @Author: dengLiMei* @CreateTime: 2023-02-10  15:12* @Description: TODO* @Version: 1.0*/
public class Main {public static void main(String[] args) {ApplicationContext content= new ClassPathXmlApplicationContext("beans.xml");User user = content.getBean("user", User.class);user.add();}
}
<?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:p="http://www.springframework.org/schema/p"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.atguigu.spring5"></context:component-scan><!--    use-default-filters=“false”:表示现在不使用默认filter,自己配置filtercontext:include-filter,设置扫描哪些内容--><!--    表示:  只扫描注解带Controller的类--><context:component-scan base-package="com.atguigu.spring5" use-default-filters="false"><context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan><!--    下面配置扫描包所有内容context:include-filter,设置扫描哪些内容--><!--    表示:  除了Controller其余类都扫描--><context:component-scan base-package="com.atguigu.spring5"><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>-filtertype="" expression=""/></context:component-scan>
</beans>

属性注入

@Autowired:根据类型注入

@Qualifier:根据名称进行注入,和Autowired

@Resource:可以根据类型或名称注入

@Value:普通属性注入

javax:java扩展包


完全注解开发

Configuration:作为配置类,替代xml配置文件

package com.atguigu.spring5.SpringConfiguration;import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;@Configuration
@ComponentScan(basePackages = {"com.atguigu.spring5"})
public class SpringConfigure {}
package com.atguigu.spring5.ScopeTest;import org.springframework.stereotype.Component;/*** @BelongsProject: 02-Spring* @BelongsPackage: com.atguigu.spring5.Book* @Author: dengLiMei* @CreateTime: 2023-02-08  19:28* @Description: TODO* @Version: 1.0*/
@Component
public class Book {private String bname;private String bauthor;public void setBname(String bname) {this.bname = bname;}public void setBauthor(String bauthor) {this.bauthor = bauthor;}public static void main(String[] args) {Book book = new Book();book.setBname("abc");}public void testDemo() {System.out.println(bname + "---" + "aaa");}}
package com.atguigu.spring5.SpringConfiguration;import com.atguigu.spring5.ScopeTest.Book;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;/*** @BelongsProject: 02-Spring* @BelongsPackage: com.atguigu.spring5.SpringConfiguration* @Author: dengLiMei* @CreateTime: 2023-02-11  09:38* @Description: TODO* @Version: 1.0*/
public class Main {public static void main(String[] args) {
//        加载配置类ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfigure.class);
//        创建实例Book book = context.getBean("book", Book.class);
//        调用方法book.testDemo();}
}

输出结果:


Spring系列文章:

Spring——是什么?作用?内容?用到的设计模式?

Spring——Bean管理-xml方式进行属性注入

Spring——Bean管理-注解方式进行属性注入

Spring——什么是IOC?

Spring——AOP是什么?如何使用?

Spring——什么是事务?传播行为?事务隔离级别有哪些?

Spring——整合junit4、junit5使用方法

如果有想要交流的内容欢迎在评论区进行留言,如果这篇文档受到了您的喜欢那就留下你点赞+收藏脚印支持一下博主~

http://www.rdtb.cn/news/17087.html

相关文章:

  • 互联网公司网站建设ppt模板下载百度seo查询系统
  • 网站设计背景怎么写网站建设哪家好
  • wordpress 网站地图网络推广费用一般多少
  • 360云盘做服务器建设网站自己的网站怎么样推广优化
  • 做门户网站需要学什么软件口碑营销的优缺点
  • 上海做网站价格制作网站的最大公司
  • 哪个在家做兼职网站比较好网络营销方式都有哪些
  • 国外网站推荐连云港seo优化公司
  • 广州十度网络网站开发最好最新热点新闻事件素材
  • 无忧网站南宁网络推广有几家
  • 深圳 网站 传播中央下令全国各地核酸检测
  • 网站里网格怎么做seo关键词外包公司
  • 开题报告 网站建设营销策略包括哪些方面
  • 网站做相片免费网站推广软件下载
  • 佘山做网站公司软文案例400字
  • 企业网站开发论文值得收藏的五个搜索引擎
  • 老李网站建设网络搜索引擎
  • wordpress wp rewrite网站seo专员
  • 做网站能拿多少钱信息流优化师是什么
  • 做响应式网站的意义百度网盘怎么用
  • 如何建设公司门户网站新网站快速排名软件
  • 华人要素互联网平台有限公司seo排名点击 seo查询
  • 做招聘网站需要哪些手续厦门百度seo公司
  • 马鞍山网站建设赛事资讯赛马资料
  • 电商网站开发费用pr的选择应该优先选择的链接为
  • 阿里云机器怎么做网站长沙企业关键词优化哪家好
  • 常州做网站的企业淄博网络推广公司哪家好
  • 网站建设管理概述自建站怎么推广
  • 深圳做网站个人百度网页版电脑版入口
  • 网站自然排名往后掉seo推广服务