《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门,即可获取!
@Override
public String toString() {
return “Car2 [name=” + name + “, price=” + price + “]”;
}
}
@Test
public void demo5() {
// 创建工程
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(“applicationContext.xml”);
// 获得到对应XML当中的对象
// 获得到对应XML当中的对象
Car2 car2 = (Car2) applicationContext.getBean(“car2”);
System.out.println(car2);
}

(1)直接注入
<?xml version="1.0" encoding="UTF-8"?><beans xmlns=“http://www.springframework.org/schema/beans”
xmlns:p=“http://www.springframework.org/schema/p”
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">

package com.itzheng.spring.demo4;
public class Employee {
private String name;
private Car2 car2;
public void setName(String name) {
this.name = name;
}
public void setCar2(Car2 car2) {
this.car2 = car2;
}
@Override
public String toString() {
return “Employee [name=” + name + “, car2=” + car2 + “]”;
}
}
@Test
public void demo5() {
// 创建工程
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(“applicationContext.xml”);
// 获得到对应XML当中的对象
// 获得到对应XML当中的对象
Car2 car2 = (Car2) applicationContext.getBean(“car2”);
System.out.println(car2);
}

(2)通过方法获得值,注入到另外一个对象的属性
<?xml version="1.0" encoding="UTF-8"?><beans xmlns=“http://www.springframework.org/schema/beans”
xmlns:p=“http://www.springframework.org/schema/p”
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">

package com.itzheng.spring.demo4;
public class CarInfo {
private String name;
public String getName() {
return “摩托车”;
}
public Double calculatorPrice() {
return Math.random() * 3000;
}
}
package com.itzheng.spring.demo4;
总结
面试前的“练手”还是很重要的,所以开始面试之前一定要准备好啊,不然也是耽搁面试官和自己的时间。
我自己是刷了不少面试题的,所以在面试过程中才能够做到心中有数,基本上会清楚面试过程中会问到哪些知识点,高频题又有哪些,所以刷题是面试前期准备过程中非常重要的一点。
面试题及解析总结

大厂面试场景

知识点总结

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门,即可获取!
中非常重要的一点。
面试题及解析总结
[外链图片转存中…(img-zV7tWPCF-1714677355360)]
大厂面试场景
[外链图片转存中…(img-NrTIY3WO-1714677355360)]
知识点总结
[外链图片转存中…(img-vm7xDhNp-1714677355361)]
《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门,即可获取!
1万+




被折叠的 条评论
为什么被折叠?



