springMVC环境搭建

一、导入相关依赖

spring-webmvc:这个依赖还需要spring的支持,但在maven里面导入后,他运行所需要的其他依赖maven会自动给我们导入

		<dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-webmvcartifactId>
            <version>5.3.1version>
        dependency>

这是整合Thymeleaf所需要的依赖,如果不用可以不加,不影响使用

        <dependency>
            <groupId>org.thymeleafgroupId>
            <artifactId>thymeleaf-spring5artifactId>
            <version>3.0.11.RELEASEversion>
        dependency>

二、配置web.xml

<servlet>
        <servlet-name>springMVCservlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
        
        <init-param>
            <param-name>contextConfigLocationparam-name>
            <param-value>classpath:springMVC01.xmlparam-value>
        init-param>
        
        <load-on-startup>1load-on-startup>
    servlet>
    <servlet-mapping>
        <servlet-name>springMVCservlet-name>
        
        <url-pattern>/url-pattern>
    servlet-mapping>

三、配置springMVC.xml


    <context:component-scan base-package="com.libo.controller">context:component-scan>
    
    <mvc:view-controller path="/index" view-name="index">mvc:view-controller>
    
    <mvc:annotation-driven/>

    
    <bean id="viewResolver" class="org.thymeleaf.spring5.view.ThymeleafViewResolver">
        <property name="order" value="1">property>
        <property name="characterEncoding" value="utf-8">property>
        <property name="templateEngine">
            <bean class="org.thymeleaf.spring5.SpringTemplateEngine">
                <property name="templateResolver">
                    <bean class="org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver">
                        <property name="prefix" value="/WEB-INF/templates/">property>
                        <property name="suffix" value=".html">property>
                        <property name="templateMode" value="HTML5">property>
                        <property name="characterEncoding" value="UTF-8">property>
                    bean>
                property>
            bean>
        property>
    bean>

以上就是springmvc最基本的环境搭建,现在就可以使用了

你可能感兴趣的:(springMVC学习,mvc,spring)