開発モード用に構成され、コードに変更を加え、あなたのアイデアにその構成を再実行する必要はありません、MACテストは無効です
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
アクセス静的リソース
SRC /メイン/リソース/静的
# 设定静态文件路径
spring.resources.static-locations=classpath:/static/
カスタムメッセージ改質器
//定义消息转换器
//springboot默认配置org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration
@Bean
public StringHttpMessageConverter stringHttpMessageConverter(){
return new StringHttpMessageConverter(StandardCharsets.ISO_8859_1);
}
@RequestMapping("/")
public String first(){
return "hello傅立叶" //因为使用的是ISO_8859_1,所以中文乱码
}
アイデアは、文字化けのプロパティは、ソリューションファイル漢字を読むには
- >設定- IntelliJのIDEAをクリックしてファイルに>エディタ- >ファイルエンコーディングはすべてUTF-8に設定され、透明なネイティブ-する -ascii ダニ
NO BOMを選択UTF-8のファイルを作成します
FastJson
springbootのデフォルトはジャクソンです
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.15</version>
</dependency>
@SpringBootApplication(scanBasePackages = {"com.fly"})//默认是本包及子报
public class SpringDemoApp extends WebMvcConfigurerAdapter {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
//创建FastJson的消息转换器
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
//创建FastJson的配置对象
FastJsonConfig config = new FastJsonConfig();
//对Json数据进行格式化
config.setSerializerFeatures(SerializerFeature.PrettyFormat);
converter.setFastJsonConfig(config);
converters.add(converter);
}
//不继承WebMvcConfigurerAdapter使用配置成Bean的方式
//@Bean
//public HttpMessageConverters fastJsonHttpMessageConverter(){
// //创建FastJson的消息转换器
// FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
// //创建FastJson的配置对象
// FastJsonConfig config = new FastJsonConfig();
// //对Json数据进行格式化
// config.setSerializerFeatures(SerializerFeature.PrettyFormat);
// converter.setFastJsonConfig(config);
// return new HttpMessageConverters(converter);
//}
public static void main(String[] args){
SpringApplication.run(SpringDemoApp.class,args);
}
}
@RequestMapping("/person")
public Object show(){
Person person = new Person();
person.setId(1);
person.setDate(new Date());
person.setName("fly傅立叶");
return person;
}
中国の文字化けことがわかりました
#response编码设置为utf-8功能开启
spring.http.encoding.force=true
**表示される時間は、タイムスタンプがあります
@JSONField(format = "yyyy-MM-dd HH:mm:ss") //也可以加在字段上
public Date getDate() {
return date;
}