다국어처리
This commit is contained in:
@@ -2,6 +2,11 @@ package com.example.restfulwebservice;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@SpringBootApplication
|
||||
public class RestfulWebServiceApplication {
|
||||
@@ -10,4 +15,10 @@ public class RestfulWebServiceApplication {
|
||||
SpringApplication.run(RestfulWebServiceApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LocaleResolver localeResolver() {
|
||||
SessionLocaleResolver localeResolver = new SessionLocaleResolver();
|
||||
localeResolver.setDefaultLocale(Locale.KOREA);
|
||||
return localeResolver;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.example.restfulwebservice.user;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||
@@ -7,10 +9,13 @@ import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||
import javax.validation.Valid;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@RestController
|
||||
public class UserController {
|
||||
private final UserDaoService userDaoService;
|
||||
@Autowired
|
||||
private MessageSource messageSource;
|
||||
|
||||
public UserController(UserDaoService userDaoService) {
|
||||
this.userDaoService = userDaoService;
|
||||
@@ -51,4 +56,10 @@ public class UserController {
|
||||
throw new UserNotFoundException(String.format("ID[%s] not found", id));
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping(path = "/hello-world-internationalized")
|
||||
public String helloWorldInternationalized(
|
||||
@RequestHeader(name = "Accept-Language", required = false) Locale locale) {
|
||||
return messageSource.getMessage("greeting.message", null, locale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,8 @@ server:
|
||||
|
||||
logging:
|
||||
level:
|
||||
org.springframework: DEBUG
|
||||
org.springframework: DEBUG
|
||||
|
||||
spring:
|
||||
messages:
|
||||
basename: messages
|
||||
@@ -0,0 +1 @@
|
||||
greeting.message=<EFBFBD>ȳ<EFBFBD><EFBFBD>ϼ<EFBFBD><EFBFBD><EFBFBD>
|
||||
@@ -0,0 +1 @@
|
||||
greeting.message=Hello
|
||||
@@ -0,0 +1 @@
|
||||
greeting.message=Bonjour
|
||||
Reference in New Issue
Block a user