栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Spring View解析器可以与angularjs配合使用?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring View解析器可以与angularjs配合使用?

为了在spring使用静态资源(html,css,img,js),请使用类似于以下内容的目录结构:

src/   package/   LayoutController.javaWebContent/   WEB-INF/    static/      html/       layout.html      images/       image.jpg      css/       test.css      js/       main.js     web.xml    springmvc-servlet.xml@Controller public class LayoutController { @RequestMapping("/staticPage") public String getIndexPage() { return "layout.htm"; } }  <!-- in spring config file --> <mvc:resources mapping="/static/**" location="/WEB-INF/static/" />

layout.html

<h1>Page with image</h1><img src="/static/img/image.jpg"/>

请注意,你必须提及/static/img/image.jpg而不只是/image.jpg ..同样适用于CSS和JS。

要么

你还可以使用内容协商视图解析器,如下所示:

 <bean >          <property name="order" value="1" />          <property name="mediaTypes"> <map>    <entry key="json" value="application/json" />    <entry key="xml" value="application/xml" />    <entry key="rss" value="application/rss+xml" />     <entry key="html" value="text/html"/> </map>          </property>          <property name="defaultViews"> <list>   <!-- JSON View -->   <bean     >   </bean>

Spring MVC将使用“ ContentNegotiatingViewResolver”(order = 1)返回合适的视图(基于在“ mediaTypes ”属性中声明的文件扩展名),如果不匹配,则使用“ InternalResourceViewResolver”(order = 2)返回默认的JSP页面。

<bean        >        <property name="order" value="2" />        <property name="prefix"> <value>/WEB-INF/pages/</value>        </property>        <property name="suffix"> <value>.jsp</value>        </property>    </bean>

现在,从你的jsp中,你也可以重定向到你的静态html页面

   @Controller    public class LayoutController {        @RequestMapping("/index")        public String getIndexPage() { return "index";        }    }

index.jsp

<form:form method="GET" action="/static/html/layout.html">

现在尝试通过http://yourapp.com/ / index 访问你的服务,显示上述表单操作,它将显示layout.html

单击一个按钮或在jsp页面中提交以调用layout.html页面



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/395200.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号