0
在search()方法中,我将值设置为ss
变量,但在尝试访问此内部run()或任何其他方法时获取null
。无法在spring中使用不同的方法访问实例变量mvc
最近我从支柱来到了春天。这senerio是可能的支柱,但我不知道为什么它没有在春天采取。
注意我不能在这里使用static
关键字,因为它是一个多用户应用程序。
@Controller
public class AddEmployee implements Runnable {
// instance variable having getter() and setter() method.
String ss;
@RequestMapping("/search")
public String search(Model model, @RequestParam String text) throws InterruptedException {
setSs(text); // setting value in ss
AddEmployee r = new AddEmployee();
Thread t = new Thread(r);
t.start();
return "listEmployee";
}
public void run() {
System.out.println("$$$$$$$$$$$$$$$--->"+getSs());// getting null here
}
public String getSs() {
return ss;
}
public void setSs(String ss) {
this.ss = ss;
}
}
在此先感谢。
你确定'text'变量不是null吗? –
@BOUALIALI是的,我确定 –