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

北京高端网站定制公司网站建设维护学什么

北京高端网站定制公司,网站建设维护学什么,东莞自媒体运营推广公司,南通网站维护背景 spring框架的一个核心功能是IOC,就是将Bean初始化加载到容器中,Bean是如何加载到容器的,可以使用spring注解方式或者spring XML配置方式。 spring注解方式直接对项目中的类进行注解,减少了配置文件内容,更加便于…

背景

spring框架的一个核心功能是IOC,就是将Bean初始化加载到容器中,Bean是如何加载到容器的,可以使用spring注解方式或者spring XML配置方式。

spring注解方式直接对项目中的类进行注解,减少了配置文件内容,更加便于管理,使用注解可以大大提高了开发效率!

注解

@Component表示一个带注释的类是一个“组件”,成为Spring管理的Bean。当使用基于注解的配置和类路径扫描时,这些类被视为自动检测的候选对象。同时@Component还是一个元注解。

@Controller组合注解(组合了@Component注解),应用在MVC层(控制层),DispatcherServlet会自动扫描注解了此注解的类,然后将web请求映射到注解了@RequestMapping的方法上。

@Service组合注解(组合了@Component注解),应用在service层(业务逻辑层)。

@Reponsitory组合注解(组合了@Component注解),应用在dao层(数据访问层)。

测试代码:

被@Component注解的类UserDaoImpl:

package com.annotation.dao.impl;import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;import com.annotation.dao.interfaces.InterfaceUserDao;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;/*** @copyright 2003-2025* @author    qiao wei* @date      2025-03-24* @version   1.0* @brief     注解方式标注Bean,命名为“userDaoDao”,如果没有命名,则默认为类名首字母小写,即“userDaoImpl”。* @history   name*            date*            brief*/
@Component(value = "userDao01")
@Scope(value = "prototype")
@Lazy(value = false)
public class UserDaoImpl implements InterfaceUserDao {public UserDaoImpl() {System.out.println("类的构造方法");}@Overridepublic void print() {System.out.println("UserDaoImpl类实例,继承接口InterfaceUserDao");}@PostConstructpublic void init() {System.out.println("UserDaoImpl类init方法,在构造方法之后调用");}@PreDestroypublic void destroy() {System.out.println("UserDaoImpl类destroy方法,在Bean销毁之前调用");}
}

注解类实现的接口InterfaceUserDao :

package com.annotation.dao.interfaces;/*** @copyright 2003-2024* @author    qiao wei* @date      2024-12-22* @version   1.0* @brief     * @history   name*            date*            brief*/
public interface InterfaceUserDao {void print();
}

测试验证:

package com.annotation.dao.impl;import org.junit.jupiter.api.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;import com.annotation.dao.interfaces.InterfaceUserDao;/*** @copyright 2003-2025* @author    qiao wei* @date      2025-04-12* @version   1.0* @brief     * @history   name*            date*            brief*/
class UserDaoImplTest {@Testpublic void test01() {ClassPathXmlApplicationContext context =new ClassPathXmlApplicationContext("./xml/annotation/applicationContext.xml");InterfaceUserDao userDao = context.getBean("userDao01", InterfaceUserDao.class);userDao.print();context.close();}
}

读取的配置文件:

<?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"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-4.0.xsd"><!--  进行注解扫描。扫描制定的包及其子包。  --><context:component-scan base-package="com.annotation" />
</beans>

运行结果:

http://www.dtcms.com/a/616041.html

相关文章:

  • 如何做网站拉动条网站策划包括哪些内容
  • 整形网站 源码百度seo怎么做
  • 虚拟机做局域网网站服务器商务定制网站
  • 什么是网页站点什么软件可以自主建设网站
  • 网站建设费计入那个科目中华室内设计师网
  • 南阳做网站的公司网站规划与建设的流程与方法 高中信息技术
  • wordpress你访问的网站不存在网页产品设计
  • C语言编译程序属于应用软件 | 探讨编译器在软件开发中的重要性
  • 白酒网站源码学会网站建设方案
  • 360网站兼容模式营销策划思路及方案
  • 外贸公司网站有哪些为什么网站后台怎么换图片
  • 首饰盒东莞网站建设网络推广方案p
  • 南通专业网站制作公司crm系统是什么意思啊
  • 联通网站备案系统拼多多网店能挣钱吗
  • 锟鹏建设招聘网站云主机重装系统后网站重新部署吗
  • 阿里云服务器上的网站怎么做修改小程序定制语言
  • 网站建设的工资安徽康东建设工程有限公司网站
  • 免费模板网站word网站开发对cpu要求高吗
  • 食品网站设计工商联网站建设方案
  • java学习连续打卡30天(1)
  • 手机有软件做ppt下载网站有哪些内容吗营销qq手机版
  • 网站开发需要注意的石家庄网页网站制作
  • 网站流程图设计网站要设置哪些栏目
  • 微信制作网站设计做网站要会什么
  • 延长中路上海网站建设江西建设工程信息网站
  • 网站右下角广告代码基于php技术的小型企业网站开发
  • 佛山建网站价格网站显示已备案
  • 网站建设业务渠道小程序平台
  • 中国建设网站上报名塔吊司索工企业门户网站建设方案怎么写
  • 北京哪里可以做网站企业培训 电子商务网站建设 图片