研磨SpringCloud系列(一)第一个Spring Boot应用
在此之前,给大家推荐几个东西.
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看以下吧~
研磨SpringCloud系列(一)第一个Spring Boot应用的更多相关文章
- spring boot系列01--快速构建spring boot项目
最近的项目用spring boot 框架 借此学习了一下 这里做一下总结记录 非常便利的一个框架 它的优缺点我就不在这背书了 想了解的可以自行度娘谷歌 说一下要写什么吧 其实还真不是很清楚,只是想记录 ...
- Sping Boot入门到实战之入门篇(二):第一个Spring Boot应用
该篇为Spring Boot入门到实战系列入门篇的第二篇.介绍创建Spring Boot应用的几种方法. Spring Boot应用可以通过如下三种方法创建: 通过 https://start.spr ...
- Spring Boot 2.0系列文章(五):Spring Boot 2.0 项目源码结构预览
关注我 转载请务必注明原创地址为:http://www.54tianzhisheng.cn/2018/04/15/springboot2_code/ 项目结构 结构分析: Spring-boot-pr ...
- 创建一个 Spring Boot 项目,你会几种方法?
我最早是 2016 年底开始写 Spring Boot 相关的博客,当时使用的版本还是 1.4.x ,文章发表在 CSDN 上,阅读量最大的一篇有 42W+,如下图: 2017 年由于种种原因,就没有 ...
- Springboot 系列(一)Spring Boot 入门篇
注意:本 Spring Boot 系列文章基于 Spring Boot 版本 v2.1.1.RELEASE 进行学习分析,版本不同可能会有细微差别. 前言 由于 J2EE 的开发变得笨重,繁多的配置, ...
- Spring Boot2 系列教程(二)创建 Spring Boot 项目的三种方式
我最早是 2016 年底开始写 Spring Boot 相关的博客,当时使用的版本还是 1.4.x ,文章发表在 CSDN 上,阅读量最大的一篇有 43W+,如下图: 2017 年由于种种原因,就没有 ...
- Spring Boot2 系列教程(二十)Spring Boot 整合JdbcTemplate 多数据源
多数据源配置也算是一个常见的开发需求,Spring 和 SpringBoot 中,对此都有相应的解决方案,不过一般来说,如果有多数据源的需求,我还是建议首选分布式数据库中间件 MyCat 去解决相关问 ...
- Spring Boot2 系列教程(三十)Spring Boot 整合 Ehcache
用惯了 Redis ,很多人已经忘记了还有另一个缓存方案 Ehcache ,是的,在 Redis 一统江湖的时代,Ehcache 渐渐有点没落了,不过,我们还是有必要了解下 Ehcache ,在有的场 ...
- spring boot系列(五)spring boot 配置spring data jpa (查询方法)
接着上面spring boot系列(四)spring boot 配置spring data jpa 保存修改方法继续做查询的测试: 1 创建UserInfo实体类,代码和https://www.cnb ...
随机推荐
- 大学写作期中作业--霸天黄小o
霸天黄小o 百无聊赖之中,小o又回想起了它当初的辉煌时刻. 那是凤儿凰自行车厂的又一次大规模交货.虽然其实在500万的订单下,一批又一批的交货几乎是连着的. 但这并不影响小o和与它一届的同学们的意气风 ...
- python制作爬虫爬取京东商品评论教程
作者:蓝鲸 类型:转载 本文是继前2篇Python爬虫系列文章的后续篇,给大家介绍的是如何使用Python爬取京东商品评论信息的方法,并根据数据绘制成各种统计图表,非常的细致,有需要的小伙伴可以参考下 ...
- 在WP应用中创建全局应用程序栏
创建一个WindowsPhone应用程序(这个就不用说了吧,嘿嘿) 打开项目中的App.xaml文件 在打开的App.xaml文件中,如图所示, 在<Application.Resources& ...
- 进程管理之system
system定义 #include<stdlib.h> int system(const char *command); 首先要知道,system函数是c库中的函数,而不是系统调用.其实s ...
- grep Pocket Reference读记
1 简介 grep的基本命令格式如下: grep [options] [regexp] [filename] 如果regexp中含有空格,应该使用单引号或双引号括起来.单引号和 ...
- throws Exception方法异常处理机制
public class T4 { private String sex; public String getSex() { return sex; } public void setSex(Stri ...
- 运用jQuery写的验证表单
//运用jQuery写的验证表单 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "h ...
- 使用CXF开发JAX-RS类型的WebService
1.JAXRSServerFactoryBean编程方式 访问方式:http://localhost:8080/cxf_spring_rest_server/ws/rest/student/query ...
- Day-8: 面对对象编程
面对过程的程序设计方法意在将函数分成子函数,再依次调用这些函数来解决问题. 而面对对象的程序设计方法,来源于自然界,类是实例的抽象,实例是类的具体.自定义出来的对象是类,而所有的数据都可以看成是对象, ...
- 网络传输编程之TCP
网络传输编程之TCP 网络传输编程指基于各种网络协议进行编程,包括TCP编程,UDP编程,P2P编程.本节介绍TCP编程. (1)TCP简介: TCP是TCP/IP体系中最重要的传输层协议 ...