SpringBoot官方笔记4Web

这篇具有很好参考价值的文章主要介绍了SpringBoot官方笔记4Web。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

Most web applications use the spring-boot-starter-web module to get up and running quickly. You can also choose to build reactive web applications by using the spring-boot-starter-webflux module.

Servlet Web Applications

Spring Web MVC Framework

import java.util.List;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/users")
public class MyRestController {

    private final UserRepository userRepository;

    private final CustomerRepository customerRepository;

    public MyRestController(UserRepository userRepository, CustomerRepository customerRepository) {
        this.userRepository = userRepository;
        this.customerRepository = customerRepository;
    }

    @GetMapping("/{userId}")
    public User getUser(@PathVariable Long userId) {
        return this.userRepository.findById(userId).get();
    }

    @GetMapping("/{userId}/customers")
    public List<Customer> getUserCustomers(@PathVariable Long userId) {
        return this.userRepository.findById(userId).map(this.customerRepository::findByUser).get();
    }

    @DeleteMapping("/{userId}")
    public void deleteUser(@PathVariable Long userId) {
        this.userRepository.deleteById(userId);
    }

}

Static Content

By default, Spring Boot serves static content from a directory called /static (or /public or /resources or /META-INF/resources) in the classpath or from the root of the ServletContext.

Error Handling

By default, Spring Boot provides an /error mapping that handles all errors in a sensible way, and it is registered as a “global” error page in the servlet container.

