Commit 0d1226fc authored by Quxl's avatar Quxl

语言环境设置

parent faa1cfc0
package com.egolm.film.api; package com.egolm.film.api;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import com.egolm.common.bean.Rjx; import com.egolm.common.bean.Rjx;
import com.egolm.film.config.interceptor.LocaleSessionInterceptor;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
...@@ -15,7 +22,7 @@ import io.swagger.annotations.ApiOperation; ...@@ -15,7 +22,7 @@ import io.swagger.annotations.ApiOperation;
@Controller @Controller
@RequestMapping("open/member") @RequestMapping("open/member")
public class MemberOpenApiController { public class MemberOpenApiController {
@PostMapping("register") @PostMapping("register")
@ApiOperation("会员注册") @ApiOperation("会员注册")
@ApiImplicitParams({ @ApiImplicitParams({
...@@ -41,7 +48,15 @@ public class MemberOpenApiController { ...@@ -41,7 +48,15 @@ public class MemberOpenApiController {
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "i18n_language", defaultValue="zh_CN"), @ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "i18n_language", defaultValue="zh_CN"),
}) })
public Object setLocale(String i18n_language) { public Object setLocale(HttpSession session, String i18n_language) {
Locale locale = new Locale(i18n_language);
session.setAttribute(LocaleSessionInterceptor.I18N_LANGUAGE_SESSION, locale);
return Rjx.jsonOk(); return Rjx.jsonOk();
} }
@PostMapping("getLocale")
@ApiOperation("获取当前语言环境")
public Object getLocale(HttpServletRequest request) {
return Rjx.jsonOk().setMessage(LocaleContextHolder.getLocale().getLanguage());
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment