一 第一步,实现hello world ,加载静态资源。

77 阅读1分钟

一创建项目 。

新建一个springboot 项目 ,选中 springweb . image.png

二 跑一个hello world

package com.demo.helloworld.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @GetMapping("/hello")
    public String hello()
    {
        return "hello world";
    }
}

image.png

三 访问静态资源。

方法1 ,安装webjars.

自己的文件。 resource > static > public

image.png

注意 静态文件也要编译后才能访问。

四 来个控制器,加载视图。

创项目时,需要勾选模版引擎 .(thymeleaf)

package com.xuxing.study2;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class IndexController {

    @RequestMapping("/index")
    public String index()
    {
        return "index";
    }

}

image.png