表单方式:
Js代码
<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 三种方式
第一种:
Java代码
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) { }
希望对大家有帮助...
本文章来自: http://blog.mkfree.com/posts/510d0c51975ad0eb7d135971