当前位置: 首页 > news >正文

怎么做网络销售的网站/成都网站建设

怎么做网络销售的网站,成都网站建设,营销网站建设培训,wordpress提示窗Spring Boot应用开发:从入门到精通 Spring Boot是Spring框架的一个子项目,旨在简化Spring应用的初始搭建和开发过程。通过自动配置和约定大于配置的原则,Spring Boot使开发者能够快速构建独立的、生产级别的Spring应用。本文将深入探讨Sprin…

Spring Boot应用开发:从入门到精通

Spring Boot是Spring框架的一个子项目,旨在简化Spring应用的初始搭建和开发过程。通过自动配置和约定大于配置的原则,Spring Boot使开发者能够快速构建独立的、生产级别的Spring应用。本文将深入探讨Spring Boot的核心概念、常见功能以及实际应用案例,帮助你从入门到精通掌握Spring Boot应用开发。

Spring Boot的核心概念

1. 自动配置(Auto-Configuration)

Spring Boot的自动配置功能是其核心特性之一,通过自动配置,Spring Boot能够根据项目的依赖自动配置Spring应用的上下文。开发者无需手动配置大量的XML或Java配置文件,从而大大简化了开发过程。

  • 条件化配置:Spring Boot根据项目的依赖和类路径中的类,自动配置Spring应用的上下文。
  • 自定义配置:开发者可以通过application.propertiesapplication.yml文件自定义配置。

2. 起步依赖(Starter Dependencies)

Spring Boot提供了大量的起步依赖,每个起步依赖都包含了一组常用的依赖库,开发者只需引入一个起步依赖,即可自动引入相关的依赖库。

  • 常用起步依赖
    • spring-boot-starter-web:用于构建Web应用。
    • spring-boot-starter-data-jpa:用于数据访问。
    • spring-boot-starter-security:用于安全认证。

3. 嵌入式服务器(Embedded Server)

Spring Boot内置了Tomcat、Jetty和Undertow等嵌入式服务器,开发者无需手动配置和部署服务器,只需运行Spring Boot应用即可启动Web服务器。

  • 默认服务器:Spring Boot默认使用Tomcat作为嵌入式服务器。
  • 自定义服务器:开发者可以通过配置文件或代码自定义嵌入式服务器。

4. 命令行接口(Spring Boot CLI)

Spring Boot CLI是一个命令行工具,用于快速创建和运行Spring Boot应用。通过Spring Boot CLI,开发者可以快速生成项目结构、运行应用和测试代码。

  • 安装CLI:通过brew install springboot或下载安装包进行安装。
  • 常用命令
    • spring init:生成项目结构。
    • spring run:运行应用。
    • spring test:运行测试。

Spring Boot的常见功能

1. Web应用开发

Spring Boot提供了丰富的功能支持Web应用开发,包括RESTful API、模板引擎、静态资源处理等。

  • RESTful API:通过Spring MVC和Spring Data REST,开发者可以快速构建RESTful API。
@RestController
@RequestMapping("/api")
public class UserController {@GetMapping("/users")public List<User> getUsers() {// 返回用户列表}@PostMapping("/users")public User createUser(@RequestBody User user) {// 创建用户}
}
  • 模板引擎:Spring Boot支持多种模板引擎,如Thymeleaf、FreeMarker和JSP。
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head><title>Spring Boot Thymeleaf Example</title>
</head>
<body><h1 th:text="'Hello, ' + ${name} + '!'"></h1>
</body>
</html>

2. 数据访问

Spring Boot提供了多种数据访问方式,包括JPA、MyBatis、MongoDB等。

  • JPA:通过Spring Data JPA,开发者可以快速实现数据访问。
@Entity
public class User {@Id@GeneratedValue(strategy = GenerationType.IDENTITY)private Long id;private String name;private String email;// Getters and Setters
}@Repository
public interface UserRepository extends JpaRepository<User, Long> {
}
  • MongoDB:通过Spring Data MongoDB,开发者可以快速实现MongoDB的数据访问。
@Document(collection = "users")
public class User {@Idprivate String id;private String name;private String email;// Getters and Setters
}@Repository
public interface UserRepository extends MongoRepository<User, String> {
}

3. 安全认证

Spring Boot提供了Spring Security支持,开发者可以快速实现安全认证和授权。

  • 基本认证:通过Spring Security,开发者可以实现基本认证。
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {@Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().antMatchers("/public/**").permitAll().anyRequest().authenticated().and().httpBasic();}
}
  • OAuth2认证:通过Spring Security OAuth2,开发者可以实现OAuth2认证。
