小编nlo*_*uit的帖子

未加载Springboot模板文件

我正在编写我的第一个springboot web应用程序,其项目结构如下:

---src/main/java
           +com.example.myproject
                                +--Application.java
           +com.example.myproject.domain
                                +--Person.java
           +com.example.myproject.web
                                +--GreetingController.java
---src/main/resources
           +static
                 +--css
                 +--js
           +templates
                 +--greeting.html 
Run Code Online (Sandbox Code Playgroud)

Aplication.java

package com.example.myproject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(Application.class);
        app.setShowBanner(false);
        app.run(args);
    }
}
Run Code Online (Sandbox Code Playgroud)

GreetingController.java

package com.example.myproject.web;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class GreetingController {

    @RequestMapping("/greeting")
    public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
        model.addAttribute("name", name);
        return "greeting";
    }
}
Run Code Online (Sandbox Code Playgroud)

greeting.html

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org"> …
Run Code Online (Sandbox Code Playgroud)

java templates thymeleaf spring-boot

5
推荐指数
1
解决办法
1777
查看次数

标签 统计

java ×1

spring-boot ×1

templates ×1

thymeleaf ×1