springBoot 搭建以及初始化教程

使用eclipse 创建一个maven项目

  

<parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>1.5.10.RELEASE</version>

      <relativePath/>   <!-- 表示父模块pom的相对路径,这里没有值 -->
  </parent>

然后你的第一个spring boot项目就初步搭建好了

接下来是配置pom.xml自己对比一下我把你缺少的部分的代码已经粘贴在下面了

(***********切记***********)

修改jdk要刷新项目

 <!-- 修改jdk -->
     <properties>
         <java.version>1.7</java.version>
     </properties>
     <dependencies>
         <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-web</artifactId>
          </dependency>
     </dependencies>

修改后记得多点几下报错,也可能是因为你网速问题下载开发包可能会就久一些上面配置的是web开发模板

下面建一个分别建一个controller和一个启动项

(***********切记*********)

controller必须在启动项可控内部在弄一包下或在其子包下

Controller代码

package com.wqc.controller;


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

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

/**
 * 
 * @author Administrator
 *
 */
@Controller
public class HlloWorld {
	@RequestMapping("/hello")
	@ResponseBody
	public Map<String,Object> showHellWorld() {
		Map<String, Object>map=new HashMap<>();
		map.put("msg", "helloword");
		return map;
	}
}

启动项代码

package com.wqc;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * 启动
 * @author Administrator
 *
 */
@SpringBootApplication
public class App {

	public static void main(String[] args) {
		SpringApplication.run(App.class, args);
	}
}

全部完成后点击启动页右键 applaction

接下来就可以在浏览器访问了 http://localhost:8080/hello

猜你喜欢

转载自blog.csdn.net/qq_35128576/article/details/90770636
今日推荐