@RequestParam注解
顾名思义:获取参数,即是获取传送过来的参数;
举例:
举例:
// http://localhost:8090/hello?id=2
public String Demo1(@RequestParam String id){...}
defaultValue设置初始化值,required = false代表可以为空
@RequestParam(defaultValue = "", required = false) String mypostion
@PathVariable注解
顾名思义:路径变量,即是获取链接路径上的变量;
function todetail(topId) {
window.location.href = "/notice/getNoticeme" + topId;
}
@RequestMapping("/getNoticeme{noticeId}")
public ModelAndView getNoticeme(@PathVariable("noticeId") String noticeId)
@RequestBody注解
@RequestBody注解一般主要是用来处理content-type:"application/json charset=utf-8"或者content-type:"application/xml charset=utf-8"两种请求数据,一般是异步请求用的比较多些;
$.ajax({
type : "post",
url : "/notice/commentnotice",
contentType : "application/json; charset=utf-8",
dataType : "json",
data :JSON.stringify(str),
success : function(data) {
window.location.href = "/notice/getNotice" + data.oneDate.notice.id + "?mypostion="+data.oneDate.parent_id.id;
}
});
@ResponseBody
@RequestMapping("/commentnotice")
public ReturnData commentNotice(@RequestBody Notice_Reply notice_Reply){...}