This guide show you how to use GSP as view templates with Spring Boot.
- Grace Framework 2022.2.4
Adding grace-plugin-gsp
plugin to the build.gradle
,
dependencies {
implementation 'org.graceframework:grace-boot'
implementation 'org.graceframework:grace-core'
implementation 'org.graceframework:grace-plugin-core'
implementation 'org.graceframework:grace-plugin-i18n'
implementation 'org.graceframework:grace-plugin-gsp'
}
Creating a Tag in app/taglib
,
class GreetingTagLib {
GrailsApplication grailsApplication
def welcome = { args, body ->
out << "Welcome to Grace " << grailsApplication.metadata.getGrailsVersion()
}
}
Now we can use this tag in the GSP app/views/greeting/index.gsp
,
<!DOCTYPE HTML>
<html>
<head>
<title>Spring Boot with GSP</title>
<meta name="layout" content="main"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1><g:welcome/></h1>
Hello, <b>${name}</b>
</body>
</html>
./gradlew bootRun
then open your browser, http://localhost:8080/greeting