SpringMVC学习笔记1_XML配置文件

本文详细介绍了SpringMVC框架的基本配置方法,包括web.xml中DispatcherServlet的设置、核心配置文件mvc-dispatcher-servlet.xml的内容解析,以及如何通过配置实现自动扫描Controller、消息转换、静态资源访问等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.web.xml中SpringMVC配置

/webapp/WEB-INF/web.xml

<!-- springMVC前置控制器的配置 --> 
 <servlet>
    <servlet-name>mvc-dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <!-- springMVC配置文件 --> 
   <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/config/mvc-dispatcher-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <!-- 拦截URL中包含[/]的请求 -->
 <servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

2.SpringMVC配置文件

/WEB-INF/config/mvc-dispatcher-servlet.xml

 <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> 
<!-- 自动扫描指定包里的controller类,如果扫描到的类中有Controller,RequestMapping等注解,则注册为bean -->
    <context:component-scan base-package="com.xxx.controller"/>
    <!-- Json类型的消息转换 -->
    <mvc:annotation-driven>
        <mvc:message-converters  register-defaults="true">
            <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/html;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
            <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
                <property name="objectMapper">
                    <bean class="com.xxx.util.CustomObjectMapper"/>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

    <!-- 静态资源的访问 -->
    <mvc:resources mapping="/images/**" location="/WEB-INF/images/"/>
    <mvc:resources mapping="/scripts/**" location="/WEB-INF/scripts/"/>
    <mvc:resources mapping="/resources/**" location="/WEB-INF/resources/"/>
    <mvc:resources mapping="/common/**" location="/WEB-INF/common/"/>

    <mvc:default-servlet-handler/>

    <!-- 视图解析ViewResolver -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/jsp/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

    <!-- 拦截器:拦截非法请求(不经过登录) -->
      <mvc:interceptors>
        <mvc:interceptor>
            <!-- 需拦截的地址 -->
            <!-- 一级目录 -->
            <mvc:mapping path="/*.do"/>
            <mvc:mapping path="/*.ajax"/>
            <mvc:mapping path="/*.htm"/>
            <mvc:mapping path="/*.html"/>
            <!-- 二级目录 -->
            <mvc:mapping path="/*/*.do"/>
            <mvc:mapping path="/*/*.ajax"/>
            <mvc:mapping path="/*/*.htm"/>
            <mvc:mapping path="/*/*.html"/>
            <!-- 三级目录 -->
            <mvc:mapping path="/*/*/*.do"/>
            <mvc:mapping path="/*/*/*.ajax"/>
            <mvc:mapping path="/*/*/*.htm"/>
            <mvc:mapping path="/*/*/*.html"/>
            <!-- 四级目录 -->
            <mvc:mapping path="/*/*/*/*.do"/>
            <mvc:mapping path="/*/*/*/*.ajax"/>
            <mvc:mapping path="/*/*/*/*.htm"/>
            <mvc:mapping path="/*/*/*/*.html"/>

            <!-- 需排除拦截的地址 -->
            <mvc:exclude-mapping path="/index.htm"/>
            <mvc:exclude-mapping path="/xxx/login.html"/>
            <mvc:exclude-mapping path="/xxx/notice.html"/>
            <mvc:exclude-mapping path="/xxx/default.html"/>
            <mvc:exclude-mapping path="/xxx/ana/login.ajax"/>
            <mvc:exclude-mapping path="/xxx/ana/logout.ajax"/>
            <bean class="com.xxx.interceptor.SessionCheckInterceptor"/>
        </mvc:interceptor>

        <mvc:interceptor>
            <!-- 需拦截的地址 -->
            <!-- 一级目录 -->
            <mvc:mapping path="/*.ajax"/>
            <!-- 二级目录 -->
            <mvc:mapping path="/*/*.ajax"/>
            <!-- 三级目录 -->
            <mvc:mapping path="/*/*/*.ajax"/>
            <!-- 四级目录 -->
            <mvc:mapping path="/*/*/*/*.ajax"/>
            <!-- 需排除拦截的地址 -->
            <mvc:exclude-mapping path="/xxx/origin/download_excel.ajax"/>
            <mvc:exclude-mapping path="/xxx/enterpriseHome/checkAuthentication.ajax"/>
            <mvc:exclude-mapping path="/xxx/ana/login.ajax"/>
            <bean class="com.xxx.interceptor.DemoInterceptor"/>
        </mvc:interceptor>
    </mvc:interceptors>
</beans>


内容概要:该论文探讨了一种基于粒子群优化(PSO)的STAR-RIS辅助NOMA无线通信网络优化方法。STAR-RIS作为一种新型可重构智能表面,能同时反射和传输信号,与传统仅能反射的RIS不同。结合NOMA技术,STAR-RIS可以提升覆盖范围、用户容量和频谱效率。针对STAR-RIS元素众多导致获取完整信道状态信息(CSI)开销大的问题,作者提出一种在不依赖完整CSI的情况下,联合优化功率分配、基站波束成形以及STAR-RIS的传输和反射波束成形向量的方法,以最大化总可实现速率并确保每个用户的最低速率要求。仿真结果显示,该方案优于STAR-RIS辅助的OMA系统。 适合人群:具备一定无线通信理论基础、对智能反射面技术和非正交多址接入技术感兴趣的科研人员和工程师。 使用场景及目标:①适用于希望深入了解STAR-RIS与NOMA结合的研究者;②为解决无线通信中频谱资源紧张、提高系统性能提供新的思路和技术手段;③帮助理解PSO算法在无线通信优化问题中的应用。 其他说明:文中提供了详细的Python代码实现,涵盖系统参数设置、信道建模、速率计算、目标函数定义、约束条件设定、主优化函数设计及结果可视化等环节,便于读者理解和复现实验结果。此外,文章还对比了PSO与其他优化算法(如DDPG)的区别,强调了PSO在不需要显式CSI估计方面的优势。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值