I will explain how to build an MVC structure on Scala's ultra-lightweight framework "Scalatra". ** Not only Scalatra, Scala has too few articles **.
As you can see from the tag, it is ** 8 ** only for Scalatra.
It's difficult to get started because it's overwhelmingly small ... Because of that, I usually write Swift, Go, Python, Ruby, but Scala is very interesting, but there is little literature. So this time I will start by building MVC so that I can develop web applications.
I usually develop with "full stack framework" such as Rails, Django, Gin, but I don't have much freedom to say MVC structure. Rails is so black-boxed that I don't feel like I'm doing experiential programming.
This article covers the following:
--Those who have already built with bst
etc.
Is targeted at.
There may be slight differences, but the directory structure should look like this:
src
├── main
│ ├── java
│ ├── resources
│ │ └── logback.xml
│ ├── scala
│ │ ├── ScalatraBootstrap.scala
│ │ └── com
│ │ └── example
│ │ └── app
│ │ └── ScalaServlet.scala
│ └── webapp
│ └── WEB-INF
│ └── web.xml
└── test
├── java
├── scala
│ └── com
│ └── example
│ └── app
│ └── MyScalatraServletTests.scala
└── scala-2.12
As a beginner, I didn't know where to put what, but I thought of the Go package. Package is okay if you remember it as a namespace.
In other words, if you want to make it MVC, you can separate it with a package, and the next question is ** how can you explicitly build MVC while maintaining transparency **.
Of course, it may be better to build it under app. Extract the directory tree from earlier and change it as follows.
src
├── main
│ ├── java
│ ├── resources
│ │ └── logback.xml
│ ├── scala
│ │ ├── ScalatraBootstrap.scala
│ │ └── com
│ │ └── example
│ │ └── app
│ │ └── ScalaServlet.scala
│ │ └── view
│ │ └── controller
│ │ └── model
│ └── webapp
│ └── WEB-INF
│ └── web.xml
└── test
It is recommended to build MVC around ScalaServlet.scala
because it is highly transparent and easy to develop.
Recommended Posts