我已经用SpringMVC开始了一个新项目。我使用messagesource结构。但是密钥已经在html页面中查找过了。关键是“deneme.deneme”。这个字符串正在网页中查找
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.yummynoodlebar.web.controller","com.yummynoodlebar.web.service","com.yummynoodlebar.web.domain"})
public class WebConfig extends WebMvcConfigurerAdapter {
...
@Bean(name = "labelSource")
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasenames("classpath:resources/i18n/labels");
...
return messageSource;
}}
@Component
public class ResourceManager {
@Resource(name = "labelSource")
private MessageSource messageSource;
public String getLabel(String code) {
return messageSource.getMessage(code, null, Locale.ENGLISH);
}
}
@Controller
@RequestMapping("/")
public class SiteController {
@RequestMapping(method = RequestMethod.GET)
public String getHomePage(Model model) {
String str = resourceManager.getLabel("deneme.deneme");
model.addAttribute("deneme",str);
return "/anasayfa";
}
}
labels_en.properties is file under the resources/i18/ directory.
{
deneme.deneme = burak
}
答案 0 :(得分:0)
我修正了错误。我做错了。这段代码" messageSource.setBasenames(" classpath:resources / i18n / labels");"是错的。它应该是" messageSource.setBasenames(" classpath:i18n / labels");"