快速搭建Spring-boot Demo
2017-04-19 15:29
337 查看
快速搭建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
类中的注解我们下面再一起学习
相关文章推荐
- spring boot 快速搭建 基于 Restful 风格的微服务
- springboot与RabbitMQ的快速搭建
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- springboot快速搭建
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- SpringBoot-快速搭建WEB工程
- 【SpringBoot教程二】:RESTfull API简单项目的快速搭建
- 聊聊SpringBoot | 第一章:快速搭建SpringBoot第一个应用
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- 使用SpringBoot快速搭建服务器
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- 用Spring Boot & Cloud,Angular2快速搭建微服务web应用 - AngularJS2客户端
- SpringBoot 快速搭建
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程