莆田市秀屿区建设局网站取消wordpress的最近文档

张小明 2026/1/2 12:13:32
莆田市秀屿区建设局网站,取消wordpress的最近文档,海南省交通工程建设局网站,域名与网站区别目录 1.快速入门 2.常用注解 bean管理类常用的4个注解#xff08;作用相同#xff0c;推荐使用在不同分层上#xff09; ​ 依赖注入常用的注解 对象生命周期#xff08;作用范围#xff09;注解 3.纯注解模式 1.快速入门 导入依赖#xff1a; dependencies作用相同推荐使用在不同分层上 ​依赖注入常用的注解对象生命周期作用范围注解3.纯注解模式1.快速入门导入依赖dependencies dependency groupIdorg.springframework/groupId artifactIdspring-context/artifactId version5.0.2.RELEASE/version /dependency dependency groupIdcommons-logging/groupId artifactIdcommons-logging/artifactId version1.2/version /dependency dependency groupIdjunit/groupId artifactIdjunit/artifactId version4.10/version scopetest/scope /dependency /dependencies在配置文件中开启注解扫描?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beans xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:contexthttp://www.springframework.org/schema/context xsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd !-- 开启注解扫描 -- context:component-scan base-packagecom.qcby/ /beans创建接口和实现类package com.qcby.service; public interface UserService { public void hello(); } package com.qcby.service.Impl; import com.qcby.service.UserService; import org.springframework.stereotype.Component; /** * Component 作用是把当前类使用IOC容器进行管理如果没有指定名称默认使用当前类名userServiceImpl */ Component(value userService) public class UserServiceImpl implements UserService { Override public void hello() { System.out.println(hello IOC注解........); } }测试代码import com.qcby.service.UserService; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Demo { Test public void test1() { ApplicationContext context new ClassPathXmlApplicationContext(applicationContext.xml); UserService userService (UserService) context.getBean(userService); userService.hello(); } }运行结果我们在实现类上面加了Component注解它的作用是把当前类使用IOC容器进行管理value指定Bean的名称如果没有指定名称默认使用当前类名userServiceImpl2.常用注解bean管理类常用的4个注解作用相同推荐使用在不同分层上 ​Component普通的类Controller表现层Service业务层Repository持久层依赖注入常用的注解Value用于注入普通类型Stringintdouble等类型 ​Autowired默认按类型进行自动装配引用类型 ​Qualifier和Autowired一起使用强制使用名称注入 ​Resource JavaEE提供的注解也被支持。使用name属性按名称注入对象生命周期作用范围注解Scope生命周期注解取值singleton默认值单实例和prototype多例初始化方法和销毁方法注解PostConstruct相当于init-methodPreDestroy相当于destroy-method3.纯注解模式纯注解的方式是微服务架构开发的主要方式所以也是非常的重要。纯注解的目 的是替换掉所有的配置文件。但是需要编写配置类。配置类package com.qcby.config; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; /** * spring的配置类替换掉applicationContext.xml */ //声明这个类是配置类 Configuration //扫描指定的包结构 ComponentScan(valuecom.qcby) public class SpringConfig { }实体类package com.qcby.entity; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; Component public class Order { Value(北京) private String address; Override public String toString() { return Order [address address ]; } }测试方法import com.qcby.config.SpringConfig; import com.qcby.entity.Order; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; public class Demo { /** * 需要加载配置类 */ Test public void test() { ApplicationContext context new AnnotationConfigApplicationContext(SpringConfig.class); //获取对象 Order order (Order) context.getBean(order); System.out.println(order); } }Configuration声明是配置类ComponentScan扫描具体包结构的Import注解Spring的配置文件可以分成多个配置的编写多个配置类。用于导入其他配置类Bean注解只能写在方法上表明使用此方法创建一个对象对象创建完成保 存到IOC容器中创建SpringConfig2在SpringConfig2当中配置德鲁伊连接池package com.qcby.config; import com.alibaba.druid.pool.DruidDataSource; import org.springframework.context.annotation.Bean; import javax.sql.DataSource; public class SpringConfig2 { Bean(name dataSource) public DataSource createDataSource() { DruidDataSource dataSource new DruidDataSource(); dataSource.setDriverClassName(com.mysql.jdbc.Driver); dataSource.setUrl(jdbc:mysql://localhost:3306/spring_db); dataSource.setUsername(root); dataSource.setPassword(root); return dataSource; } }在原来的配置类当中导入配置package com.qcby.config; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; /** * spring的配置类替换掉applicationContext.xml */ //声明这个类是配置类 Configuration //扫描指定的包结构 ComponentScan(valuecom.qcby) Import(value{SpringConfig2.class}) public class SpringConfig { }创建实体类package com.qcby.entity; public class Account { private int id; private String name; private Double money; public Account(String name, int id, Double money) { this.name name; this.id id; this.money money; } public Account() { } public int getId() { return id; } public void setId(int id) { this.id id; } public String getName() { return name; } public void setName(String name) { this.name name; } public Double getMoney() { return money; } public void setMoney(Double money) { this.money money; } Override public String toString() { return Account [id id , name name , money money ]; } }持久层:package com.qcby.dao; import com.qcby.entity.Account; import java.util.List; public interface AccountDao { ListAccount findAll(); } package com.qcby.dao.Impl; import com.qcby.dao.AccountDao; import com.qcby.entity.Account; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import javax.sql.DataSource; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; Repository public class AccountDaoImpl implements AccountDao { Autowired private DataSource dataSource; Override public ListAccount findAll() { ListAccount list new ArrayList(); Connection conn null; PreparedStatement ps null; ResultSet rs null; try{ //获取连接 conndataSource.getConnection(); //编写sql String sqlselect * from account; //预编译 psconn.prepareStatement(sql); //查询 rs ps.executeQuery(); while(rs.next()){ Account accountnew Account(); account.setId(rs.getInt(id)); account.setName(rs.getString(name)); account.setMoney(rs.getDouble(money)); list.add(account); } } catch (Exception e) { throw new RuntimeException(e); }finally { try { if (rs ! null) rs.close(); if (ps ! null) ps.close(); if (conn ! null) conn.close(); } catch (Exception e) { e.printStackTrace(); } } return list; } }业务层package com.qcby.service.Impl; import com.qcby.dao.AccountDao; import com.qcby.entity.Account; import com.qcby.service.AccountService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; Service public class AccountServiceImpl implements AccountService { Autowired private AccountDao accountDao; Override public ListAccount findAll() { return accountDao.findAll(); } } package com.qcby.service; import com.qcby.entity.Account; import java.util.List; public interface AccountService { ListAccount findAll(); }测试代码Test public void test2() { ApplicationContext context new AnnotationConfigApplicationContext(SpringConfig.class); AccountService accountService context.getBean(AccountService.class); ListAccount listaccountService.findAll(); for(Account account:list){ System.out.println(account); } }结果可见我们在配置类2当中的配置也生效了
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

