package com.sptg.common.core.test;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.sptg.common.core.locale.I18n;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping(value = "/test")
@RequiredArgsConstructor
@Slf4j
public class TestController {
	@Autowired
	private MessageSource messageSource;
	@I18n("messages")
	@GetMapping("/index")
    public ModelAndView index(HttpServletRequest request){
		 ModelAndView modelAndView=new ModelAndView("index");
		 Locale locale = LocaleContextHolder.getLocale();
		 String hello= messageSource.getMessage("hello", null, locale);
		 log.warn("----------------"+hello);
		 return modelAndView;
	}
}
