zoukankan      html  css  js  c++  java
  • SpringMVC的依赖和视图解析器配置

    1、SpingMVC的pom.xml依赖

    <build>
            <resources>
                <resource>
                    <directory>src/main/java</directory>
                    <includes>
                        <include>**/*.properties</include>
                        <include>**/*.xml</include>
                    </includes>
                    <filtering>false</filtering>
                </resource>
                <resource>
                    <directory>src/main/resources</directory>
                    <includes>
                        <include>**/*.properties</include>
                        <include>**/*.xml</include>
                    </includes>
                    <filtering>false</filtering>
                </resource>
            </resources>
        </build>
    
    
    <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>5.2.7.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>2.5</version>
            </dependency>
            <dependency>
                <groupId>javax.servlet.jsp</groupId>
                <artifactId>jsp-api</artifactId>
                <version>2.2.1-b03</version>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jstl</artifactId>
                <version>1.2</version>
            </dependency>
        </dependencies>

    2、视图解析器的配置

    <?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
           https://www.springframework.org/schema/context/spring-mvc.xsd
           http://www.springframework.org/schema/mvc
           https://www.springframework.org/schema/mvc/spring-mvc.xsd">
        <!--自动扫面包,让注解生效,由IOC容器统一管理-->
        <context:component-scan base-package="com.meng.controller"/>
        <!--让springMVC不处理静态资源-->
        <mvc:default-servlet-handler/>
        <mvc:annotation-driven></mvc:annotation-driven>
    
        <!--视图解析器的配置-->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/jsp/"></property>
            <property name="suffix" value=".jsp"></property>
        </bean>
    </beans>

    3、controller层

    @Controller
    public class HelloController {
    
        @RequestMapping("/hello")
        public String hello(Model model){
            //封装数据
            model.addAttribute("msg","Hello,springMVC!!!!!!!!!!");
            return "hello";//返回视图解析器处理
        }
    }
  • 相关阅读:
    Win10 JDK 配置
    Java Selenium
    Java Selenium
    Eclipse配置Github -分享你的代码
    TestNG-详解preserve-order的作用与测试case的执行顺序
    Java
    VirtualBox 在Win10上的蓝屏问题
    SQL _ Create Procedure
    LINQ 学习路程 -- 查询语法 LINQ Query Syntax
    LINQ 学习路程 -- 开篇
  • 原文地址:https://www.cnblogs.com/Meng2113/p/13470074.html
Copyright © 2011-2022 走看看