兰州手机网站制作公司哪家好医院网站制作好吗

嵌入式系统开发:瘦客户端与家庭自动化应用 1. 瘦客户端应用概述 瘦客户端终端是一种轻量级的计算设备,它依赖于服务器来提供大部分的计算和存储功能。通过使用WTC OS设计模板,我们可以轻松地生成一个OS运行时映像。具体步骤如下: - 首先,对瘦客户端终端进行简要概述,了…

张小明 2025/12/31 22:41:00 网站建设

网站代码 如何做层级关系dedecms 网站迁移

✍✍计算机毕设指导师** ⭐⭐个人介绍:自己非常喜欢研究技术问题!专业做Java、Python、小程序、安卓、大数据、爬虫、Golang、大屏等实战项目。 ⛽⛽实战项目:有源码或者技术上的问题欢迎在评论区一起讨论交流! ⚡⚡有什么问题可以…

张小明 2025/12/31 19:07:01 网站建设

关于做外汇现货的网站工信部网站备案时间

目录 前言:为什么需要list 二、基础认知:list的底层与初始化 2.1什么是list 2.2头文件与命名空间 2.3初始化方式 三、迭代器误区 四、核心操作:增删查改 4.1元素添加:push_back/push_front/insert 4.2元素删除&#xff1…

张小明 2025/12/31 6:03:06 网站建设

网站建设 物流互联网推广品牌

电子电路设计应用很多,对于电子电路设计,我们需正确认识其重要性。为增进大家对电子电路设计的了解,本文将介绍电子电路相关知识,并对FPGA控制系统中的电子电路设计方法予以探讨。如果你对这篇电子电路设计文章存在兴趣&#xff0…

张小明 2025/12/31 19:57:08 网站建设

大连零基础网站建设培训班wordpress+tag+数字

Ai元人文构想:大行为模型2024—2025在技术与哲学中相遇——当智能学会行动,当行动追问意义文 / 为AI元人文构想悟空而行者今天是2025年12月10日。近一年前的2024-12-23 06:06七元宇宙,一篇题为《超越大型语言模型:大型行为模型如何…

张小明 2025/12/30 23:20:28 网站建设

网站制作报价优惠群晖wordpress 外网

第一章:金融风控图 Agent 的实时分析在高频交易与复杂欺诈手段并存的现代金融环境中,传统批处理式风控系统已难以应对毫秒级的风险识别需求。金融风控图 Agent 通过构建动态知识图谱,结合流式计算引擎,实现对账户、交易、设备等多…

张小明 2025/12/31 15:28:00 网站建设