首页  

play scala hello world tutorial     所属分类 play 浏览量 201
play-scala-hello-world-tutorial
增加一个带入参 name的页面
http://127.0.0.1:9200/hello?name=dog

Create a new page
Add an action method
Define a route
Customize the greeting


项目导入 idea , 如果出现 找不到 xxx ,可以 sbt 编译下
sbt compile
sbt clean compile

增加模板 hello.scala.html  不会自动编译
直接命令行 sbt 先编译下 

模板 编译生成
/target/scala-2.13/twirl/main/views/html/hello.template.scala

sbt run -Dhttp.port=9200
默认端口 9000

/app/controllers/HomeController.scala

/app/views/hello.scala.html
/conf/routes

GET    /hello    controllers.HomeController.hello(name:String)



@Singleton class HomeController @Inject()(cc: ControllerComponents) extends AbstractController(cc) { def index() = Action { implicit request: Request[AnyContent] => Ok(views.html.index()) } def explore() = Action { implicit request: Request[AnyContent] => Ok(views.html.explore()) } def tutorial() = Action { implicit request: Request[AnyContent] => Ok(views.html.tutorial()) } def hello(name: String) = Action { Ok(views.html.hello(name)) } }
@(name: String) @main("Hello") { <section id="content"> <div class="wrapper doc"> <article> <h1>Hello @name!</h1> </article> <aside> @commonSidebar() </aside> </div> </section> }
完整代码 https://gitee.com/dyyx/hellocode/tree/master/demo/scala/play-scala-hello-world-tutorial
play REST hello 实例

上一篇     下一篇
mac mvn 编译 找不到JDK

Scala map与flatMap

Scala 集合操作

Scala 下划线的用途

scala 匿名函数

scala函数定义及使用