简体   繁体   中英

IntelliJ IDEA - SpringBoot project / cannot find declaration to go to

I am fairly new to Java and Spring and I have troubles with writing a simple application.

Thing is, IntelliJ does not see my.jsp files that are in the project. The application works, but I am not getting help from IntelliJ. I also can't use model I created in my HomeController class in my homepage.jsp with forms and modelAttribute, as it becomes red and does not support me writing the code.

.jsp files are in webapp/WEB-INF/jsp/

I have application.properties file with:

spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

Here are my files:

HomeController.java

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HomeController {

    @RequestMapping("/")
    public String hello(Model theModel){

        Credentials theCredentials = new Credentials();

        theModel.addAttribute("credentials", theCredentials);

        return "homepage";
    }
}

Credentials.java

public class Credentials {

private String username;
private String password;

public Credentials() {
}

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

}

homepage.jsp

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Homepage</title>
</head>
<body>

Welcome to the virtual deanery!!!
<br><br>

Please log in as Student or Teacher to continue:
<br><br>

<form:form modelAttribute="credentials"> 
<%--credentials are not found--%>

<%--somecode--%>

</form:form>



</body>
</html>

Thanks a lot for help!

Maybe you have something wrong with your web-inf directory mark. Right click on webapp -> mark directory as -> sources root

Need to add spring Facet with springs configurations like this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM