Spring MVC的自身业务处理

2019-04-03  本文已影响0人  草珊瑚_6557

请求处理

1.请求捕获(url路由匹配,请求头匹配)
@RequestMapping("/")匹配http://xxx.com/请求
@RequestMapping("/hello")匹配http://xxx.com/hello请求

@RestController
@RequestMapping("/classPath")
public class Application {
    @RequestMapping("/methodPath")
    public String method() {
        return "mapping url is /classPath/methodPath";
    }
}

匹配http://xxx.com/classPath/methodPath请求

2.文件上传请求处理(multipart/form-data)

3.静态文件转发

响应

  1. 模板渲染
  2. json文本

拦截器Interceptor(请求处理前/处理后,响应后处理)

目的是减少重复代码。

数据模型绑定

数据绑定是指,把请求参数转化为数据模型(数据库某张表或其字段)。
然后把该模型作为请求处理的入参。

异常处理

出现异常后,比如url匹配不到,control层代码运行异常,数据库连接不上等等。
该返回的响应数据。

参考:
https://www.tianmaying.com/tutorial/spring-mvc-quickstart

上一篇 下一篇

猜你喜欢

热点阅读