Call the driver in SpringMVC

1

I need to call my controller directly when the application is started, to paint the html with the data, but I do not know how it is done - >

<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>
             <!-- Spring -->
            <prop key="index.htm">indexController</prop>

            <!-- Funciones del Sistema -->
            <prop key="Form_CrearCuenta.htm">SistemaController</prop>
            <prop key="CrearCuenta.htm">SistemaController</prop>
            <prop key="Cerrar_sesion.htm">SistemaController</prop>
            <prop key="Corregir_Examen.htm ">SistemaController</prop>


            <!-- Funciones Comunes de usuarios-->
            <prop key="Home.htm">UsuarioController</prop> 
            <prop key="Login.htm">UsuarioController</prop>
            <prop key="Hacer_examen.htm">UsuarioController</prop>

            <!-- Funciones Comunes Administrador-->
            <prop key="AdministrarUsuarios.htm">AdminController</prop>
        </props>
    </property>
</bean>


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

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

<!--  Controlador del Sistema  -->
<bean name="SistemaController" class="Controladores.ControladorSistema"/>

<!--  Controlador del usuario  -->
<bean name="UsuarioController" class="Controladores.ControladorUsuario"/>

<!--  Controlador del admin  -->
<bean name="AdminController" class="Controladores.ControladorAdministrador"/>

You put forms that call controllers and forward the data to a page and paint the data, but call my controller directly when I start my program, I'm having problems.

I tried to do

<bean id="viewResolver" class="SistemaController" />

But I can not do it, thanks.

    
asked by EduBw 25.10.2018 в 12:23
source

1 answer

1

Right now you have the default page of your application be managed by the bean indexController

<prop key="index.htm">indexController</prop>

That is an instance of ParameterizableViewController

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

We can see in the documentation of Spring which is a basic Controller class, created to simply associate a view:

  

Trivial controller that always returns to named view.

You can, therefore, create a new class (called for example IndexController ) that gets all the functionality you want to add, and that shows the view (the JSP) you need, showing the data you want:

<bean name="indexController" class="controladores.IndexController" />
    
answered by 25.10.2018 / 15:11
source