Spring Boot - 无法解析JSP页面

时间:2016-04-15 12:22:47

标签: spring-boot

application.yml

spring:
    mvc.view:
        prefix: /
        suffix: .jsp

SampleController.java

package springboot_demo;

import javax.annotation.Resource;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import springboot_demo.service.StudentService;

@Controller
@SpringBootApplication
public class SampleController extends SpringBootServletInitializer{

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SampleController.class);
    }

    @Resource
    private StudentService studentService;


    @RequestMapping("/")
    public String home(Model model) {
        model.addAttribute("data", studentService.list());
        return "index";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);
    }
}

'数据'从数据库中正确获取,但JSP页面似乎没有编译。我访问http://localhost:8080,浏览器会显示我:

<%@page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<body>
<h2>Hello World!</h2>
<c:forEach items="${data }" var="i">
<h2>${i.id }${i.name }</h2>
</c:forEach>
</body>
</html>

0 个答案:

没有答案