[英]how to get Spring MVC in intellij to run HTML
我有一個基本的spring MVC項目(他們創建的基本模型),並試圖讓它運行html而不是JSP(JSP完美運行)
我的控制器
@Controller
@RequestMapping("/")
public class HelloController {
@RequestMapping(method = RequestMethod.GET)
public String printWelcome(ModelMap model) {
model.addAttribute("message", "Hello world!");
return "index";
}
}
我的MVC調度程序服務
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.springapp.mvc"/>
<!--<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">-->
<!--<property name="prefix" value="/WEB-INF/pages/"/>-->
<!--<property name="suffix" value=""/>-->
<!--</bean>-->
<mvc:resources mapping="/WEB-INF/pages/" location="/WEB-INF/pages/" />
我已經嘗試了很多事情,例如映射到/ WEB-INF / pages / **,完全刪除InternalResourceViewResolver(帶有以前的映射,)使后綴為空,帶有html等,但無濟於事。 我看了其他與此類似的問題,但沒有運氣。 還閱讀了有關htmls的靜態文件夾的信息,但感到困惑...我做錯了什么?
網頁webapp的文件結構
--WEB-INF ----頁面------ hello.jsp,index.html
<mvc:resources mapping="/WEB-INF/pages/" location="/WEB-INF/pages/" />
映射值代表URL映射。 因此,請在此處輸入“ / pages / **”
<mvc:resources mapping="/pages/**" location="/WEB-INF/pages/" />
現在,您可以通過localhost:8080/app/pages/index.html
來訪問html頁面之類的靜態文件。
在Java Controller中而不是return "index";
應該return "redirect:/pages/index.html";
閱讀此示例以獲取所有詳細信息。 希望我能幫上忙。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.