无标题文章

## 新建项目

>新建一个maven quickstart项目:

![image](https://raw.githubusercontent.com/yangyp8110/markdown-images/master/maven-new-spring-boot-project/1-create-quickstart.png)

>项目结构图:

![image](https://raw.githubusercontent.com/yangyp8110/markdown-images/master/maven-new-spring-boot-project/2-project.png)

>pom.xml文件:

```java

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

mybatis-generator-demo

mybatis-generator

1.0-SNAPSHOT

jar

mybatis-generator

http://maven.apache.org

UTF-8

junit

junit

3.8.1

test

```

## 配置项目

>一、打开settings.xml,配置本地仓库:

```java

C:\Users\yangyp\.m2\libs

```

>二、在profiles下配置远程仓库(或自建仓库)地址:

```java

nexus

central

http://repo1.maven.org/maven2

true

false

central

http://repo1.maven.org/maven2

true

false

```

> **http://repo1.maven.org/maven2 为美国ip,速度比较慢**

>三、pom.xml配置:

```java

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

mybatis-generator-demo

mybatis-generator

1.0-SNAPSHOT

jar

mybatis-generator

http://maven.apache.org

UTF-8

1.8

org.springframework.boot

spring-boot-starter-parent

1.4.0.RELEASE

xxx

xxx

http://maven.repo.xxx.com/nexus/content/groups/public/

xxx

xxx

http://maven.repo.xxx.com/nexus/content/repositories/releases/

xxx

xxx

http://maven.repo.xxx.com/nexus/content/repositories/snapshots/

org.springframework.boot

spring-boot-starter-web

junit

junit

3.8.1

test

org.apache.maven.plugins

maven-compiler-plugin

3.3

1.8

1.8

```

> Reimport项目后:

![image](https://raw.githubusercontent.com/yangyp8110/markdown-images/master/maven-new-spring-boot-project/3-load-jar-from-remote-repository-finished.png)

>controller:

```java

@RestController

@RequestMapping("/")

public class HelloController {

@RequestMapping("/hello")

public String PrintHello(){

return "hello world !";

}

@RequestMapping("/printMsg/{msg}")

//    public String PrintPathVariable(@PathVariable String msg){

//        return msg;

//    }

public String PrintPathVariable(@PathVariable("msg") String paramMsg){

return paramMsg;

}

@RequestMapping("/requestParams")

public String PrintRequestParams(@RequestParam(name = "inputMsg",required = true) String inputMsg,@RequestParam(value = "username",required = false)String username){

String msg = "inputMsg :"+inputMsg+",username :"+username;

return msg;

}

@RequestMapping("/saveUser")

public String SaveUser(@RequestBody UserDto userDto){

return userDto.toString();

}

}

```

>运行测试:

>@PathVariable传参:

http://localhost:8080/printMsg/welcome

![image](https://raw.githubusercontent.com/yangyp8110/markdown-images/master/maven-new-spring-boot-project/4-@RequestParam.png)

>@RequestParam传参:

![image](https://raw.githubusercontent.com/yangyp8110/markdown-images/master/maven-new-spring-boot-project/5-@ResponseBody.png)

运行成功!

spring.boot服务构建成功!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,032评论 19 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,977评论 6 342
  • spring官方文档:http://docs.spring.io/spring/docs/current/spri...
    牛马风情阅读 1,745评论 0 3
  • http://blog.csdn.net/Flight5630/article/details/51228916?...
    perfect_jimmy阅读 202评论 0 0
  • 上一章: 海盗狗的咒语 2 -- 学徒 一天的练习结束了,路路猫平静的走在去往小木屋的路上。直到这时,她还在想,海...
    人类阿小晴阅读 289评论 0 0