我第一次建立了我的Spring MVC的項目,gradle bootRun
與成功以下控制器類:大廈的Spring MVC應用程序,控制器「無法找到符號」模式
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloController {
@RequestMapping("/")
public String hello() {
return "resultPage";
}
}
然後我就把它改成了數據傳遞給我的視圖類:
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloController {
@RequestMapping("/")
public String hello(Model model) {
model.addAttribute("message", "Hello from the controller");
return "resultPage";
}
}
現在當我建立我的項目,我得到以下錯誤:
HelloController.java:13: error: cannot find symbol
public String hello(Model model) {
^
symbol: class Model
location: class HelloController
1 error
:compileJava FAILED
FAILURE: Build failed with an exception.
任何想法我做錯了什麼?
可能缺少導入? –
@MatiasElorriaga是的,正確!我剛剛在幾分鐘前添加了一個答案。 – KZcoding