1.Spring 和SpringBoot区别
2.Web开发入门
3.MVC模型
4.@RequestMapping用法
5.RESTful
参考:
大家都懂Spring和SpringBoot的区别吗? - 知乎
https://www.zhihu.com/question/598494506/answer/3018702101
在学习了Spring和初步了解了SpringBoot之后,我想讨论一下这俩者的区别,从我一个初学者的角度出发,看待这个问题。
a.Spring依赖XML配置文件,虽然也支持Java配置和注解,但是早期还是以XML配置为主。SpringBoot通过各种的注解,极大地缩减了或者说消除了XML配置文件
b.Springboot集成了许多依赖项,大大减少了项目的搭建和开发流程。提供的“starters” poms来简化 Maven 配置。
Maven依赖:
首先,让我们看一下使用Spring创建Web应用程序所需的最小依赖项
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.0.RELEASE</version>
</dependency>
与Spring不同,Spring Boot只需要一个依赖项来启动和运行Web应用程序:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.6.RELEASE</version>
</dependency>
在 Spring 项目中,我们应该将Spring Test , JUnit , Hamcrest 和 Mockito添加为依赖项。但是在 Spring Boot中 ,我们只需要添加 spring-boot-starter-test 依赖项来自动包含这些库。 Spring Boot为不同的Spring模块提供了许多依赖项。一些最常用的是: spring-boot-starter-data-jpa spring-boot-starter-security spring-boot-starter-test spring-boot-starter-web spring-boot-starter-thymeleaf
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.demo.demos.web;
/**
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
*/
public class User {
private String name;
private Integer age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
运行结果:返回结果是JSON格式