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

SpringMVC环境搭建之Idea

时间:2019-01-11 23:13:39      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:包含   ref   code   ini   重要   ota   idea   att   结果   

SpringMVC
.. SpringMVC重要组件介绍
    1. DispacherServlet:前端控制器,接收所有请求,(如果配置/不包含jsp)
    2. HandlerMapping:解析请求格式,判断希望要执行哪个方法
    3. HandlerAdapter:负责调用具体的方法
    4. ViewResovler:视图解析器,解析结果,准备跳转的具体的视图

spring的jar包官方下载地址:

https://repo.spring.io/libs-release-local/org/springframework/spring/
环境搭建
    1.导入jar包
    2.在web.xml中配置前端控制器,若不配置<init-param>,会去/web-inf/<servlet-name>servlet.xml找
<servlet>
<servlet-name>qq</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<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>qq</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
  3.src下面新建springmvc.xml
   3.1.引入命名空间
<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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">

<!--扫描注解-->
<context:component-scan base-package="com.bj.controller"></context:component-scan>
<!--注解驱动-->
<mvc:annotation-driven></mvc:annotation-driven>
<!--放行静态资源两个*号表示文件夹下所有文件-->
<mvc:resources mapping="/js/**" location="/js/"></mvc:resources>
<mvc:resources mapping="/css/**" location="/css/"></mvc:resources>
<mvc:resources mapping="/imgs/**" location="/imgs/"></mvc:resources>
</beans>
3.2.编写控制器类

1 @Controller
2 public class Democontroller {
3 @RequestMapping("demo")
4      public String demo(){
5         return "main.jsp";
6     }
7 
8 }

 




SpringMVC环境搭建之Idea

标签:包含   ref   code   ini   重要   ota   idea   att   结果   

原文地址:https://www.cnblogs.com/code-coffee/p/10257644.html

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