第二节:Spring MVC

SpringMVC 的帮助文档中有这样一段话:注意以下加粗变色的位置

A key principle of REST is the use of the Uniform Interface. This means that all resources (URLs) can be manipulated using the same four HTTP methods: GET, PUT, POST, and DELETE. For each method, the HTTP specification defines the exact semantics. For instance, a GET should always be a safe operation, meaning that is has no side effects, and a PUT or DELETE should be idempotent, meaning that you can repeat these operations over and over again, but the end result should be the same. While HTTP defines these four methods, HTML only supports two: GET and POST. Fortunately, there are two possible workarounds: you can either use JavaScript to do your PUT or DELETE, or simply do a POST with the 'real' method as an additional parameter (modeled as a hidden input field in an HTML form). This latter trick is what Spring’s HiddenHttpMethodFilter does. This filter is a plain Servlet Filter and therefore it can be used in combination with any web framework (not just Spring MVC). Simply add this filter to your web.xml, and a POST with a hidden _method parameter will be converted into the corresponding HTTP method request.


当表单提交为put或者delete请求时,正常情况下都会自动变成post请求,所以为了使用put或者delete,我们需要添加以下配置。


132700_XpI2_2319558.jpg

传递参数,注意name的对应,默认情况下required为true,但是当我们传递的数据为空时,便会出现错误,所以我们需要将默认值设置为false

当传递的是两个数据时,我们将传递的参数的名称设置和要传递的值一样也就是需要传递的参数是id那么接收方也要设置成id呼应,这样就省去了@RequestParam的一系列的步骤。

132700_Lc2y_2319558.jpg

132700_LqIw_2319558.jpg



传递对象时,当表单中的属性对应类中的属性时,会自动完成转换

132700_A7Nh_2319558.jpg




转载于:https://my.oschina.net/courage123/blog/652277

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值