一个简单的spring boot 小例子

一个简单的spring boot 小例子_第1张图片一个简单的spring boot 小例子_第2张图片

注意  这里的版本要是1.5.15的

一个简单的spring boot 小例子_第3张图片一个简单的spring boot 小例子_第4张图片

Application代码


@SpringBootApplication
@ComponentScan("com.example.demo1.controller")
public class Demo1Application {

   public static void main(String[] args) {
      SpringApplication.run(Demo1Application.class, args);
   }
}

Controller代码

方法一:ModelAndView

@Controller
@EnableAutoConfiguration
public class HelloController {

    @RequestMapping("/hello")

    @ResponseBody
    public ModelAndView hello(){
        System.out.println("hello!");
        ModelAndView mode = new ModelAndView();
        mode.setViewName("hello");
        return mode;
    }
}

方法二:String

@Controller
@EnableAutoConfiguration
public class HelloController {

    @RequestMapping("/hello")

    public String hello() {
        System.out.println("进入controller");
        return "hello";
    }
} 

html代码

html>
lang="en">

    charset="UTF-8"/>
    </span>Hello<span style="color:#e8bf6a;">


hello,java!

properties文件

spring.mvc.view.prefix=/
spring.mvc.view.suffix=.html

pom文件配置

加上这两段



   org.springframework
   springloaded
   1.2.6.RELEASE
   provided



   org.springframework.boot
   spring-boot-starter-thymeleaf

输入http://localhost:8080/hello

执行结果

一个简单的spring boot 小例子_第5张图片

你可能感兴趣的:(spring,boot)