Spring boot to jsp page implementation
- 2020-06-23 00:32:59
- OfStack
I am learning Spring boot and have searched a lot about the implementation method of Spring boot jumping to jsp page. I will record 1 below for your reference. I hope this article has been helpful to you.
@ Controller annotations
1. Configuration in ES13en. properties file
# configuration jsp The default location of the file is: src/main/webapp
spring.mvc.view.prefix=/pages/
# configuration jsp File suffix
spring.mvc.view.suffix=.jsp
2. Configuration in Controller file
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class UserController {
@RequestMapping(value = "/index",method = RequestMethod.GET)
public String toIndex(){
return "index";
}
}
3. Start the method [main] in project ES24en. Java]
4. Visit url, access to jsp page: http: / / localhost: 8080 / index
@ RestController annotations
1. Configuration in ES42en. properties file
# configuration jsp The default location of the file is: src/main/webapp
spring.mvc.view.prefix=/pages/
# configuration jsp File suffix
spring.mvc.view.suffix=.jsp
2. Configuration in RestController file
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@RestController
public class UserController {
@RequestMapping(value = "/index",method = RequestMethod.GET)
public String toIndex(){
ModelAndView mv = new ModelAndView("index");
return mv;
}
}
3. Start the method [main] in project ES53en. java]
4. Visit url, access to jsp page: http: / / localhost: 8080 / index
. Note: application properties in spring. mvc. view. prefix and spring mvc. view. prefix attributes in spring - boot old version and new version is not 1:
In the old version:
spring.view.prefix=/pages/
spring.view.suffix=.jsp
In the new version:
spring.mvc.view.prefix=/pages/
spring.mvc.view.suffix=.jsp