为什么我这个国际化,点击切换按钮英文不起作用?只显示中文
最后附上controller代码
package com.yadu.example.demo.controller;
import com.yadu.example.demo.entity.User;
import com.yadu.example.demo.service.LocaleMessageSourceService;
import com.yadu.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
@RestController
public class Controller {
@Autowired
private UserService userService;
@Autowired
private MessageSource messageSource;
/**
* 获取国际化信息
*/
@Resource
private LocaleMessageSourceService localeMessageSourceService;
@GetMapping("/hi")
public String index(){
return "hello spring boot";
}
@RequestMapping("/users/{userId}")
public User getUser(@PathVariable("userId") int userId){
User user = userService.getById(userId);
return user;
}
/**
* freemarker模板
* @param modelAndView
* @return
*/
@RequestMapping(value = "/indexFre")
public ModelAndView indexFre(ModelAndView modelAndView) {
//设置返回的页面名称
modelAndView.setViewName("indexFre");
//要返回在页面的数据
/* List<User> userList = userService.getUsers();
modelAndView.addObject("userList", userList);*/
return modelAndView;
}
@RequestMapping("/hello")
public ModelAndView hello(ModelAndView modelAndView){
String msg3 = localeMessageSourceService.getMessage("welcome");
modelAndView.setViewName("hello");
return modelAndView;
}
/* @RequestMapping("/changeSessionLanauage")
public String changeSessionLanauage(HttpServletRequest request, HttpServletResponse response, String lang){
System.out.println(lang);
LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
if("zh".equals(lang)){
localeResolver.setLocale(request, response, new Locale("zh", "CN"));
}else if("en".equals(lang)){
localeResolver.setLocale(request, response, new Locale("en", "US"));
}
return "redirect:/hello";
}*/
}