快速搭建Spring-boot Demo

快速搭建Spring-boot Demo

环境:
jdk: 1.8
ide: Spring Tool Suite
maven : 3.2 地址为阿里的maven仓库

步骤:
1 : file-->new--->Spring Starter Project
快速搭建Spring-boot Demo_第1张图片
快速搭建Spring-boot Demo_第2张图片
快速搭建Spring-boot Demo_第3张图片

2: 完成上述步骤后可以看到项目结构为:
快速搭建Spring-boot Demo_第4张图片
com.example包下新建两个包com.example.controller , com.example.entiry
快速搭建Spring-boot Demo_第5张图片
Controller中代码如下:
@RestController
@RequestMapping("/hello")
public class ExampleController {
	@GetMapping("/home")//@GetMapping("/home")相当于@RequestMapping(value = "/home" ,method = requestMethod.Post)
	public Person home(){
		Person person = new Person();
		person.setId(222L);
		person.setName("张三");
		person.setAge(20);
		return person;
	}
}
Person基本结构:
package com.example.entity;

public class Person {
	private Long id;
	private String name;
	private String add;
	private int age;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAdd() {
		return add;
	}

	public void setAdd(String add) {
		this.add = add;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

}
选中DemoApplication.java 右键run as Spring Boot App,启动完成后默认端口为8080
在浏览器中输入:http://localhost:8080/hello/home
快速搭建Spring-boot Demo_第6张图片
如上显示,那么一个简单的Demo就完成了,关于controller和DemoApplication.java 类中的注解我们下面再一起学习

你可能感兴趣的:(Spring)