Spring入门实例:用Spring创建对象

 时间:2024-10-13 20:59:19

1、新建一个domain对象实例:Department。package com.gwolf.springmvc.domain;publ足毂忍珩ic class Department { private Integer id; private String departmentName; public Department() { } public Department(int i, String string) { this.id = i; this.departmentName = string; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getDepartmentName() { return departmentName; } public void setDepartmentName(String departmentName) { this.departmentName = departmentName; } @Override public String toString() { return "Department [id=" + id + ", departmentName=" + departmentName + "]"; } }

Spring入门实例:用Spring创建对象

3、在applicationContext.xml文件中声明Department实例。争犸禀淫<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="department" class = "com.gwolf.springmvc.domain.Department"> <property name="departmentName" value="技术部"></property> </bean> </beans>

Spring入门实例:用Spring创建对象

5、从IOC容器中获取Bean实例:Spring将调用构造器初始化Bean方法。ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml"); Department department = (Department)applicationContext.getBean("department");

Spring入门实例:用Spring创建对象
  • 花生棒+树莓派端口映射搭建Web网站
  • win10 1903新bug移动宽带无法正常WiFi连接
  • linux下telnet安装与使用
  • 如何让笔记本电脑变成一个路由器
  • Xenserver中如何关闭虚拟机
  • 热门搜索
    姜撞奶为什么不凝固 为什么电脑开机黑屏 mc天佑为什么被全网封 昱字怎么读 哈罗单车怎么收费 舍利子是怎么形成的 sunny怎么读 日本拉面的做法 手机呼叫转移怎么设置 扁豆的做法大全家常