如何將URL中的數據傳遞給控制器

1.在views下創建名爲Home的包,在包中新建Play 2 Template名爲welcome
2.引包:
import views.html.index;
import views.html.Home.*;
3.在welcome中:
@(name:String,lastname:String)
<html>
<head>
<title>my welcome page</title>
</head>
<body>
<p>Welcome @name @lastname To our website</p>
</body>
</html>
4.在HomeController中定義方法:
public Result welcome(String name, String lastname) {
return ok(welcome.render(name, lastname));
}
效果:在網頁上輸入localhost:9000/welcome/:xxx/xx得到響應(xxx爲任意輸入名稱)都可以顯示

發佈了132 篇原創文章 · 獲贊 35 · 訪問量 13萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章