springboot访问页面显示Whitelabel Error Page
问题新建springboot(2.5.7版本)项目配置好mvc,访问页面显示Whitelabel Error Page项目代码@Controllerpublic class LoginController {@Autowiredprivate LoginService loginService;@RequestMapping("/login")public String login(){Syste
·
背景描述
问题
新建springboot(2.5.7版本)项目配置好mvc,访问页面显示Whitelabel Error Page
项目
代码
@Controller
public class LoginController {
@Autowired
private LoginService loginService;
@RequestMapping("/login")
public String login(){
System.out.println("访问");
return "login";
}
}
配置文件
server:
port: 8080
servlet:
context-path: /
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
username: root
password: root
mvc:
view:
prefix: /views/
suffix: .html
访问登录页面
解决
配置文件添加
spring:
resources:
static-locations: classpath:/templates
总结
默认Springboot会从static目录加载前端静态资源,我的项目页面写在了templates目录下,通过配置static-locations参数或直接把页面放入static目录下都可以解决问题。
更多推荐
已为社区贡献1条内容
所有评论(0)