oyhk学习笔记
springMvc 三种接收客户端参数方法
首先是前端:发送请求方式:两种 暂时只是(post方式哦..)
表单方式:
<form> title:<input type="text" name="title"/> content:<input type="text" name="content"/> <input type="submit" value="提交"/> </form>
异步方式:
function saveBlogComment(postsId,userId,userNick) { $.ajax({ type : "POST", url : '/posts/save', data : { title: "这里是标题", content :"这里是内容" }, success : function(data, textStatus, jqXHR) { alert("异步方法提交") }, dataType : "json" }); }
服务端的springMvc 三种方式
第一种:
public void saveComment(Posts posts) {
}
你可以用debug方式去看看对象里面是否有值了..
博客类是以下
public class Posts{
private String id;
private String title;
private String content;
下面是set/get
}
第二种
public void saveComment(String title,String content) {
}
第三种
public void saveComment(@RequestParam("title") String title,@RequestParam("content")String content) {
}
希望对大家有帮助...