本文基於:
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數據並在界面上顯示
