SPRING MVC3.2案例讲解--SPRING MVC3的各种URL映射(1)

SPRING MVC3 提供了各种映射方式,除了传统的URL方式如(/save?name=value);

又有restful风格的url : /books/1 各种方式任君选择!

 

本章节内容讲解的代码内容如图:

  1.  SIMPLE标签页对应的代码如下:

<li><a href="#simple">Simple</a></li>

 

<a id="simpleLink" class="textLink" href="/simple">GET /simple</a>

 

<a id="simpleRevisited" class="textLink" href="/simple/revisited">GET /simple/revisited</a>

 

$("a.textLink").click(function(){

var link = $(this);

$.ajax({ url: link.attr("href"), dataType: "text", success: function(text) { MvcUtil.showSuccessResponse(text, link); }, error: function(xhr) { MvcUtil.showErrorResponse(xhr.responseText, link); }});

return false;

});

 

注意一点:这边的@ResponseBody直接返回内容,而不是转向某个视图(jsp页面);

http://127.0.0.1:8010/simple

@Controller

public class SimpleController {

 

@RequestMapping("/simple")

public @ResponseBody String simple() {

return "Hello world!";

}

 

}

 

http://127.0.0.1:8010//simple/revisited

@Controller

public class SimpleControllerRevisited {

 

@RequestMapping(value="/simple/revisited", method=RequestMethod.GET, headers="Accept=text/plain")

public @ResponseBody String simple() {

return "Hello world revisited!";

}

 

}

 

 

 

打个标记:晚上继续request mapping的相关代码:

$("#byHeader").click(function(){

var link = $(this);

$.ajax({ url: this.href, dataType: "text", beforeSend: function(req) { req.setRequestHeader("FooHeader", "foo"); }, success: function(form) { MvcUtil.showSuccessResponse(form, link); }, error: function(xhr) { MvcUtil.showErrorResponse(xhr.responseText, link); }});

return false;

});

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值