This article mainly introduces the implementation method of Spring boot jumping to jsp page. The editor thinks it is quite good. Now I will share it with you and give it as a reference. Let’s follow the editor to take a look.
I am learning Spring boot, and I have searched a lot about the implementation method of Spring boot jumping to jsp page. I will record it below, and friends who need to know can refer to it. Hope this article is helpful to you.
@Controller annotations
1. Configuration in the application.properties file
# 配置jsp文件的位置,默认位置为:src/main/webapp spring.mvc.view.prefix=/pages/ # 配置jsp文件的后缀 spring.mvc.view.suffix=.jsp
2. Configuration in the 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 [main] method in the project App.Java
4. Access the url and access the jsp page: localhost:8080/index
@RestController annotation
1. Configuration in the application.properties file
# 配置jsp文件的位置,默认位置为:src/main/webapp spring.mvc.view.prefix=/pages/ # 配置jsp文件的后缀 spring.mvc.view.suffix=.jsp
2. Configuration in the 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 [main] method in the project App.java to start
4. Access the url and access the jsp page: localhost:8080/index
Note: application.properties The properties in spring.mvc.view.prefix and spring.mvc.view.prefix are different in the old version of spring-boot and in the new version:
Used in the old version:
spring.view.prefix=/pages/ spring.view.suffix=.jsp
Used in the new version:
spring.mvc.view.prefix=/pages/ spring.mvc.view.suffix=.jsp
[Related recommendations]
2. Java implementation Video tutorial on proportional thumbnails of pictures
The above is the detailed content of How to implement jsp page jump in java. For more information, please follow other related articles on the PHP Chinese website!