質問編集履歴
2
ソースコード追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -48,6 +48,102 @@
|
|
48
48
|
|
49
49
|
```
|
50
50
|
|
51
|
+
|
52
|
+
|
53
|
+
```ここに言語を入力
|
54
|
+
|
55
|
+
package com.toray.controller;
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
import java.security.Principal;
|
60
|
+
|
61
|
+
import java.util.Locale;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
import org.springframework.beans.factory.annotation.Autowired;
|
66
|
+
|
67
|
+
import org.springframework.security.core.Authentication;
|
68
|
+
|
69
|
+
import org.springframework.ui.Model;
|
70
|
+
|
71
|
+
import org.springframework.web.bind.annotation.ControllerAdvice;
|
72
|
+
|
73
|
+
import org.springframework.web.bind.annotation.ModelAttribute;
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
import com.toray.entity.User;
|
78
|
+
|
79
|
+
import com.toray.repository.UserRepository;
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
@ControllerAdvice(basePackages = "com.xxx.controller")
|
84
|
+
|
85
|
+
public class AppController {
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
@Autowired
|
90
|
+
|
91
|
+
UserRepository userRepository;
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
@ModelAttribute("user")
|
96
|
+
|
97
|
+
public User addOneObject(Principal principal, Model model) {
|
98
|
+
|
99
|
+
Authentication authentication = (Authentication) principal;
|
100
|
+
|
101
|
+
User user = (User) authentication.getPrincipal();
|
102
|
+
|
103
|
+
User myuser = userRepository.findByIdEquals(user.getId());
|
104
|
+
|
105
|
+
Integer languageflg = myuser.getLanguageflg();
|
106
|
+
|
107
|
+
this.setLang(languageflg);
|
108
|
+
|
109
|
+
model.addAttribute("languageflg", languageflg);
|
110
|
+
|
111
|
+
return user;
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
public void setLang(Integer languageflg)
|
118
|
+
|
119
|
+
{
|
120
|
+
|
121
|
+
switch(languageflg) {
|
122
|
+
|
123
|
+
case 2:
|
124
|
+
|
125
|
+
Locale.setDefault(Locale.JAPANESE);
|
126
|
+
|
127
|
+
System.out.println(Locale.getDefault());
|
128
|
+
|
129
|
+
break;
|
130
|
+
|
131
|
+
default:
|
132
|
+
|
133
|
+
Locale.setDefault(Locale.ENGLISH);
|
134
|
+
|
135
|
+
System.out.println(Locale.getDefault());
|
136
|
+
|
137
|
+
break;
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
```
|
146
|
+
|
51
147
|
各言語ごとの表示内容は、messages.propertiesに定義しています。
|
52
148
|
|
53
149
|
動いている場所が違うので不可能でしょうか?
|
1
ソースコード追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,7 +24,27 @@
|
|
24
24
|
|
25
25
|
```ここに言語を入力
|
26
26
|
|
27
|
+
//Thymeleaf
|
28
|
+
|
27
|
-
th:utext="#{
|
29
|
+
th:utext="#{company}";
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
```ここに言語を入力
|
34
|
+
|
35
|
+
//messages_ja.properties
|
36
|
+
|
37
|
+
company = 会社
|
38
|
+
|
39
|
+
```
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
```ここに言語を入力
|
44
|
+
|
45
|
+
//messages_en.properties
|
46
|
+
|
47
|
+
company = Company
|
28
48
|
|
29
49
|
```
|
30
50
|
|