CORS Support

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration(proxyBeanMethods = false)
public class MyCorsConfiguration {

    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {

            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/api/**");
            }

        };
    }

}

By default, the embedded server listens for HTTP requests on port 8080.

Reactive Web Applications

Spring WebFlux is the new reactive web framework introduced in Spring Framework 5.0. Unlike Spring MVC, it does not require the servlet API, is fully asynchronous and non-blocking, and implements the Reactive Streams specification through the Reactor project.

Spring Security

Spring Boot relies on Spring Security’s content-negotiation strategy to determine whether to use httpBasic or formLogin.

The basic features you get by default in a web application are:

  • UserDetailsService (or ReactiveUserDetailsService in case of a WebFlux application) bean with in-memory store and a single user with a generated password (see SecurityProperties.User for the properties of the user).

  • Form-based login or HTTP Basic security (depending on the Accept header in the request) for the entire application (including actuator endpoints if actuator is on the classpath).

  • DefaultAuthenticationEventPublisher for publishing authentication events.

OAuth2 is a widely used authorization framework that is supported by Spring.

Spring Session

When building a servlet web application, the following stores can be auto-configured:

  • Redis

  • JDBC

  • Hazelcast

  • MongoDB

参考资料:

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#web文章来源地址https://www.toymoban.com/news/detail-583648.html

到了这里,关于SpringBoot官方笔记4Web的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Spring MVC官方文档学习笔记(一)之Web入门

    注: 该章节主要为原创内容,为后续的Spring MVC内容做一个先行铺垫 1.Servlet的构建使用 (1) 选择Maven - webapp来构建一个web应用 (2) 构建好后,打开pom.xml文件,一要注意打包方式为war包,二导入servlet依赖,如下 (3) 替换webapp/WEB-INF/web.xml文件为如下内容,采用Servlet 3.1版本 (4) 在

    2024年02月03日
    浏览(32)
  • web server apache tomcat11-01-官方文档入门介绍

    整理这个官方翻译的系列,原因是网上大部分的 tomcat 版本比较旧,此版本为 v11 最新的版本。 同时也为从零手写实现 tomcat 提供一些基础和特性的思路。 minicat 别称【嗅虎】心有猛虎,轻嗅蔷薇。 web server apache tomcat11-01-官方文档入门介绍 web server apache tomcat11-02-setup 启动 we

    2024年04月16日
    浏览(33)
  • 《vtk9 book》 官方web版 第1章 - 介绍

    可视化将数字转化为图像。         可视化——《  Webster’s Ninth New Collegiate Dictionary 》中的定义:“2:将信息以视觉形式解释或呈现的行为或过程。”         可视化是我们日常生活的一部分。从天气图到娱乐行业令人兴奋的计算机图形,可视化的例子比比皆是。但

    2024年01月23日
    浏览(27)
  • 《vtk9 book》 官方web版 第2章 - 面向对象设计

     备注:本篇偏向面向对象基础知识,可以略过。               面向对象的系统因为很好的原因在计算机行业变得越来越普遍。面向对象的系统比传统的过程式系统更模块化、更易于维护,也更容易描述。由于可视化工具包是使用面向对象设计进行设计和实现的,我们在

    2024年01月23日
    浏览(30)
  • Java使用Springboot集成Es官方推荐(RestHighLevelClient)

    SpringBoot集成ElasticSearch的四种方式(主要讲解ES官方推荐方式) TransportClient:这种方式即将弃用 官方将在8.0版本彻底去除 Data-Es:Spring提供的封装的方式,由于是Spring提供的,所以每个SpringBoot版本对应的ElasticSearch,具体这么个对应的版本,自己去官网看 ElasticSearch SQL:将Elasti

    2023年04月08日
    浏览(28)
  • 一文读懂Springboot如何使用ChatGPT【OpenAI官方Springboot依赖,极强接口封装】

    封装了丰富的OpenAI 接口可直接使用 申请外国虚拟信用卡【Depay】 充值USTD虚拟货币【欧易】 USTD充值到Depay Depay 的USTD 转 USD虚拟货币 将USD货币存入虚拟信用卡 通过虚拟信用卡充值到ChatGPT 优先ChatGPT试用用户 畅享丝滑的响应速度 优先体验新功能 原文 非常感谢你从头到尾阅读

    2024年02月07日
    浏览(27)
  • 使用百度地图官方WEB API,提示 “ APP 服务被禁用“ 问题的解决方法

    项目上用了百度地图官方WEB API,打开界面时百度地图无法打开,出现弹窗: APP被您禁用啦。详情查看:http://lbsyun.baidu.com/apiconsole/key# 。 查看错误信息: \\\"status\\\":240,\\\"message\\\":\\\"APP 服务被禁用\\\" 在https://lbsyun.baidu.com/index.php?title=webapi/appendix中找到百度地图官方WEB API服务文档—附录

    2023年04月09日
    浏览(94)
  • 《vtk9 book》 官方web版 第3章 - 计算机图形基础 (1 / 6)

            计算机图形是数据可视化的基础。从实际角度来看,可视化是将数据转换为一组图形基元的过程。然后使用计算机图形的方法将这些基元转换为图片或动画。本章讨论了基本的计算机图形原理。我们首先描述了光线和物体如何相互作用形成我们所看到的景象。接下

    2024年01月24日
    浏览(29)
  • 【Unity学习笔记】DOTween(2)官方案例

    本文中大部分内容学习来自DOTween官方文档 此处无法展示动图(懒得录GIF),请下载官方案例场景自行学习 案例一展示了最基础的一些用法: 解读一下代码,redCube的移动是在两秒内移动到了指定坐标 0,4,0 ,而greenCube移动带有 From 方法,则是从坐标 0,4,0 移动到原坐标。blueC

    2024年02月11日
    浏览(31)
  • 学习笔记-elstaciElasticSearch7.17官方文档

    特征 适用于所有 Elasticsearch API 的强类型请求和响应。 所有 API 的阻塞和异步版本。 在创建复杂的嵌套结构时,使用流畅的构建器和功能模式允许编写简洁但可读的代码。 通过使用对象映射器(例如 Jackson 或任何 JSON-B 实现)无缝集成应用程序类。 将协议处理委托给一个 h

    2024年02月14日
    浏览(29)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包