简化spring开发/约定优于配置 :java
入门容易, 精通难~web
springboot:
spring
一个应用, 是一组小型服务, 能够经过http方式进行互通; 每个功能元素都是一个能够独立替换和独立升级的单元;shell
springcloud:
apache
整个应用的大型分布式网格之间的调用;springboot
<?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>
SpringBootApplication
启动类app
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.javamaven
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/hellospring-boot
返回:
{"name":"niewj","age":33}