<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">1、前台脚本</span>
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"></span><pre name="code" class="javascript"><script type="text/javascript">
$(document).ready(function(){
$(".wulin").click(function(){
$.ajax({
type: "post",
url: "<%=path%>/test/getUser.do?userId=4",
success: function (result) {
alert(result.username);
}
});
});
})
</script>
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">2、</span><span style="color: rgb(68, 68, 68); font-family: "Hiragino Sans GB", "Microsoft YaHei", 微软雅黑, tahoma, arial, simsun, 宋体; font-size: 14px; background-color: rgb(237, 237, 239);">后台利用springmvc,采用注解方式实现</span>
@ResponseBody
@RequestMapping(value="getUser",method = RequestMethod.POST)
public User getUser(Integer userId, HttpServletRequest request, HttpServletResponse response){
try {
return userService.getUser(userId);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}