gpt4 book ai didi

java - Vaadin 获取 init 外部字符串的值

转载 作者:行者123 更新时间:2023-12-02 05:39:40 25 4
gpt4 key购买 nike

我是否可以在 init 方法之外检索字符串“code”的值并在不同的方法中使用它?

如果是,怎么做?

感谢您的帮助。

编辑:字符串必须位于 init 方法中。

代码:

protected void init(VaadinRequest request) {
main();
String code = request.getParameter("code");
if (code != null){
System.out.println("Code: " + code);
next();
}
}

最佳答案

您可以将代码存储为实例变量:

public class VaadinApplication {

private String code = null; // <-- Instance variable

protected void init(VaadinRequest request) {
main();
String code = request.getParameter("code");
if (code != null){
this.code = code; // <-- store code here
System.out.println("Code: " + code);
next();
}

protected void otherMethod() {
this.code; // <-- Get code here and use it
//...
}
}

关于java - Vaadin 获取 init 外部字符串的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24613722/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com