This autoconfiguration purpose is to wrap scala objects to Freemarker TemplateModel's. Following scala types are supported:
- arrays
- iterables
- iterators
- maps
- sequences
- Options
- Booleans
Given the following class
class User {
val id = 100500
var name: String = ""
def sayHi(): String = s"Hi, $name"
def sayHi(n: String): String = s"Hi, $n"
def sayHi(n: String, i: Int): String = s"Hi, $n $i"
def getName: String = name
def setName(name: String): Unit = this.name = name
}
it allows you to access Users's methods and properties like this:
${user.id}
${user.getId()}
${user.name}
${user.getName()}
${user.sayHi()}
${user.sayHi("Bob")}
${user.sayHi("Bill", 100)}
-
Add dependency to your Maven
<dependency> <groupId>com.github.anadea</groupId> <artifactId>freemarker-scala-spring-boot-autoconfigure</artifactId> <version>1.1-RELEASE</version> </dependency>
or Gradle
compile group: 'com.github.anadea', name: 'freemarker-scala-spring-boot-autoconfigure', version: '1.1-RELEASE'
-
Add following key to application.properties:
freemarker.use_scala_wrapper = true
or application.yml
freemarker.use_scala_wrapper: true
Build command:
./gradlew build
Deploy command:
./gradlew uploadArchives