该项目有点混乱,所以我会尝试尽可能简单,但就上下文而言,这是使用 Angular、Spring 和 Maven。不过,我相当确定唯一相关的部分是有角度的。
我正在尝试进行调用以显示资源包中的信息,并且它可以很好地处理几个显示字符串完整的控制台打印,但在加载时它仍然在页面上显示为数组(例如:显示为 S,t, r,i,n,g 而不是字符串)
这是java中的MessageController(多线程是作业的一部分,我不认为它是相关的,但将其包含在上下文中):
public class MessageController {
static ExecutorService messageExecutor = newFixedThreadPool(2);
public static String myMessage = "";
public static String myMessage1 = "";
@RequestMapping(path = "/welcome")
public String welcome(){
Properties properties=new Properties();
messageExecutor.execute(()->{
try{
InputStream stream = new ClassPathResource("welcome_en.properties").getInputStream();
properties.load(stream);
System.out.println(properties.getProperty("welcome"));
myMessage = properties.getProperty("welcome");
} catch (Exception e) {
e.printStackTrace();
}
});
messageExecutor.execute(()->{
try{
InputStream stream = new ClassPathResource("welcome_fr.properties").getInputStream();
properties.load(stream);
System.out.println(properties.getProperty("welcome"));
myMessage1 = properties.getProperty("welcome");
} catch (Exception e) {
e.printStackTrace();
}
});
String arrayMessage = myMessage+ ", " +myMessage1;
System.out.println(arrayMessage);
return arrayMessage;
}
}
此时,一切都正确打印到控制台,一切看起来都很好。
接下来,在 app.component.ts 中我们有:
ngOnInit(){
this.getWelcome().subscribe(
welcome=>{
this.welcome= <any>Object.values(welcome);
}}
和 getWelcome():
getWelcome(): Observable<any>{
return this.httpClient.get(this.baseURL + '/welcome', {responseType: "text"});
}
这只是设置:
welcome!:string;
并在 html 中调用为:
{{welcome}}
使用此,网页显示:W,e,l,c,o,m,e,,, ,B,i,e,n,v,e,n,u,e
即使 http://localhost:8080/welcome 正确显示:Welcome, Bienvenue
如何才能正确显示此消息?