码迷,mamicode.com
首页 > 编程语言 > 详细

Spring MVC的配置

时间:2018-06-10 23:03:10      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:img   framework   图片   page   context   ima   ase   image   class   

一、添加依赖

<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;
    }
}

五、测试

技术分享图片

 

Spring MVC的配置

标签:img   framework   图片   page   context   ima   ase   image   class   

原文地址:https://www.cnblogs.com/wslook/p/9164729.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!