跟我学Spring Boot(二)Hello World

1、打开DemoApplication添加如下代码

package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller //1
@SpringBootApplication
public class DemoApplication {

    //2
    @RequestMapping("/helloboot")
    public String helloBoot(Model model){
        return "index";
    }
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

 

2、在resources/template/目录下新建index.html

代码如下

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>Title</title>
</head>
<body>
hello world
</body>
</html>

 

这里需要注意的是meta 部分一定要有结束符不然后提示下面错误

org.xml.sax.SAXParseException: 元素类型 "meta" 必须由匹配的结束标记 "</meta>" 终止。

 

posted on 2016-12-11 15:43  lvlv岁月流逝  阅读(276)  评论(0编辑  收藏  举报

导航