@Configuration
@EnableAuthorizationServer
public class OAuth2Config extends AuthorizationServerConfigurerAdapter {@Overridepublic void configure(ClientDetailsServiceConfigurer clients) throws Exception {clients.inMemory().withClient("client").secret("secret").authorizedGrantTypes("authorization_code").scopes("user_info").autoApprove(true);}
}

4. 缓存支持

Spring Boot提供了多种缓存支持,包括Ehcache、Redis等。

  • Ehcache:通过Spring Cache,开发者可以快速实现Ehcache缓存。
@Configuration
@EnableCaching
public class CacheConfig {@Beanpublic CacheManager cacheManager() {return new EhCacheCacheManager(ehCacheCacheManager().getObject());}@Beanpublic EhCacheManagerFactoryBean ehCacheCacheManager() {EhCacheManagerFactoryBean factory = new EhCacheManagerFactoryBean();factory.setConfigLocation(new ClassPathResource("ehcache.xml"));factory.setShared(true);return factory;}
}
  • Redis:通过Spring Data Redis,开发者可以快速实现Redis缓存。
@Configuration
@EnableCaching
public class CacheConfig {@Beanpublic CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {return RedisCacheManager.create(redisConnectionFactory);}
}

Spring Boot的实际应用案例

1. 构建RESTful API

假设我们有一个简单的用户管理系统,希望通过Spring Boot构建RESTful API。

  • 项目结构
src
├── main
│   ├── java
│   │   └── com
│   │       └── example
│   │           └── demo
│   │               ├── DemoApplication.java
│   │               ├── controller
│   │               │   └── UserController.java
│   │               ├── model
│   │               │   └── User.java
│   │               └── repository
│   │                   └── UserRepository.java
│   └── resources
│       └── application.properties
└── test└── java└── com└── example└── demo└── DemoApplicationTests.java
  • 依赖配置
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency><dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>
</dependencies>
  • 实体类
@Entity
public class User {@Id@GeneratedValue(strategy = GenerationType.IDENTITY)private Long id;private String name;private String email;// Getters and Setters
}
  • Repository接口
@Repository
public interface UserRepository extends JpaRepository<User, Long> {
}
  • Controller类
@RestController
@RequestMapping("/api")
public class UserController {@Autowiredprivate UserRepository userRepository;@GetMapping("/users")public List<User> getUsers() {return userRepository.findAll();}@PostMapping("/users")public User createUser(@RequestBody User user) {return userRepository.save(user);}
}
  • 启动类
@SpringBootApplication
public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}
}

2. 构建Web应用

假设我们有一个简单的博客系统,希望通过Spring Boot构建Web应用。

  • 项目结构
src
├── main
│   ├── java
│   │   └── com
│   │       └── example
│   │           └── blog
│   │               ├── BlogApplication.java
│   │               ├── controller
│   │               │   └── BlogController.java
│   │               ├── model
│   │               │   └── Post.java
│   │               └── repository
│   │                   └── PostRepository.java
│   └── resources
│       ├── application.properties
│       └── templates
│           └── index.html
└── test└── java└── com└── example└── blog└── BlogApplicationTests.java
  • 依赖配置
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency><dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>
</dependencies>
  • 实体类
@Entity
public class Post {@Id@GeneratedValue(strategy = GenerationType.IDENTITY)private Long id;private String title;private String content;// Getters and Setters
}
  • Repository接口
@Repository
public interface PostRepository extends JpaRepository<Post, Long> {
}
  • Controller类
@Controller
public class BlogController {@Autowiredprivate PostRepository postRepository;@GetMapping("/")public String index(Model model) {model.addAttribute("posts", postRepository.findAll());return "index";}@PostMapping("/posts")public String createPost(@ModelAttribute Post post) {postRepository.save(post);return "redirect:/";}
}
  • 模板文件
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head><title>Spring Boot Blog</title>
</head>
<body><h1>Blog Posts</h1><ul><li th:each="post : ${posts}"><h2 th:text="${post.title}"></h2><p th:text="${post.content}"></p></li></ul><h2>Create New Post</h2><form action="/posts" method="post"><label for="title">Title:</label><input type="text" id="title" name="title" required><label for="content">Content:</label><textarea id="content" name="content" required></textarea><button type="submit">Create</button></form>
</body>
</html>
  • 启动类
@SpringBootApplication
public class BlogApplication {public static void main(String[] args) {SpringApplication.run(BlogApplication.class, args);}
}

Spring Boot的未来发展趋势

1. 微服务架构

