zoukankan      html  css  js  c++  java
  • SpringBoot 2 : 网络配置

    引入 Web 模块

    1、pom.xml中添加支持web的模块:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    

    pom.xml文件中默认有两个模块:

    spring-boot-starter:核心模块,包括自动配置支持、日志和YAML;

    spring-boot-starter-test:测试模块,包括JUnit、Hamcrest、Mockito。

    2、编写controller内容

    
    @RestController
    public class HelloWorldController {
        @RequestMapping("/hello")
        public String index() {
            return "Hello World";
        }
    }
    

    @RestController的意思就是controller里面的方法都以json格式输出,不用再写什么jackjson配置的了!

    3、启动主程序,打开浏览器访问http://localhost:8080/hello,就可以看到效果了,有木有很简单!

  • 相关阅读:
    pinyin4j使用示例
    迭代器模式
    适配器模式
    策略模式
    装饰模式
    责任链模式
    命令模式
    中介者模式
    原型模式
    代理模式
  • 原文地址:https://www.cnblogs.com/Plorde/p/13191355.html
Copyright © 2011-2022 走看看