zoukankan      html  css  js  c++  java
  • SpringMVC入门

    引入需要的jar包

    在Web.xml配置文件中添加关于SpringMVC的配置

    <servlet>
          <servlet-name>springmvc</servlet-name>
          <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- 不配置此处的话,默认为WEB-INF目录下,名称为[<servlet-name>]-servlet.xml,如spring-servlet.xml-->
        <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>classpath:springmvc.xml</param-value>
          </init-param>
            <!-- <load-on-startup>1</load-on-startup> -->
      </servlet>
    
      <servlet-mapping>
          <servlet-name>springmvc</servlet-name>
          <url-pattern>/</url-pattern>
      </servlet-mapping>
    

      

    在src下添加springmvc.xml配置文件

    <?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: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-4.1.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">                    
    
        <!-- scan the package and the sub package -->
        <context:component-scan base-package="test.SpringMVC"/>
    
        <!-- don't handle the static resource -->
        <mvc:default-servlet-handler />
    
        <!-- if you use annotation you must configure following setting -->
        <mvc:annotation-driven />
        
        <!-- configure the InternalResourceViewResolver -->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
                id="internalResourceViewResolver">
            <!-- 前缀 -->
            <property name="prefix" value="/WEB-INF/jsp/" />
            <!-- 后缀 -->
            <property name="suffix" value=".jsp" />
        </bean>
    </beans>
    

    在WEB-INF文件夹下创建名为jsp的文件夹,用来存放jsp视图。创建一个hello.jsp,在body中添加“Hello World”。

    编写Controller

    @Controller
    @RequestMapping("/mvc")
    public class mvcController {
    
        @RequestMapping("/hello")
        public String hello(){        
            return "hello";
        }
    }
    

    详尽信息请参考:

    https://www.cnblogs.com/sunniest/p/4555801.html

  • 相关阅读:
    python列表
    Apache ab压力测试
    nmon监控与 nmon analyser分析
    一些有用的cocos2d-x,box2d等网址链接
    手把手教你实现物理碰撞的网络同步
    cocos2dx-lua使用UIListView制作二级折叠菜单
    【Cocos2d-x游戏开发】Cocos2d-x中的弱联网技术
    Java游戏服务器成长之路——弱联网游戏篇(源码分析)
    在浏览器上实现自动引导(五)
    使用Cocos2d-JS制作游戏新手引导(四)应用篇
  • 原文地址:https://www.cnblogs.com/xiaoQ0725/p/8066653.html
Copyright © 2011-2022 走看看