随着微服务架构的流行,Spring Boot将成为构建微服务应用的首选框架。通过Spring Cloud,开发者可以快速构建分布式系统,实现服务注册、发现、配置和负载均衡等功能。

2. 云原生应用

随着云计算的发展,Spring Boot将更加注重云原生应用的开发。通过Spring Cloud Kubernetes和Spring Cloud Function,开发者可以快速构建云原生应用,实现容器化部署和函数式编程。

3. 自动化与智能化

随着人工智能和机器学习技术的发展,Spring Boot将越来越依赖自动化和智能化工具。通过自动化配置、自动化测试和智能化监控,开发者可以提高Spring Boot应用的开发效率和运维效率。

4. 数据驱动业务

随着数据驱动业务的需求增加,Spring Boot将更加注重数据集成和数据分析。通过Spring Data和Spring Integration,开发者可以快速实现数据集成和数据分析,推动企业实现数据驱动的业务决策和运营优化。

总结

Spring Boot通过其自动配置、起步依赖和嵌入式服务器等特性,使开发者能够快速构建独立的、生产级别的Spring应用。通过掌握Spring Boot的核心概念和常见功能,你将能够构建高效、安全的Web应用,推动企业实现数字化转型。

希望这篇文章能帮助你更好地理解Spring Boot,并激发你探索更多应用开发的可能性。Happy coding!

相关文章:

Spring Boot应用开发:从入门到精通

Spring Boot应用开发&#xff1a;从入门到精通 Spring Boot是Spring框架的一个子项目&#xff0c;旨在简化Spring应用的初始搭建和开发过程。通过自动配置和约定大于配置的原则&#xff0c;Spring Boot使开发者能够快速构建独立的、生产级别的Spring应用。本文将深入探讨Sprin…...

【JAVA项目】基于jspm的【医院病历管理系统】

技术简介&#xff1a;采用jsp技术、MySQL等技术实现。 系统简介&#xff1a;通过标签分类管理等方式&#xff0c;实现管理员&#xff1b;个人中心、医院公告管理、用户管理、科室信息管理、医生管理、出诊信息管理、预约时间段管理、预约挂号管理、门诊病历管理、就诊评价管理、…...

Python中的常见配置文件写法

在软件开发过程中&#xff0c;开发者常常需要利用一些固定的参数或常量。对于这些相对恒定且频繁使用的元素&#xff0c;一种常见的做法是将它们集中存储在一个特定的文件中&#xff0c;以避免在多个模块代码中重复定义&#xff0c;从而维护核心代码的清晰度和整洁性。 具体而…...

语义分割实战——基于PSPnet神经网络动物马分割系统源码

第一步&#xff1a;准备数据 动物马分割数据&#xff0c;总共有328张图片&#xff0c;里面的像素值为0和1&#xff0c;所以看起来全部是黑的&#xff0c;不影响使用 第二步&#xff1a;搭建模型 psp模块的样式如下&#xff0c;其psp的核心重点是采用了步长不同&#xff0c;po…...

Python+Appium编写脚本

一、环境配置 1、安装JDK&#xff0c;版本1.8以上 2、安装Python&#xff0c;版本3.x以上&#xff0c;用来解释python 3、安装node.js&#xff0c;版本^14.17.0 || ^16.13.0 || >18.0.0&#xff0c;用来安装Appimu Server 4、安装npm&#xff0c;版本>8&#xff0c;用…...

RK3288 android7.1 适配 ilitek i2c接口TP

一&#xff0c;Ilitek 触摸屏简介 Ilitek 提供多种型号的触控屏控制器&#xff0c;如 ILI6480、ILI9341 等&#xff0c;采用 I2C 接口。 这些控制器能够支持多点触控&#xff0c;并具有优秀的灵敏度和响应速度。 Ilitek 的触摸屏控制器监测屏幕上的触摸事件。 当触摸发生时&am…...

C++ 越来越像函数式编程了!

C 越来越像函数式编程了 大家好&#xff0c;欢迎来到今天的博客话题。今天我们要聊的是 C 这门老牌的强类型语言是如何一步一步向函数式编程靠拢的。从最早的函数指针&#xff0c;到函数对象&#xff08;Functor&#xff09;&#xff0c;再到 std::function 和 std::bind&…...

maven工程结构说明

1、maven工程文件目录 |-- pom.xml # Maven 项目管理文件 |-- src # 放项目源文件|-- main # 项目主要代码| |-- java # Java 源代码目录| | -- com/example/myapp…...

【GESP】C++一级真题练习(202312)luogu-B3921,小杨的考试

