zoukankan      html  css  js  c++  java
  • Spring MVC的XML方式配置

    一、添加依赖

    <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-web</artifactId>
          <version>4.3.12.RELEASE</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-webmvc</artifactId>
          <version>4.3.12.RELEASE</version>
        </dependency>

    二、配置web.xml

    <!--SpringMVC核心分发器-->
      <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>classpath:spring/spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
      </servlet-mapping>

    三、配置spring-mvc.xml

    <context:component-scan base-package="com.wslook.controller" />
     
    <!-- 视图模式配置 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name="prefix" value="/WEB-INF/pages/" />
       <property name="suffix" value=".jsp" />
    </bean>

    四、创建controller

    @Controller
    @RequestMapping("/test")
    public class TestController {
    
        @RequestMapping("/hello")
        @ResponseBody
        public String hello(){
            String str = "Hello World 中国!!!";
            return str;
        }
    }

    五、测试

  • 相关阅读:
    hadoop面试时的一些问题解答
    FTRL(Follow The Regularized Leader)学习总结
    循环神经(LSTM)网络学习总结
    深度学习中常用的激活函数
    TF.learn学习
    TensorFlow实现分布式计算
    TensorFlow TensorBoard使用
    深度学习总结
    Spark SQL相关总结
    推荐系统/广告系统索引目录
  • 原文地址:https://www.cnblogs.com/wslook/p/9164729.html
Copyright © 2011-2022 走看看