美文网首页
SpringBoot | 跟随官网的脚步 | 110: URL

SpringBoot | 跟随官网的脚步 | 110: URL

作者: 码农学禅 | 来源:发表于2018-09-11 15:10 被阅读0次

    目标

    这次前进一小步,对localhost:8080/ 能够响应Hello World。

    要点

    @RestController、@RequestMapping

    代码

    import org.springframework.boot.*;

    import org.springframework.boot.autoconfigure.*;

    import org.springframework.web.bind.annotation.*; //new in 110

    @RestController //new in 110

    @EnableAutoConfiguration

    public class example {

        @RequestMapping("/")

        String home(){

        return "Hello World:/";

        }

        public static void main(String args[]) throws Exception{

            SpringApplication.run(example.class, args);

        }

    }

    所有新增加的语句后面都有注释//new in 110

    说明

    大多数文章里看到是@Controller,而这里是@RestController。两者的区别在于:@Controller返回的字符串是模板文件名,而@RestController返回的就是Response Body

    参考

    官网 | Developing Your First Spring Boot Application

    相关文章

      网友评论

          本文标题:SpringBoot | 跟随官网的脚步 | 110: URL

          本文链接:https://www.haomeiwen.com/subject/xfnegftx.html