Spring Boot非常适合Web应用程序开发。 我们可以使用嵌入式Tomcat,Jetty或Undertow轻松创建自包含的HTTP服务器。 大多数Web应用程序将使用spring-boot-starter-web模块快速启动和运行。
在SpringBoot中使用mvc与springmvc基本一致,我们甚至可以按照springmvc中的标准来完成控制器的实现。
代码示例:
package com.bdqn.lyrk.study.springboot.controller; import lombok.AllArgsConstructor; import lombok.Data; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; /** * @author chen.nie */ @Controller @RequestMapping("/index") public class IndexController { @GetMapping("/index") public String index() { return "index"; } @GetMapping("/number/{number}/Desc/{desc}") @ResponseBody public BeanEntity bean(@PathVariable ("number") int number, @PathVariable("desc") String desc) { return new BeanEntity(number,desc); } } @Data @AllArgsConstructor class BeanEntity { private int number; private String desc; }