GESP一级真题练习。为2023年12月一级认证真题。逻辑计算问题。 题目题解详见&#xff1a;【GESP】C一级真题练习(202312)luogu-B3921&#xff0c;小杨的考试 | OneCoder 【GESP】C一级真题练习(202312)luogu-B3921&#xff0c;小杨的考试 | OneCoderGESP一级真题练习。为2023…...

游戏中Dubbo类的RPC设计时的注意要点

一.消费方 1.需要使用到动态代理&#xff0c;代理指定的接口&#xff0c;这样子接口被调用时&#xff0c;就可以拿到&#xff1a;"类名 方法名参数返回值" 这些类型。 2.既然是rpc&#xff0c;那么接口被调用时&#xff0c;肯定在动态代理中会进行网络消息的发送&a…...

ARXML汽车可扩展标记性语言规范讲解

ARXML: Automotive Extensible Markup Language &#xff08;汽车可扩展标记语言&#xff09; xmlns: Xml name space &#xff08;xml 命名空间&#xff09; xsd: Xml Schema Definition (xml 架构定义) 1、XML与HTML的区别&#xff0c;可扩展。 可扩展&#xff0c;主要是…...

Hadoop(HDFS)

Hadoop是一个开源的分布式系统架构&#xff0c;旨在解决海量数据的存储和计算问题&#xff0c;Hadoop的核心组件包括Hadoop分布式文件系统&#xff08;HDFS&#xff09;、MapReduce编程模型和YARN资源管理器,最近需求需要用到HDFS和YARN。 文章目录 HDFS优缺点HDFS的读写原理 常…...

机器学习系列----梯度下降算法

梯度下降算法&#xff08;Gradient Descent&#xff09;是机器学习和深度学习中最常用的优化算法之一。无论是在训练神经网络、线性回归模型&#xff0c;还是其他类型的机器学习模型时&#xff0c;梯度下降都是不可或缺的一部分。它的核心目标是最小化一个损失函数&#xff08;…...

AI大模型:软件开发的未来之路

随着AI技术的快速发展&#xff0c;AI大模型正在对软件开发流程产生深远的影响。从代码自动生成到智能测试&#xff0c;AI大模型正在重塑软件开发的各个环节&#xff0c;为软件开发者、企业和整个产业链带来新的流程和模式变化。 首先&#xff0c;AI大模型的定义是指通过大规模…...

指标+AI+BI:构建数据分析新范式丨2024袋鼠云秋季发布会回顾

10月30日&#xff0c;袋鼠云成功举办了以“AI驱动&#xff0c;数智未来”为主题的2024年秋季发布会。大会深度探讨了如何凭借 AI 实现新的飞跃&#xff0c;重塑企业的经营管理方式&#xff0c;加速数智化进程。 作为大会的重要环节之一&#xff0c;袋鼠云数栈产品经理潮汐带来了…...

2024年第四届“网鼎杯”网络安全比赛---朱雀组Crypto- WriteUp

2024年第四届“网鼎杯”网络安全比赛---朱雀组Crypto-WriteUp Crypto&#xff1a;Crypto-2&#xff1a;Crypto-3&#xff1a; 前言&#xff1a;本次比赛已经结束&#xff0c;用于赛后复现&#xff0c;欢迎大家交流学习&#xff01; Crypto&#xff1a; Crypto-2&#xff1a; …...

关于Markdown的一点疑问,为什么很多人说markdown比word好用?

markdown和word压根不是一类工具&#xff0c;不存在谁比谁好&#xff0c;只是应用场景不一样。 你写博客、写readme肯定得markdown&#xff0c;但写合同、写简历肯定word更合适。 markdown和word类似邮箱和微信的关系&#xff0c;这两者都可以通信&#xff0c;但微信因为功能…...

NoSQL大数据存储技术测试(1)绪论

写在前面&#xff1a;未完成测试的同学&#xff0c;请先完成测试&#xff0c;此博文供大家复习使用&#xff0c;&#xff08;我的答案&#xff09;均为正确答案&#xff0c;大家可以放心复习 单项选择题 第1题 以下不属于云计算部署模型的是&#xff08; &#xff09; 公…...

Linux命令学习,git命令

Linux系统&#xff0c;Git是一个强大的版本管理系统&#xff0c;允许用户跟踪代码的更改、管理项目历史以及与他人协作。 Linux Git命令&#xff1a; 初始化仓库:当前目录创建一个Git仓库&#xff0c;生成.git隐藏目录存储版本历史和其他Git相关的元数据。 git init 克隆仓库…...

【AI大模型】Transformer中的编码器详解,小白必看!!

