研磨SpringCloud系列(一)第一个Spring Boot应用
2017-09-05 15:09
381 查看
在此之前,给大家推荐几个东西.
STS,Spring官方基于eclipse做的扩展ide.Spring官方背书.
第二个,lombok,注解生成get/set,构造以及基本方法的插件,"隐藏大量非业务代码",可以让我们的业务代码变的更纯净,更加容易维护.
第三个,推荐一下JPA,现在也越来越流行.
总之呢,目的就是让我们的代码阅读性更强,规范我们的开发.
下面编写我们第一个Spring boot应用
先构建一个maven项目,在pom.xml文件中添加springboot web依赖
接下来我们新建一个springboot启动类,用@SpringBootApplication标识它
新建一个Controller类,提供网页访问接口,@RestController注解默认以json格式返回.
运行Application类的main方法,我们第一个springboot 应用就创建成功了,是不是超级方便呢
接下来我们访问以下localhost:8080/add?a=1&b=2看以下吧~
STS,Spring官方基于eclipse做的扩展ide.Spring官方背书.
第二个,lombok,注解生成get/set,构造以及基本方法的插件,"隐藏大量非业务代码",可以让我们的业务代码变的更纯净,更加容易维护.
第三个,推荐一下JPA,现在也越来越流行.
总之呢,目的就是让我们的代码阅读性更强,规范我们的开发.
下面编写我们第一个Spring boot应用
先构建一个maven项目,在pom.xml文件中添加springboot web依赖
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com</groupId> <artifactId>SrpingBoot</artifactId> <version>0.0.1-SNAPSHOT</version> <name>boot</name> <description>第一个SpringBoot应用</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </project>
接下来我们新建一个springboot启动类,用@SpringBootApplication标识它
package com; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Application { public static void main(String[] args) throws Exception { SpringApplication.run(Application.class, args); } }
新建一个Controller类,提供网页访问接口,@RestController注解默认以json格式返回.
package com.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController public class Controller { @RequestMapping(name="/add" ,method=RequestMethod.GET) public Integer add(@RequestParam Integer a, @RequestParam Integer b) { return a+b; } }
运行Application类的main方法,我们第一个springboot 应用就创建成功了,是不是超级方便呢
接下来我们访问以下localhost:8080/add?a=1&b=2看以下吧~
相关文章推荐
- Spring-Cloud 系列第 1 篇:spring-cloud-config
- spring cloud放弃系列之--3-zuul
- Spring Cloud Security系列教程一:入门
- Spring Cloud微服务实战教程系列(一)——Spring Cloud微服务简介
- Spring Cloud | 学习系列 Spring Cloud中基于Sleuth的参数透传功能探索
- spring cloud 系列文章
- spring-cloud系列 | eureka注册中心搭建
- SpringBoot - 第一个spring boot应用
- SpringCloud系列:服务注册与发现、负责均衡、hystrix服务降级的实现
- SpringCloud系列十:SpringCloudConfig 高级配置(密钥加密处理(JCE)、KeyStore 加密处理、SpringCloudConfig 高可用机制、SpringCloudBus 服务总线)
- Spring Boot系列教程二:创建第一个web工程 hello world
- Spring cloud系列二 Spring Cloud 配置中心的基本用法
- Spring Boot学习笔记-创建第一个Spring Boot应用
- Spring-Cloud系列第3篇:spring-cloud-eureka-consumer
- SpringCloud调研系列5.2:服务网关Zuul组合API之Filter研究
- SpringBoot系列二:搭建自己的第一个SpringBoot程序
- 【微框架】之一:从零开始,轻松搞定SpringCloud微服务系列--开山篇(spring boot 小demo)
- Spring Cloud系列学习
- spring cloud 入门实践系列 - feign
- [置顶] Spring研磨分析、Quartz任务调度、Hibernate深入浅出系列文章笔记汇总