本文基于:
Eclipse下利用Maven创建SpringBoot的Restful风格程序
在Tomcat目录的SpringBoot项目中,将index.jsp文件修改为
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>my rest api</title> 6 <script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"> 7 </script> 8 <script> 9 $(document).ready(function(){ 10 $("button").click(function(){ 11 $("#div1").load("greeting?name=wangle"); 12 }); 13 }); 14 </script> 15 </head> 16 <body> 17 18 <div id="div1"><h2>use jQuery AJAX change content</h2></div> 19 <button>outside content</button> 20 21 </body> 22 </html>
其中11行 "greeting?name=wangle" 为rest api的url
结果:
可获取到Rest API传过来的Json数据并在界面上显示