本人正在学习Spring boot,搜索了很多关于Spring boot 跳转到jsp页面的实现方法介绍,下面我来记录一下,有需要了解的朋友可参考。希望此文章对各位有所帮助。
@Controller注解
1、application.properties文件中配置
				?
			
| 
 
								1
 
								2
 
								3
 
								4
						  | 
# 配置jsp文件的位置,默认位置为:src/main/webapp
spring.mvc.view.prefix=/pages/
# 配置jsp文件的后缀
spring.mvc.view.suffix=.jsp
 | 
2、Controller文件中配置
				?
			
| 
 
								1
 
								2
 
								3
 
								4
 
								5
 
								6
 
								7
 
								8
 
								9
 
								10
 
								11
 
								12
 
								13
						  | 
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、启动项目App.Java中的【main】方法启动
4. 访问url,访问到jsp页面:http://localhost:8080/index
@RestController注解
1、application.properties文件中配置
				?
			
| 
 
								1
 
								2
 
								3
 
								4
						  | 
# 配置jsp文件的位置,默认位置为:src/main/webapp
spring.mvc.view.prefix=/pages/
# 配置jsp文件的后缀
spring.mvc.view.suffix=.jsp
 | 
2、RestController文件中配置
				?
			
| 
 
								1
 
								2
 
								3
 
								4
 
								5
 
								6
 
								7
 
								8
 
								9
 
								10
 
								11
 
								12
 
								13
 
								14
						  | 
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、启动项目App.java中的【main】方法启动
4. 访问url,访问到jsp页面:http://localhost:8080/index
	注意:application.properties中spring.mvc.view.prefix和spring.mvc.view.prefix属性,在spring-boot 老版本中和新版本中不一样:
	老版本中用:
				?
			
                	
    
	
	
		
		
	
 
	
		
			
	
	 
     
	
			
                 
			
		
		
			
			
			
    
        
        
	
			
						
			
            			
    		
    		
		
	    
    	
    	
        
    	
    
| 
 
								1
 
								2
						  | 
spring.view.prefix=/pages/ 
spring.view.suffix=.jsp
 | 
新版本中用:
				?
			
	
						
						
						
						
						
						
						
																		
    
        
    
        
                        
                
                    
                
                
                
                    
                
                
                
                    
                
                
                
                    
                
                        
    
 																		
						
																		
    
        
 												
						
																		
	
	
		
				
			
																		
						
						
					
				
				                | 
 
								1
 
								2
						  | 
spring.mvc.view.prefix=/pages/
spring.mvc.view.suffix=.jsp
 | 
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。
原文链接:http://blog.csdn.net/yanweihpu/article/details/53927892
相关文章
             猜你喜欢
        
        - 个人服务器网站搭建:如何选择合适的服务器提供商? 2025-06-10
 - ASP.NET自助建站系统中如何实现多语言支持? 2025-06-10
 - 64M VPS建站:如何选择最适合的网站建设平台? 2025-06-10
 - ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
 - ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
 
			TA的动态
			
		
				- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
 - 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
 - 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
 - 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
 - 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
 
快网idc优惠网
QQ交流群
				您的支持,是我们最大的动力!				
			
		
        热门文章
        
    
    - 
            2025-05-27 27
 - 
            2025-05-25 52
 - 
            2025-05-25 73
 - 
            
Windows 8系统怎么升级成Windows 11系统,Windows 8升级Windows 11系统操作步骤
2025-05-27 101 - 
            2025-06-04 59
 
		热门评论
	
	
        
    		
            	
        
        
        