Ich möchte etwas HTML und CSS für mein Frühjahrsprojekt hinzufügen. Ich laufe groß und benutze Kotlin. Mein aktuelles Baumverzeichnis ist wie folgt: link (Ich habe keine GRADLE-Build-Dateien hinzugefügt).Integrieren von HTML und CSS mit Kotlin und Spring MVC
Ich versuche einfach "Hello $ name $" zu drucken, einige Eingaben an der Webadresse. Das funktioniert. Hier ist GreetingController.kt:
@RestController
class GreetingController {
@RequestMapping("/greeting")
fun greeting(@RequestParam(value = "name", defaultValue = "World") name: String, model: Model) {
model.addAttribute("name", name);
return "greeting";
}
}
Meine gradle.build Datei:
buildscript {
ext.kotlin_version = '1.1.2' // Required for Kotlin integration
ext.spring_boot_version = '1.5.3.RELEASE'
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath "se.transmode.gradle:gradle-docker:1.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // Required for Kotlin integration
classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version"
}
}
apply plugin: 'docker'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'kotlin' // Required for Kotlin integration
apply plugin: 'org.springframework.boot'
apply plugin: 'application'
jar {
baseName = 'webapp'
version = '0.1.0'
}
repositories {
jcenter()
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-thymeleaf"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // Required for Kotlin integration
compile 'org.springframework.boot:spring-boot-starter-web'
testCompile 'junit:junit'
}
task buildDocker(type: Docker, dependsOn: build) {
push = false
applicationName = jar.baseName
dockerfile = file('src/main/docker/Dockerfile')
doFirst {
copy {
from jar
into stageDir
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '3.5'
}
springBoot {
mainClass = 'com.tunnll.spring.webapp.Application'
}
Zusätzlich meine HTML-Datei:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'Hello, ' + ${name} + '!'" />
</body>
</html>
EDIT: Die Website läuft lokal, so kann ich nicht einen Link bereitstellen Momentan gibt es "Gruß" aus, was ich im GreetingController zurücksende. Allerdings möchte ich, dass es als "Hello World" angezeigt wird, was von der HTML-Datei erzeugt werden würde. Es kann ein Problem sein, dass die HTML-Datei nicht mit der Anwendung verbunden ist. Ich bin nicht sicher. Jede Hilfe wäre willkommen.
Ihr Website-Link verweist auf 'localhost'. – zsmb13
Ja, mein Schlechter. Hatte vergessen, es ist nur vor Ort verfügbar. Ich fügte eine Beschreibung dessen hinzu, was erscheint. Es ist sehr minimalistisch, also sollte es kein Problem sein. –