zl程序教程

您现在的位置是:首页 >  后端

当前栏目

spring boot properties 编码问题[四]

SpringBoot编码 properties 问题
2023-09-14 08:59:24 时间

情景

application.properties 中:

server.port=8081
person.last-name=张三
person.age=18
person.birth=2017/12/15
person.boss=false
person.maps.k1=v1
person.maps.k2=v2
person.lists=a,b,c

在测试中的代码如下:

@RunWith(SpringRunner.class)
@SpringBootTest
class DemoApplicationTests {
    @Autowired
    Person person;
    @Test
    void contextLoads() {
        System.out.println(person);
    }
}

代码和我的一篇随笔<<spring boot yaml 配置>>一致,仅仅是配置换成了properties

结果如下:

出现了乱码。

这是因为运行时编码和我们书写的idea编码不一致。

这样就可以解决了。