Springboot系列文章
来源:互联网 发布:windows镜像下载网站 编辑:程序博客网 时间:2024/05/29 16:42
一、springboot简介
1.前世今生
在boot没有出现之前,基于spring的开发,常常需要配置大量的xml文件。工程狮们苦不堪言,渐渐厌倦了配置文件的复制黏贴。spring家族因为这件事,也经常被其它技术阵营所诟病。
boot是由毕威拓(Pivotal)团队基于spring开发的一个全新框架,可以理解为是对大量xml文件的一个抽象,基础的功能仍然是基于原生的spring,实际应用中开发人员不再需要编写xml就可以实现之前的功能。
2.web传送门
需求:开发一个web应用,支持根据用户id查询用户信息(用户信息暂时从内存获取),并返回json格式信息.
没有boot,开发人员需要:
1.配置web.xml
2.配置springmvc.xml配置文件
3.配置spring.xml配置文件
4.pom文件中增加依赖的各种jar
5.编写controller类
6.配置服务器,打成war包发布
使用boot,开发人员只需要:
1.编写controller类
2.pom文件中增加很少的jar依赖配置
3.编写启动类
居然减少了三个步骤,而且不需要拷贝黏贴xml.
二、下面demo基于boot 1.5.2开发
1.pom文件内容如下:
<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.github.braveboo</groupId> <artifactId>sboot-example</artifactId> <version>1.0-SNAPSHOT</version> <modules> <module>sboot-part1</module> </modules> <packaging>pom</packaging> <name>sboot-example</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>1.5.2.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies></project>
2.启动类
@SpringBootApplicationpublic class Application {public static void main( String[] args ){SpringApplication.run(Application.class, args);}}
3.controller
@RestControllerpublic class UserController {@RequestMapping("/getUser")User home() {return new User();}}
User对象
package com.github.braveboo.domain;public class User {private String name="lb";private String pwd="pwd";private String sex="男";private Integer id=1;private String verifyPassword="pwd";public String getName() {return name;}public void setName(String name) {this.name = name;}public String getPwd() {return pwd;}public void setPwd(String pwd) {this.pwd = pwd;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getVerifyPassword() {return verifyPassword;}public void setVerifyPassword(String verifyPassword) {this.verifyPassword = verifyPassword;}}
运行Application方法,通过浏览器访问返回如下内容:
{"name":"lb","pwd":"pwd","sex":"男","id":1,"verifyPassword":"pwd"}
三、下载地址
github:https://github.com/braveboo/sbootexample
下一篇文章将介绍boot中如何使用mybatis,敬请期待!
- Springboot系列文章
- springboot系列文章(一)-初识springboot
- springboot系列文章(二)-搭建springboot工程
- springboot系列文章(四)-springboot使用fastjson
- springboot系列文章阶段性总结
- 五.SpringBoot集成实例系列-邮件email文章列表
- springboot系列文章(三)-创建第一个controller
- SpringBoot系列
- 【SpringBoot系列】SpringBoot注解详解
- 1.SpringBoot系列-初识SpringBoot
- SpringBoot系列(6)---SpringBoot-JPA
- [springBoot系列]--springBoot注解大全
- [springBoot系列]--springBoot注解大全
- [springBoot系列]--springBoot注解大全
- [springBoot系列]--springBoot注解大全
- springboot系列文章(四)——fastjson、定时任务、全局异常配置
- SpringBoot配置属性系列
- Springboot实践系列
- StringBoot整合Shiro
- 程序员必须掌握的8种排序算法(八):基数排序
- Java锁的种类和区别
- SpringBoot整合Quartz-动态读取任务执行(2.2.1)
- SIM上运营商SPN(Service Provider Name)的读取
- Springboot系列文章
- 熵的通俗理解
- SpringBoot集成Rabbit使用TopicRabbit指定发送集合
- Spring之ioc操作与属性注入
- 输出100-500之间的水仙花数
- 数据库
- Hive(十八)--全局排序
- codevs 1079 回家 Floyd 解题报告
- StringBoot集成Rabbit,根据业务返回ACK