springboot 跳转至页面遇到的问题

问题汇总(先声明,我的springboot 版本是1.5.7.RELEASE):

1、想跳转到某个页面,但是页面上却显示字符串,比如

检查下controller类

@Controller
public class HomeController {
	
	@RequestMapping(value="/index",method = RequestMethod.GET)
	@ResponseBody
	public String index(){
		return "/index";
	}
}

我的解决办法:去掉@ResponseBody注解

另外附:我的资源文件的目录结构

2、报错:

There was an unexpected error (type=Internal Server Error, status=500).

Error resolving template "/index", template might not exist or might not be accessible by any of the configured Template Resolvers

我的目录结构:

controller类代码,见问题1。

我的解决办法:在resources下新建templates文件夹,新建index.html

注:我的配置文件没有添加额外的配置,比如

spring.mvc.view.prefix=classpath:/templates/
spring.mvc.view.suffix=.html

为什么我再强调这个,因为在网上其他文章中有这样解决的,但是我没有按着这样配

3、发送get请求,报错:

There was an unexpected error (type=Not Found, status=404).

No message available

我的代码和资源文件目录结构:

@Controller
public class HomeController {
	
	@RequestMapping(value="/getIndex",method = RequestMethod.GET)
	public String index(){
		return "/index";
	}	
}

我的解决办法:

在pom文件里面没有添加下面的这个依赖,添加上即可

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值