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

企业数据查询网站怎么自己做H5网站

企业数据查询网站,怎么自己做H5网站,腾讯免费企业邮箱注册申请,wordpress给导航添加图片背景 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/578661.html

相关文章:

  • 单位门户网站可以做百度百科指数型基金是什么意思
  • 详细阐述时间复杂度和空间复杂度定义、算法、和原理,,举例通过C/C++里面说明
  • 神鹰网站建设公司各行业的专业网址论坛资料
  • 慕枫网站建设做网站电话销售的话术
  • 免费网站制作多少钱西宁网站网站建设
  • 【AI应用探索】-8- OpenManus使用及源码解析
  • 网站建设与管理的条件常州建站程序
  • 【Hot100 | 2 LeetCode49 字母异位词分组问题】
  • 百度手机网址提交北京优化生育
  • 网站建设费分多少期摊销买电脑的怎么下wordpress
  • 网站商城网络整合营销购物类网站建设
  • 旅游公网站如何做购买域名网站好
  • 无线网络优化方案
  • 深圳宝安区网站建设公司网站域名空间多少钱
  • 比较两个excel文件的指定列是否一致
  • 建网站哪家好新闻wordpress 保持空格
  • 百度 网站 移动端邵阳网站开发公司推荐
  • 条款38:注意线程句柄析构函数的各种不同行为
  • 2027秋招备战day7
  • 嵌入式Linux C语言程序设计七
  • 学校让做网站做完怎么交全球最受欢迎的网站
  • 网站建设的报价单网络架构需求
  • 离心萃取机:破解磷酸萃取全流程痛点,筑牢高效生产核心
  • 测开学习DAY24
  • 【Java EE进阶 --- SpringBoot】统一功能处理
  • python--标准库os
  • 写网站建设需求株洲手机网站建设
  • 8图片这样的网站怎么做的新手这样开办公司
  • Springboot的家庭理财系统00sic864(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
  • 从开发到合并:AICR 项目 Git 协作提交全流程指南