SpringBoot當(dāng)中如何整合靜態(tài)html(模擬SpringMVC)
整合靜態(tài)html(模擬SpringMVC):
馬克- to-win:馬克 java社區(qū):防盜版實(shí)名手機(jī)尾號(hào): 73203。
馬克-to-win@馬克java社區(qū):1)在上一個(gè)項(xiàng)目中,在src/main目錄下,添加resources/static/index.html:(參考目錄下:BootSpringMVC)注意:在resources根目錄下添加test.html,是訪問(wèn)不到的。在src/main目錄下,添加resources/templates/result.html,也是訪問(wèn)不到的。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
index1
<a href="/hello.do">test SpringMvc</a>
</body>
</html>
package com.SpringbootMaven;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@SpringBootApplication
public class App {
@RequestMapping("/hello")
void myhome(HttpServletResponse res) throws IOException {
System.out.println("spring boot springMvc 馬克-to-win!");
res.sendRedirect("index.html");
}
public static void main(String[] args) throws Exception {
SpringApplication.run(App.class, args);
}
}
測(cè)試: http://localhost:8080/index.html