乱码问题
问题描述:
控制台打印出乱码,不知为何
相关截图:
相关代码:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>s02</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>aliyun</id>
<name>aliyun</name>
<url>https://maven.aliyun.com/repository/public</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.6.RELEASE</version>
</dependency>
</dependencies>
</project>
相关代码:
<?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
https://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 在IoC容器启动时,自动由Spring实例化Apple对象,取名sweetApple放入到容器中 -->
<bean id="girl-cloth" class="com.imooc.spring.ioc.entity.Clothes">
<property name="style" value="连衣裙"></property>
<property name="color" value="red"></property>
</bean>
<bean id="boy-cloth" class="com.imooc.spring.ioc.entity.Clothes">
<property name="style" value="小西装"></property>
<property name="color" value="blue"></property>
</bean>
<bean id="girl" class="com.imooc.spring.ioc.entity.Person">
<property name="name" value="女孩"></property>
<property name="clothes" ref="girl-cloth"></property>
</bean>
<bean id="boy" class="com.imooc.spring.ioc.entity.Person">
<property name="name" value="男孩"></property>
<property name="clothes" ref="boy-cloth"></property>
</bean>
</beans>
相关代码:
package com.imooc.spring.ioc.entity;
public class Clothes {
private String style;
private String color;
public Clothes() {
}
public Clothes(String style, String color) {
this.style = style;
this.color = color;
}
public String getStyle() {
return style;
}
public void setStyle(String style) {
this.style = style;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
@Override
public String toString() {
return "Clothes{" +
"style='" + style + '\'' +
", color='" + color + '\'' +
'}';
}
}
相关代码:
package com.imooc.spring.ioc.entity;
public class Person {
private String name;
private Clothes clothes;
public Person() {
}
public Person(String name, Clothes clothes) {
this.name = name;
this.clothes = clothes;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Clothes getClothes() {
return clothes;
}
public void setClothes(Clothes clothes) {
this.clothes = clothes;
}
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
", clothes=" + clothes +
'}';
}
public void dress(){
System.out.println(this.name+"爱穿"+this.clothes.getColor()+this.clothes.getStyle());
}
}
相关代码:
package com.imooc.spring.ioc;
import com.imooc.spring.ioc.entity.Person;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringApplication {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
Person girl = context.getBean("girl",Person.class);
Person boy = context.getBean("boy",Person.class);
girl.dress();
boy.dress();
}
}
4
收起
正在回答 回答被采纳积分+1
1回答
Java工程师 2024版
- 参与学习 2024 人
- 提交作业 1318 份
- 解答问题 1228 个
2024重磅革新,超百小时内容豪华升级,加速提升高级技能与高薪就业竞争力 课程紧贴企业最新人才需求,历经7年持续迭代,帮助万名学子入行转行 从零起点到高阶实战,学习路径稳健顺滑,成就从小白到工程师高薪
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星