无标题文章

## 新建项目

>新建一个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/[email protected])

>@RequestParam传参:

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

运行成功!

spring.boot服务构建成功!

你可能感兴趣的:(无标题文章)