Spring-MVC开发依赖以及配置和对应的配置解析------Spring-MVC框架

131 篇文章 0 订阅
11 篇文章 0 订阅
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
         version="6.0">
<!--    我们的DispatcherServlet起到的作用是-->
<!--    处理用户的HTTP请求,解析URL为Request对象-->
<!--    处理URL将URL与程序匹配,调用对应的Controller来处理-->
<!--    调用相应的控制器,将请求分发到找到的控制器处理,控制器将执行业务逻辑,返回模型对象-->
<!--    渲染视图,把模型转为用户可以查看的HTML代码-->
<!--    返回响应给客户端,可以是表单,JSON,XML,HTML等-->
    <servlet>
        <servlet-name>springMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>springMVC</servlet-name>
<!--        除了.JSP剩下所有的请求都到这里-->
<!--        因为jsp本身是一个Servlet,所以他不走前端控制器-->
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
         version="6.0">
<!--    我们的DispatcherServlet起到的作用是-->
<!--    处理用户的HTTP请求,解析URL为Request对象-->
<!--    处理URL将URL与程序匹配,调用对应的Controller来处理-->
<!--    调用相应的控制器,将请求分发到找到的控制器处理,控制器将执行业务逻辑,返回模型对象-->
<!--    渲染视图,把模型转为用户可以查看的HTML代码-->
<!--    返回响应给客户端,可以是表单,JSON,XML,HTML等-->
    <servlet>
        <servlet-name>springMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>springMVC</servlet-name>
<!--        除了.JSP剩下所有的请求都到这里-->
<!--        因为jsp本身是一个Servlet,所以他不走前端控制器-->
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.alatus</groupId>
    <artifactId>mvc1</artifactId>
    <version>1.0-SNAPSHOT</version>
<!--    这个要给tomcat跑,他没有自带tomcat,要打包为war才行-->
    <packaging>war</packaging>
    <dependencies>
<!--        springmvc依赖-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>6.1.4</version>
        </dependency>
<!--        servlet依赖也是需要的-->
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <version>6.0.0</version>
<!--            等一下有tomcat,用不着咯-->
            <scope>provided</scope>
        </dependency>
<!--        logback日志-->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.5.3</version>
        </dependency>
<!--        thymeleaf依赖-->
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf-spring6</artifactId>
            <version>3.1.2.RELEASE</version>
        </dependency>
    </dependencies>
    <properties>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.alatus</groupId>
    <artifactId>mvc1</artifactId>
    <version>1.0-SNAPSHOT</version>
<!--    这个要给tomcat跑,他没有自带tomcat,要打包为war才行-->
    <packaging>war</packaging>
    <dependencies>
<!--        springmvc依赖-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>6.1.4</version>
        </dependency>
<!--        servlet依赖也是需要的-->
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <version>6.0.0</version>
<!--            等一下有tomcat,用不着咯-->
            <scope>provided</scope>
        </dependency>
<!--        logback日志-->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.5.3</version>
        </dependency>
<!--        thymeleaf依赖-->
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf-spring6</artifactId>
            <version>3.1.2.RELEASE</version>
        </dependency>
    </dependencies>
    <properties>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>
<?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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--    配置编写mvc的配置文件-->
<!--    搞个组件扫描-->
    <context:component-scan base-package="com.alatus.testmvc.controller"/>
<!--    配置视图解析器-->
<!--    JSP的视图解析器是InternalResourceViewResolver-->
<!--    FreeMarker视图解析器是FreeMarkerViewResolver-->
<!--    Velocity视图解析器是VelocityViewResolver-->
    <bean id="thymeleafViewResolver" class="org.thymeleaf.spring6.view.ThymeleafViewResolver">
<!--        设个字符集-->
        <property name="characterEncoding" value="UTF-8"/>
<!--        设置优先级(多个视图解析器必选)-->
        <property name="order" value="1"/>
<!--        渲染时模板解析器的引擎-->
        <property name="templateEngine">
            <bean class="org.thymeleaf.spring6.templateresolver.SpringResourceTemplateResolver">
<!--                设置模板文件的位置-->
                <property name="prefix" value="/WEB-INF/templates/"/>
<!--                设置模板文件后缀-->
                <property name="suffix" value=".html"/>
<!--                设置模板类型,可以是HTML/CSS/JS等-->
                <property name="templateMode" value="HTML"/>
<!--                设置模板读取的编码级-->
                <property name="characterEncoding" value="UTF-8"/>
            </bean>
        </property>
    </bean>
</beans>
<?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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--    配置编写mvc的配置文件-->
<!--    搞个组件扫描-->
    <context:component-scan base-package="com.alatus.testmvc.controller"/>
<!--    配置视图解析器-->
<!--    JSP的视图解析器是InternalResourceViewResolver-->
<!--    FreeMarker视图解析器是FreeMarkerViewResolver-->
<!--    Velocity视图解析器是VelocityViewResolver-->
    <bean id="thymeleafViewResolver" class="org.thymeleaf.spring6.view.ThymeleafViewResolver">
<!--        设个字符集-->
        <property name="characterEncoding" value="UTF-8"/>
<!--        设置优先级(多个视图解析器必选)-->
        <property name="order" value="1"/>
<!--        渲染时模板解析器的引擎-->
        <property name="templateEngine">
            <bean class="org.thymeleaf.spring6.templateresolver.SpringResourceTemplateResolver">
<!--                设置模板文件的位置-->
                <property name="prefix" value="/WEB-INF/templates/"/>
<!--                设置模板文件后缀-->
                <property name="suffix" value=".html"/>
<!--                设置模板类型,可以是HTML/CSS/JS等-->
                <property name="templateMode" value="HTML"/>
<!--                设置模板读取的编码级-->
                <property name="characterEncoding" value="UTF-8"/>
            </bean>
        </property>
    </bean>
</beans>
  • 10
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值