[JAVA] [Introduction] Build MVC with Scala

Introduction

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.

image.png

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.

needs

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.

Premise

This article covers the following:

--Those who have already built with bst etc.

Is targeted at.

Directory structure

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

[Introduction] Build MVC with Scala
Build Doma1 with Ant
Build Java with Wercker
Build bazel with alpine
Build GitLab / Mattermost with DockerForWindows
Java Config with Spring MVC
Build softether VPN with Centos7.
Build a "Spring Thorough Introduction" development environment with IntelliJ IDEA
Build docker environment with WSL
Build Ubuntu 18.04.5 with dual boot
Ninja-build with smart differential build
Build AWS Lambda with Quarkus
Easy library introduction with Maven!
Build DynamoDB local with Docker
[Java, Scala] Image resizing with ImageIO
Build a Java project with Gradle
Build a Node.js environment with Docker
100% Pure Java BDD with JGiven (Introduction)
Build a Tomcat 8.5 environment with Pleiades 4.8
Folder compression with Scala. Using java.util.zip.ZipOutputStream.
Build PlantUML environment with VSCode + Docker
Build environment with vue.js + rails + docker
Use JDBC with Java and Scala.
Introduction to algorithms with java-Shakutori method
Build Rails environment with Docker Compose
Implement file download with Spring MVC
Java build with mac vs code
Build jooby development environment with Eclipse
Cloud Dataflow template created with Scala
Build docker + laravel environment with laradock
Build WebRTC Janus with Docker container
Spring Boot gradle build with Docker