1.1 优点:
简化spring开发/约定优于配置 :
- 嵌入式的servlet容器;
- starter自动依赖和版本控制;
- 大量自动配置, 简化开发;
- 无需配置xml, 无代码生成, 开箱即用;
- 应用监控:准生产环境的运行时应用监控;
1.2 缺点:
入门容易, 精通难~
1.3 微服务
springboot:
一个应用, 是一组小型服务, 可以通过http方式进行互通; 每一个功能元素都是一个可以独立替换和独立升级的单元;
springcloud:
整个应用的大型分布式网格之间的调用;
1.4 helloworld
1.4.1 maven依赖:
<?xml version="1.0" encoding="UTF-8"?>
<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.niewj</groupId>
<artifactId>springboot-study</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<spring-boot-version>2.3.2.RELEASE</spring-boot-version>
</properties>
<modules>
<module>springboot-01-helloworld</module>
</modules>
<!-- 表示是一个pom总的父工程 -->
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>${spring-boot-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot-version}</version>
</dependency>
</dependencies>
</project>
1.4.2 类文件:
SpringBootApplication
启动类
package com.niewj.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Created by niewj on 2020/8/4 18:04
*/
@SpringBootApplication
public class HelloApplication {
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class, args);
}
}
HelloController.java
package com.niewj.springboot.controller;
import com.niewj.springboot.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Created by niewj on 2020/8/4 18:08
*/
@Controller
public class HelloController {
@RequestMapping("/hello")
@ResponseBody
public Object hello(){
return new User("niewj", 33);
}
}
User实体类:
package com.niewj.springboot.model;
/**
* Created by niewj on 2020/8/4 18:09
*/
public class User {
private String name;
private int age;
public User(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
完结; 访问: http://localhost:8080/hello
返回:
{"name":"niewj","age":33}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。