springBoot之入门

1,新建maven项目

pom文件中加入一下配置

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.liu</groupId>
  <artifactId>springBootHelloword</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  <!-- 引入SpringBoot父类依赖 -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.22.RELEASE</version>
    </parent>
    <dependencies>
        <!-- springboot-web组件 springmvc+spring+mybatis -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    

添加controller类

package com.liu.controller;

import java.util.HashMap;
import java.util.Map;

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

//标识该接口全部返回json格式。
@RestController
public class HelloWorldController {
    @RequestMapping("/index")
    public String index() {
        return "success";
    }

    @RequestMapping("/getMap")
    public Map<String, Object> getMap() {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("errorCode", "200");
        result.put("errorMsg", "成功..");
        return result;
    }


}


 

3,编写入口类

package com.liu;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan(basePackages = { "com.liu" })
@SpringBootApplication
public class App {

    public static void main(String[] args) {
        // 主函数运行springboot项目
        SpringApplication.run(App.class, args);
    }

}

4,运行main方法

访问

        


    </dependencies>
</project>

发布了23 篇原创文章 · 获赞 0 · 访问量 204

猜你喜欢

转载自blog.csdn.net/liuerchong/article/details/105121907