Web项目中spring+springMVC的相关配置总结

1. spring + spring mvc

web项目中:
spring: applicationContext.xml (IOC配置 AOP配置 数据源配置 事务管理器配置 等等)=>src目录
web项目怎么加载 applicationContext.xml:
web.xml: 

<!-- needed for ContextLoaderListener -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

    <!-- Bootstraps the root web application context before servlet initialization -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    
-------------------------    
spring mvc:
springmvc.xml: (springmvc-servlet.xml)
配置了视图解析器,控制器的扫描包,静态资源过滤处理,文件上传下载配置
web项目怎么加载 springmvc.xml:
web.xml

<!-- The front controller of this Spring Web application, responsible for 
        handling all application requests -->
    <servlet>
        <servlet-name>springDispatcherServlet</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>

    <!-- Map all requests to the DispatcherServlet for handling -->
    <servlet-mapping>
        <servlet-name>springDispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
-------------------------------------------------------
Rest风格(restful):
查询: get    api/user/{userid}  /api/user
增加:post     /api/user
修改:put      /api/user/{userid}
删除:delete    /api/user/{userid}    /  /api/user

------------------------------------------------------
测试:
dao/service/:    junit测试  spring+junit
controller:      可以用postman(建议升级到最新版,否则可能有bug),后续还有介绍

------------------------------------------------------
@GetMapping  @RequestMapping  
@GetMapping  ==  @RequestMapping(method = RequestMethod.GET)
@RestController ==@Controller + @ResponseBody


 


    
    
    
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值