【转】SpringBoot入门教程(一)详解intellij idea搭建SpringBoot SpringBoot入门教程(一)详解intellij idea搭建SpringBoot

 

SpringBoot入门教程(一)详解intellij idea搭建SpringBoot

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
 4     <modelVersion>4.0.0</modelVersion>
 5     <parent>
 6         <groupId>org.springframework.boot</groupId>
 7         <artifactId>spring-boot-starter-parent</artifactId>
 8         <version>2.2.2.RELEASE</version>
 9         <relativePath/> <!-- lookup parent from repository -->
10     </parent>
11     <groupId>com.example</groupId>
12     <artifactId>demo</artifactId>
13     <version>0.0.1-SNAPSHOT</version>
14     <name>demo</name>
15     <description>Demo project for Spring Boot</description>
16 
17     <properties>
18         <java.version>1.8</java.version>
19     </properties>
20 
21     <dependencies>
22         <dependency>
23             <groupId>org.springframework.boot</groupId>
24             <artifactId>spring-boot-starter-web</artifactId>
25         </dependency>
26 
27         <dependency>
28             <groupId>org.springframework.boot</groupId>
29             <artifactId>spring-boot-starter-test</artifactId>
30             <scope>test</scope>
31             <exclusions>
32                 <exclusion>
33                     <groupId>org.junit.vintage</groupId>
34                     <artifactId>junit-vintage-engine</artifactId>
35                 </exclusion>
36             </exclusions>
37         </dependency>
38     </dependencies>
39 
40 
41 </project>
pom.xml
 1 package com.example.demo;
 2 
 3 import org.springframework.boot.SpringApplication;
 4 import org.springframework.boot.autoconfigure.SpringBootApplication;
 5 
 6 @SpringBootApplication(scanBasePackages = {"com.example"})
 7 public class DemoApplication {
 8 
 9     public static void main(String[] args) {
10         SpringApplication.run(DemoApplication.class, args);
11     }
12 
13 }
DemoApplication.java
package com.example.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

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

/**
 * <pre>
 * IndexController
 * </pre>
 *
 * @author wangyunpeng
 * @date 2020/1/8 11:33
 */

@Controller
public class IndexController {

    @RequestMapping(value="/", method = RequestMethod.GET)
    @ResponseBody
    public String home(){
        return "home page";
    }

    @RequestMapping(value="/index", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, String> index(){

        Map map = new HashMap<String, String>();
        map.put("北京","北方城市");
        map.put("深圳","男方城市");
        return map;
    }
}
IndexController.java

猜你喜欢

转载自www.cnblogs.com/qiyebao/p/12165259.html