SPRING MVC如何映射资源

时间:2017-04-30 23:29:45

标签: java spring twitter-bootstrap spring-mvc

我在Spring MVC中做了一个应用程序,我想使用bootstrap但是我无法链接资源文件夹,当我尝试使用我疯狂的应用程序崩溃时,是否有另一种映射方式资源文件夹?

这是我的dispatcher-servlet

<?xml version="1.0" encoding="UTF-8"?>
<!--<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:mvc="http://www.springframework.org/schema/mvc"

   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                             http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
                             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
                             http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc             
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd     
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>

<!--
Most controllers will use the ControllerClassNameHandlerMapping above, but
for the index controller we are using ParameterizableViewController, so we must
define an explicit mapping for it.
-->
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <props>

            <prop key="index.htm">indexController</prop>
            <prop key="home.htm">homeController</prop>
            <prop key="cliente.htm">AdministracionController</prop> 
            <prop key="receta.htm">RecetaController</prop>  
            <prop key="ingrediente.htm">IngredienteController</prop>
            <prop key="AñadirCliente.htm">AdministracionController</prop>
            <prop key="AñadirUsuario.htm">InfoclienteController</prop>
            <prop key="editarUsuario.htm">UsereditController</prop>
            <prop key="login.htm">LoginController</prop>
            <prop key="compañia.htm">homeController</prop>
            <prop key="socios.htm">homeController</prop>
            <prop key="soluciones.htm">homeController</prop>
            <prop key="listaUsuario.htm">InfoclienteController</prop>
            <prop key="consultaMinuta.htm">SupervisorController</prop>
            <prop key="consultaExito.htm">SupervisorController</prop>
            <prop key="consultaError.htm">SupervisorController</prop>
            <prop key="minutaDia.htm">SupervisorController</prop>
            <prop key="editarCliente.htm">ClienteController</prop>
            <prop key="admHome.htm">Administrador2Controller</prop>
            <prop key="encarHome.htm">EncargadoController</prop>
            <prop key="infoCliente.htm">InfoclienteController</prop>
            <prop key="listaCasino.htm">CasinoController</prop>
            <prop key="AñadirCasino.htm">CasinoController</prop>
            <prop key="editarCasino.htm">CasinoeditController</prop>
            <prop key="AñadirIngrediente.htm">IngredienteController</prop>
            <prop key="editarIngrediente.htm">Ingrediente2Controller</prop>
            <prop key="AñadirReceta.htm">RecetaController</prop>
            <prop key="editarReceta.htm">Receta2Controller</prop>

            <prop key="Encargado/ingrediente.htm">IngredienteControllerEncargado</prop>
            <prop key="Encargado/AñadirIngrediente.htm">IngredienteControllerEncargado</prop>
            <prop key="Encargado/editarIngrediente.htm">Ingrediente2ControllerEncargado</prop>
             <prop key="Encargado/receta.htm">RecetaControllerEncargado</prop>
            <prop key="Encargado/AñadirReceta.htm">RecetaControllerEncargado</prop>
             <prop key="Encargado/editarReceta.htm">Receta2ControllerEncargado</prop>
        </props>             
    </property>
</bean>

<bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"
      p:prefix="/WEB-INF/jsp/"
      p:suffix=".jsp" />




<bean name="Receta2ControllerEncargado" class="controller.Receta2ControllerEncargado" />
<bean name="RecetaControllerEncargado" class="controller.RecetaControllerEncargado" />
<bean name="Ingrediente2ControllerEncargado" class="controller.Ingrediente2ControllerEncargado" />
<bean name="IngredienteControllerEncargado" class="controller.IngredienteControllerEncargado" />

<bean name="Receta2Controller" class="controller.Receta2Controller" />
<bean name="RecetaController" class="controller.RecetaController" />
<bean name="Ingrediente2Controller" class="controller.Ingrediente2Controller" />
<bean name="IngredienteController" class="controller.IngredienteController" />
<bean name="InfoclienteController" class="controller.InfoclienteController"/>
<bean name="homeController" class="controller.homeController"/>
<bean name="AdministracionController" class="controller.AdministracionController"/>
<bean name="SupervisorController" class="controller.SupervisorController"/>
<bean name="LoginController" class="controller.LoginController"/>
<bean name="ClienteController" class="controller.ClienteController"/>
<bean name="Administrador2Controller" class="controller.Administrador2Controller"/>
<bean name="CasinoController" class="controller.CasinoController"/>
<bean name="CasinoeditController" class="controller.CasinoeditController"/>
<bean name="UsereditController" class="controller.UsereditController"/>

<bean name="EncargadoController" class="controller.EncargadoController"/>
<bean name="indexController"
      class="org.springframework.web.servlet.mvc.ParameterizableViewController"
      p:viewName="index" />



</beans>

1 个答案:

答案 0 :(得分:0)

最后我通过将其添加到我的调度程序servlet

来修复它
<mvc:default-servlet-handler/>
<bean      class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

并更改我的web.xml

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

所以调度程序servlet管理所有请求而不仅仅是.htm

但现在我有其他问题,有这么多控制器是正常的吗?目前我正在为每个视图和表单制作一个控制器。