前言 Transformer中编码器的构造和运行位置如下图所示&#xff0c;其中编码器内部包含多层&#xff0c;对应下图encoder1…encoder N&#xff0c;每个层内部又包含多个子层&#xff1a;多头自注意力层、前馈神经网络层、归一化层&#xff0c;而最关键的是多头自注意力层。 自注…...

PostgreSQL 字段按逗号分隔成多条数据的技巧与实践 ️

全文目录&#xff1a; 开篇语前言 &#x1f4da;1. PostgreSQL 字段拆分的基本概念 &#x1f3af;2. 使用 string_to_array 函数拆分字段 &#x1f4ac;示例&#xff1a;使用 string_to_array 拆分字段结果&#xff1a; 3. 使用 unnest 和 string_to_array 结合拆分 &#x1f5…...

设计模式学习总结(一)

设计模式学习笔记 面向对象、设计原则、设计模式、编程规范、重构之间的关系 面向对象、设计原则、设计模式、编程规范、重构之间的关系 面向对象 现在&#xff0c;主流的编程范式或者是编程风格有三种&#xff1a;面向过程、面向对象和函数式编程。 需要掌握七大知识点&#…...

软考中级 软件设计师 上午考试内容笔记(个人向)Part.1

软考上午考试内容 1. 计算机系统 计算机硬件通过高/低电平来模拟1/0信息&#xff1b;【p进制】&#xff1a; K n K n − 1 . . . K 2 K 1 K 0 K − 1 K − 2... K − m K n r n . . . K 1 r 1 K 0 r 0 K − 1 r − 1 . . . K − m r − m K_nK_{n-1}...K_2K_1K_0K…...

PHP API的数据交互类型设计

PHP API的数据交互类型设计涉及多个方面&#xff0c;包括请求方法、数据格式、安全性考虑等。以下是对PHP API数据交互类型设计的详细探讨&#xff1a; 一、请求方法 在PHP API中&#xff0c;常见的请求方法包括GET、POST、PUT、DELETE等。这些方法在数据交互中各有其用途和特…...

【EFK】Linux集群部署Elasticsearch最新版本8.x

【EFK】Linux集群部署Elasticsearch最新版本8.x 摘要环境准备环境信息系统初始化启动先决条件 下载&安装修改elasticsearch.yml控制台启动Linux服务启动访问验证查看集群信息查看es健康状态查看集群节点查询集群状态 生成service token验证service tokenIK分词器下载 摘要 …...

【大数据测试 Elasticsearch — 详细教程及实例】

大数据测试 Elasticsearch — 详细教程及实例 1. Elasticsearch 基础概述核心概念 2. 搭建 Elasticsearch 环境2.1 安装 Elasticsearch2.2 配置 Elasticsearch 3. 大数据测试的常见方法3.1 使用 Logstash 导入大数据3.2 使用 Elasticsearch 的 Bulk API3.3 使用 Benchmark 工具…...

用ArkTS写一个登录页面(实现简单的逻辑)

登录页面 1.登录页面编码 Extend(TextInput) function customStyle(){.backgroundColor(#fff).border({width:{bottom:0.5},color:#e4e4e4}).borderRadius(1) //让圆角不明显.placeholderColor(#c3c3c5).caretColor(#fa711d) //input获取焦点样式 }Entry Component struct Log…...

matlab将INCA采集的dat文件多个变量批量读取到excel中

参考资料&#xff1a; MATLAB处理INCA采集数据&#xff08;mdf&#xff0c;dat等&#xff09;一 使用matlab处理INCF采集数据&#xff0c;mdf&#xff08;.dat&#xff09;格式文件&#xff0c;并将将其写入excel文件 这个资料只能一个变量一个变量的提取&#xff0c;本对其进…...

list集合常见去重方式以及效率对比

1.概述 list集合去重是开发中比较常用的操作&#xff0c;在面试中也会经常问到&#xff0c;那么list去重都有哪些方式&#xff1f;他们之间又该如何选择呢&#xff1f; 本文将通过LinkedHashSet、for循环、list流toSet、list流distinct等4种方式分别做1W数据到1000W数据单元测试…...

JavaWeb——Web入门(7/9)-Tomcat-介绍(Tomcat 的简介:轻量级Web服务器,支持Servlet/JSP少量JavaEE规范)

目录 Web服务器的作用 三个方面的讲解 Tomcat 的简介 小结 Web服务器的作用 封装 HTTP 协议操作&#xff1a;Web服务器是一个软件程序&#xff0c;对 HTTP 协议的操作进行了封装。这样开发人员就不需要再直接去操作 HTTP 协议&#xff0c;使得外部应用程序的开发更加便捷、…...