快速搭建Spring-boot Demo

来源:互联网 发布:mac 自动更新 快捷键 编辑:程序博客网 时间:2024/06/10 02:06

快速搭建Spring-boot Demo

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

步骤:
1 : file-->new--->Spring Starter Project

2:完成上述步骤后可以看到项目结构为:
com.example包下新建两个包com.example.controller , com.example.entiry
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
如上显示,那么一个简单的Demo就完成了,关于controller和DemoApplication.java 类中的注解我们下面再一起学习
1 0
原创粉丝点击