欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解spring boot rest例子

 更新時(shí)間:2018年03月20日 10:02:39   作者:不知道該說(shuō)啥  
這篇文章主要介紹了詳解spring boot rest例子,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

簡(jiǎn)介:本文將幫助您使用 Spring Boot 創(chuàng)建簡(jiǎn)單的 REST 服務(wù)。

你將學(xué)習(xí)

  1. 什么是 REST 服務(wù)?
  2. 如何使用 Spring Initializr 引導(dǎo)創(chuàng)建 Rest 服務(wù)應(yīng)用程序?
  3. 如何創(chuàng)建獲取 REST 服務(wù)以檢索學(xué)生注冊(cè)的課程?
  4. 如何為學(xué)生注冊(cè)課程創(chuàng)建 Post REST 服務(wù)?
  5. 如何利用 postman 執(zhí)行 rest 服務(wù)?

本教程使用的 rest 服務(wù)

在本教程中,我們將使用適當(dāng)?shù)?URI 和 HTTP 方法創(chuàng)建三個(gè)服務(wù):

@GetMapping(“/ students / {studentId} / courses”):您可以使用請(qǐng)求方法 Get 和示例 uri / students / Student1 / courses 來(lái)查詢特定學(xué)生已注冊(cè)的課程。

@GetMapping(“/students/{studentId}/courses/{courseId}”):您可以使用請(qǐng)求方法 Get 和示例 uri / students / Student1 / courses / Course1 獲取特定學(xué)生的特定課程。

@PostMapping(“/students/{studentId}/courses”) :您可以通過(guò)向 UURI /students/Student1/courses 發(fā)送 POST 請(qǐng)求來(lái)為學(xué)生注冊(cè)一門課程

您將需要的工具

  1. Maven 3.0+ 是您的構(gòu)建工具
  2. 你最喜歡的 IDE。我們使用 Eclipse。
  3. JDK 1.8+

 完整的 spring booot rest Maven 項(xiàng)目代碼示例子

我們的 Github 存儲(chǔ)庫(kù)包含所有代碼示例 - https://github.com/in28minutes/in28minutes.github.io/tree/master/code-zip-files

帶有單元和集成測(cè)試的 REST 服務(wù)

Website-springbootrestservices-simplerestserviceswithunitandintegrationtests.zip

 什么是 REST?

REST 代表 REpresentational State Transfer。REST 指定了一組體系結(jié)構(gòu)約束。任何滿足以下這些條件的服務(wù)都稱為 RESTful 服務(wù)。

RESTful Web Service 的五個(gè)重要條件:

  1. 客戶端 - 服務(wù)器:應(yīng)該有一個(gè)服務(wù)生產(chǎn)者和一個(gè)服務(wù)使用者。
  2. 接口(URL)是統(tǒng)一的并且暴露資源。
  3. 該服務(wù)是無(wú)狀態(tài)的。
  4. 服務(wù)結(jié)果應(yīng)該是可緩存的。例如 HTTP 緩存。
  5. 服務(wù)應(yīng)該采用分層架構(gòu)??蛻舳瞬粦?yīng)該直接連接到服務(wù)器 - 它可能從中間層獲取信息 - 緩存。

 理查森成熟度模型

Richardson 成熟度模型用于識(shí)別 Restful Web Service 的成熟度級(jí)別。以下是不同級(jí)別和特點(diǎn):

級(jí)別 0:以 REST 風(fēng)格公開(kāi) SOAP Web 服務(wù)。公開(kāi)的操作使用 REST 服務(wù)(http:// server / getPosts,http:// server / deletePosts,http:// server / doThis,http:// server / doThat 等)。

級(jí)別 1:使用正確的 URI(使用名詞)公開(kāi)資源。例如:http:// server / accounts,http:// server / accounts / 10。但是,HTTP 方法并未使用。

級(jí)別 2:資源使用正確的 URI + HTTP 方法。例如,要更新一個(gè)賬戶,你需要做一個(gè) PUT。創(chuàng)建一個(gè)帳戶,你做一個(gè) POST。Uri 看起來(lái)像 posts/1/comments/5 和 accounts/1/friends/1.

等級(jí) 3:HATEOAS (Hypermedia as the engine of application state)。您不僅可以了解所請(qǐng)求的信息,還可以了解服務(wù)消費(fèi)者可以采取的下一個(gè)可能的操作。當(dāng)請(qǐng)求有關(guān) Facebook 用戶的信息時(shí),REST 服務(wù)可以返回用戶詳細(xì)信息以及有關(guān)如何獲取他最近的帖子,如何獲取他最近的評(píng)論以及如何檢索他朋友的列表的信息。

使用適當(dāng)?shù)恼?qǐng)求方法

始終使用 HTTP 方法。有關(guān)每種 HTTP 方法的最佳做法如下所述:

GET:不應(yīng)該更新任何東西。應(yīng)該是冪等的(多次調(diào)用相同的結(jié)果)??赡艿姆祷卮a 200(OK)+ 404(NOT FOUND)+400(BAD REQUEST)

POST:應(yīng)該創(chuàng)建新的資源。理想情況下返回 JSON 和鏈接到新創(chuàng)建的資源。盡可能使用相同的返回碼。另外:返回碼 201(創(chuàng)建)是可能的。

PUT:更新已知資源。例如:更新客戶詳細(xì)信息??赡艿姆祷卮a:200(OK)

DELETE:用于刪除資源。

項(xiàng)目結(jié)構(gòu)

以下屏幕截圖顯示了我們將創(chuàng)建的項(xiàng)目的結(jié)構(gòu)。

一些細(xì)節(jié):

  1. StudentController.java - rest 控制器提供上面討論的所有三種服務(wù)方法。
  2.  Course.java, Student.java, StudentService.java - 應(yīng)用程序的業(yè)務(wù)邏輯。StudentService 提供了一些我們從 Rest 控制器中消耗的方法。
  3. StudentControllerIT.java - rest 服務(wù)的集成測(cè)試。
  4. StudentControllerTest.java - test 服務(wù)的單元測(cè)試。
  5. StudentServicesApplication.java - Spring Boot 應(yīng)用程序的啟動(dòng)器。要運(yùn)行該應(yīng)用程序,只需將該文件作為 Java 應(yīng)用程序啟動(dòng)。
  6. pom.xml - 包含構(gòu)建此項(xiàng)目所需的所有依賴。我們將使用 Spring Boot Starter Web。

使用 Spring Initializr 引導(dǎo)創(chuàng)建 REST 服務(wù)

用 Spring Initializr 創(chuàng)建一個(gè) REST 服務(wù)是非常的容易小菜一碟。我們將使用 Spring Web MVC 作為我們的 web 層框架。

Spring Initializr http://start.spring.io/ 是引導(dǎo)創(chuàng)建 Spring Boot 項(xiàng)目的好工具。

如上圖所示,必須執(zhí)行以下步驟

啟動(dòng) Spring Initializr 并選擇以下內(nèi)容

選擇 com.in28minutes.springboot 為 Group

選擇 student-services 為 Artifact

選擇以下依賴項(xiàng)

  1.  Web
  2. Actuator
  3. DevTools

點(diǎn)擊生成項(xiàng)目。

將項(xiàng)目導(dǎo)入 Eclipse。文件 - > 導(dǎo)入 - > 現(xiàn)有的 Maven 項(xiàng)目。

如果你想了解這個(gè)項(xiàng)目的所有文件,你可以繼續(xù)向下閱讀。

應(yīng)用業(yè)務(wù)層實(shí)現(xiàn)

所有應(yīng)用都需要數(shù)據(jù)。我們將使用 ArrayList 這種內(nèi)存數(shù)據(jù)存儲(chǔ),而不是與真實(shí)數(shù)據(jù)庫(kù)交互。

一名學(xué)生可以參加多門課程。課程有一個(gè) ID,名稱,說(shuō)明和完成課程需要完成的步驟列表。學(xué)生有一個(gè)身份證,姓名,說(shuō)明和他 / 她目前注冊(cè)的課程列表。StudentService 提供以下公開(kāi)方法

public List retrieveAllStudents() - 檢索所有學(xué)生的詳細(xì)信息

public Student retrieveStudent(String studentId) - 檢索特定的學(xué)生詳細(xì)信息

public List retrieveCourses(String studentId) - 檢索學(xué)生注冊(cè)的所有課程

public Course retrieveCourse(String studentId, String courseId) - 檢索學(xué)生注冊(cè)的特定課程的詳細(xì)信息

public Course addCourse(String studentId, Course course) - 為現(xiàn)有學(xué)生添加課程

請(qǐng)參閱下面這些文件,具體的實(shí)現(xiàn)服務(wù)類 StudentService 和模型類 Course 和 Student。

  1. src/main/java/com/in28minutes/springboot/model/Course.java
  2. src/main/java/com/in28minutes/springboot/model/Student.java
  3. src/main/java/com/in28minutes/springboot/service/StudentService.java

添加幾個(gè) GET Rest 服務(wù)

Rest 服務(wù) StudentController 暴露了幾個(gè) get 服務(wù)。

  1. @Autowired private StudentService studentService :我們使用 Spring Autowiring 將 student 服務(wù)自動(dòng)注入到 StudentController。
  2. @GetMapping(“/students/{studentId}/courses”):以 studentId 作為路徑變量公開(kāi)獲取服務(wù)
  3.  @GetMapping(“/students/{studentId}/courses/{courseId}”):公開(kāi)獲取服務(wù)以檢索學(xué)生的特定課程。
  4. @PathVariable String studentId:來(lái)自 uri 的 studentId 的值將映射到此參數(shù)。
package com.in28minutes.springboot.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import com.in28minutes.springboot.model.Course;
import com.in28minutes.springboot.service.StudentService;
@RestController
public class StudentController {

	@Autowired
	private StudentService studentService;

	@GetMapping("/students/{studentId}/courses")
	public List<Course> retrieveCoursesForStudent(@PathVariable String studentId) {
		return studentService.retrieveCourses(studentId);
	}
	
	@GetMapping("/students/{studentId}/courses/{courseId}")
	public Course retrieveDetailsForCourse(@PathVariable String studentId,
			@PathVariable String courseId) {
		return studentService.retrieveCourse(studentId, courseId);
	}
}

使用 Postman 執(zhí)行獲取服務(wù)

我們將向 http:// localhost:8080 / students / Student1 / courses / Course1 發(fā)起請(qǐng)求以測(cè)試該服務(wù)?;貞?yīng)如下所示。

{
 "id": "Course1",
 "name": "Spring",
 "description": "10 Steps",
 "steps": [
  "Learn Maven",
  "Import Project",
  "First Example",
  "Second Example"
 ]
}

下面的圖片顯示了我們?nèi)绾螆?zhí)行 Postman 的 Get Service - 我最喜歡的運(yùn)行 rest 服務(wù)的工具。

 

添加 POST Rest 服務(wù)

當(dāng)資源創(chuàng)建成功時(shí),POST 服務(wù)應(yīng)該返回創(chuàng)建的狀態(tài)(201)。

  1. @PostMapping(“/students/{studentId}/courses”):為 POST 請(qǐng)求映射 URL
  2. @RequestBody Course newCourse:使用綁定將請(qǐng)求正文綁定到課程對(duì)象。
  3. ResponseEntity.created(location).build():返回已創(chuàng)建的狀態(tài)。還將創(chuàng)建資源的位置作為響應(yīng)標(biāo)題返回。
@PostMapping("/students/{studentId}/courses")
	public ResponseEntity<Void> registerStudentForCourse(
			@PathVariable String studentId, @RequestBody Course newCourse) {

		Course course = studentService.addCourse(studentId, newCourse);
		if (course == null)
			return ResponseEntity.noContent().build();
		URI location = ServletUriComponentsBuilder.fromCurrentRequest().path(
				"/{id}").buildAndExpand(course.getId()).toUri();
		return ResponseEntity.created(location).build();
	}

執(zhí)行 POST Rest 服務(wù)

示例請(qǐng)求如下所示。它包含了學(xué)生注冊(cè)課程的所有細(xì)節(jié)。

{
 "name": "Microservices",
 "description": "10 Steps",
 "steps": [
  "Learn How to Break Things Up",
  "Automate the hell out of everything",
  "Have fun"
 ]
}

下圖顯示了我們?nèi)绾螐?Postman 執(zhí)行 Post 服務(wù) - 我最喜歡的運(yùn)行 rest 服務(wù)的工具。確保你去 Body 選項(xiàng)卡并選擇 raw。從下拉菜單中選擇 JSON。將上述請(qǐng)求復(fù)制到 body 中。

我們使用的 URL 是 http:// localhost:8080 / students / Student1 / courses。

完整的代碼示例

pom.xml

<?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.in28minutes.springboot</groupId>
	<artifactId>student-services</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>student-services</name>
	<description>Demo project for Spring Boot</description>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.4.4.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>
</project>

src/main/java/com/in28minutes/springboot/controller/StudentController.java

import java.net.URI;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import com.in28minutes.springboot.model.Course;
import com.in28minutes.springboot.service.StudentService;

@RestController
public class StudentController {

	@Autowired
	private StudentService studentService;

	@GetMapping("/students/{studentId}/courses")
	public List<Course> retrieveCoursesForStudent(@PathVariable String studentId) {
		return studentService.retrieveCourses(studentId);
	}
	
	@GetMapping("/students/{studentId}/courses/{courseId}")
	public Course retrieveDetailsForCourse(@PathVariable String studentId,
			@PathVariable String courseId) {
		return studentService.retrieveCourse(studentId, courseId);
	}
	
	@PostMapping("/students/{studentId}/courses")
	public ResponseEntity<Void> registerStudentForCourse(
			@PathVariable String studentId, @RequestBody Course newCourse) {

		Course course = studentService.addCourse(studentId, newCourse);

		if (course == null)
			return ResponseEntity.noContent().build();

		URI location = ServletUriComponentsBuilder.fromCurrentRequest().path(
				"/{id}").buildAndExpand(course.getId()).toUri();

		return ResponseEntity.created(location).build();
	}
}

src/main/java/com/in28minutes/springboot/model/Course.java

import java.util.List;
public class Course {
	private String id;
	private String name;
	private String description;
	private List<String> steps;

	// Needed by Caused by: com.fasterxml.jackson.databind.JsonMappingException:
	// Can not construct instance of com.in28minutes.springboot.model.Course:
	// no suitable constructor found, can not deserialize from Object value
	// (missing default constructor or creator, or perhaps need to add/enable
	// type information?)
	public Course() {

	}

	public Course(String id, String name, String description, List<String> steps) {
		super();
		this.id = id;
		this.name = name;
		this.description = description;
		this.steps = steps;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getDescription() {
		return description;
	}

	public String getName() {
		return name;
	}

	public List<String> getSteps() {
		return steps;
	}

	@Override
	public String toString() {
		return String.format(
				"Course [id=%s, name=%s, description=%s, steps=%s]", id, name,
				description, steps);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Course other = (Course) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
}

src/main/java/com/in28minutes/springboot/model/Student.java

package com.in28minutes.springboot.model;

import java.util.List;

public class Student {
	private String id;
	private String name;
	private String description;
	private List<Course> courses;

	public Student(String id, String name, String description,
			List<Course> courses) {
		super();
		this.id = id;
		this.name = name;
		this.description = description;
		this.courses = courses;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<Course> getCourses() {
		return courses;
	}

	public void setCourses(List<Course> courses) {
		this.courses = courses;
	}

	@Override
	public String toString() {
		return String.format(
				"Student [id=%s, name=%s, description=%s, courses=%s]", id,
				name, description, courses);
	}
}

src/main/java/com/in28minutes/springboot/service/StudentService.java

package com.in28minutes.springboot.service;

import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springframework.stereotype.Component;

import com.in28minutes.springboot.model.Course;
import com.in28minutes.springboot.model.Student;

@Component
public class StudentService {

	private static List<Student> students = new ArrayList<>();

	static {
		//Initialize Data
		Course course1 = new Course("Course1", "Spring", "10 Steps", Arrays
				.asList("Learn Maven", "Import Project", "First Example",
						"Second Example"));
		Course course2 = new Course("Course2", "Spring MVC", "10 Examples",
				Arrays.asList("Learn Maven", "Import Project", "First Example",
						"Second Example"));
		Course course3 = new Course("Course3", "Spring Boot", "6K Students",
				Arrays.asList("Learn Maven", "Learn Spring",
						"Learn Spring MVC", "First Example", "Second Example"));
		Course course4 = new Course("Course4", "Maven",
				"Most popular maven course on internet!", Arrays.asList(
						"Pom.xml", "Build Life Cycle", "Parent POM",
						"Importing into Eclipse"));

		Student ranga = new Student("Student1", "Ranga Karanam",
				"Hiker, Programmer and Architect", new ArrayList<>(Arrays
						.asList(course1, course2, course3, course4)));

		Student satish = new Student("Student2", "Satish T",
				"Hiker, Programmer and Architect", new ArrayList<>(Arrays
						.asList(course1, course2, course3, course4)));

		students.add(ranga);
		students.add(satish);
	}

	public List<Student> retrieveAllStudents() {
		return students;
	}

	public Student retrieveStudent(String studentId) {
		for (Student student : students) {
			if (student.getId().equals(studentId)) {
				return student;
			}
		}
		return null;
	}

	public List<Course> retrieveCourses(String studentId) {
		Student student = retrieveStudent(studentId);

		if (student == null) {
			return null;
		}

		return student.getCourses();
	}

	public Course retrieveCourse(String studentId, String courseId) {
		Student student = retrieveStudent(studentId);

		if (student == null) {
			return null;
		}

		for (Course course : student.getCourses()) {
			if (course.getId().equals(courseId)) {
				return course;
			}
		}

		return null;
	}

	private SecureRandom random = new SecureRandom();

	public Course addCourse(String studentId, Course course) {
		Student student = retrieveStudent(studentId);

		if (student == null) {
			return null;
		}

		String randomId = new BigInteger(130, random).toString(32);
		course.setId(randomId);

		student.getCourses().add(course);

		return course;
	}
}

src/main/java/com/in28minutes/springboot/StudentServicesApplication.java

package com.in28minutes.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class StudentServicesApplication {

	public static void main(String[] args) {
		SpringApplication.run(StudentServicesApplication.class, args);
	}
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java數(shù)組反轉(zhuǎn)方式

    Java數(shù)組反轉(zhuǎn)方式

    這篇文章主要介紹了Java數(shù)組反轉(zhuǎn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-06-06
  • Java  Object類中的常用API介紹

    Java  Object類中的常用API介紹

    這篇文章主要介紹了Java  Object類中的常用API介紹,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-11-11
  • springBoot+mybatis-plus實(shí)現(xiàn)監(jiān)聽(tīng)mysql數(shù)據(jù)庫(kù)的數(shù)據(jù)增刪改

    springBoot+mybatis-plus實(shí)現(xiàn)監(jiān)聽(tīng)mysql數(shù)據(jù)庫(kù)的數(shù)據(jù)增刪改

    mybatis-plus技術(shù)是簡(jiǎn)化了繁瑣的代碼操作,把增刪改查的語(yǔ)句都內(nèi)置了,直接調(diào)用就可以實(shí)現(xiàn)數(shù)據(jù)庫(kù)的增刪改查了,這篇文章主要給大家介紹了關(guān)于springBoot+mybatis-plus實(shí)現(xiàn)監(jiān)聽(tīng)mysql數(shù)據(jù)庫(kù)數(shù)據(jù)增刪改的相關(guān)資料,需要的朋友可以參考下
    2024-01-01
  • java實(shí)戰(zhàn)案例之用戶注冊(cè)并發(fā)送郵件激活/發(fā)送郵件驗(yàn)證碼

    java實(shí)戰(zhàn)案例之用戶注冊(cè)并發(fā)送郵件激活/發(fā)送郵件驗(yàn)證碼

    現(xiàn)在很多的網(wǎng)站都提供有用戶注冊(cè)功能,當(dāng)我們注冊(cè)成功之后就會(huì)收到封注冊(cè)網(wǎng)站的郵件,郵件里包含了我們的注冊(cè)的用戶名和密碼及激活賬戶的超鏈接等信息,這篇文章主要給大家介紹了關(guān)于java實(shí)戰(zhàn)案例之用戶注冊(cè)并發(fā)送郵件激活/發(fā)送郵件驗(yàn)證碼的相關(guān)資料,需要的朋友可以參考下
    2021-09-09
  • Java雪花算法的原理和實(shí)現(xiàn)方法

    Java雪花算法的原理和實(shí)現(xiàn)方法

    這篇文章主要介紹了Java雪花算法的原理和實(shí)現(xiàn)方法,雪花算法是一種分布式唯一ID生成算法,可以生成全局唯一的ID標(biāo)識(shí)符,就像自然界中雪花一般沒(méi)有相同的雪花,下面將詳細(xì)介紹,感興趣的可以學(xué)習(xí)一下
    2023-10-10
  • jdbc結(jié)合dpcp連接池的封裝實(shí)例

    jdbc結(jié)合dpcp連接池的封裝實(shí)例

    下面小編就為大家?guī)?lái)一篇jdbc結(jié)合dpcp連接池的封裝實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-10-10
  • 詳解消息隊(duì)列及RabbitMQ部署和使用

    詳解消息隊(duì)列及RabbitMQ部署和使用

    消息隊(duì)列是最古老的中間件之一,從系統(tǒng)之間有通信需求開(kāi)始,就自然產(chǎn)生了消息隊(duì)列。本文告訴什么是消息隊(duì)列,為什么需要消息隊(duì)列,常見(jiàn)的消息隊(duì)列有哪些,RabbitMQ的部署和使用
    2021-09-09
  • SpringSecurity實(shí)現(xiàn)登陸認(rèn)證并返回token方式

    SpringSecurity實(shí)現(xiàn)登陸認(rèn)證并返回token方式

    這篇文章主要介紹了SpringSecurity實(shí)現(xiàn)登陸認(rèn)證并返回token方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • SpringBoot項(xiàng)目中HTTP請(qǐng)求體只能讀一次的解決方案

    SpringBoot項(xiàng)目中HTTP請(qǐng)求體只能讀一次的解決方案

    在基于Spring開(kāi)發(fā)Java項(xiàng)目時(shí),可能需要重復(fù)讀取HTTP請(qǐng)求體中的數(shù)據(jù),例如使用攔截器打印入?yún)⑿畔⒌?但當(dāng)我們重復(fù)調(diào)用getInputStream()或者getReader()時(shí),通常會(huì)遇到SpringBoot HTTP請(qǐng)求只讀一次的問(wèn)題,本文給出了幾種解決方案,需要的朋友可以參考下
    2024-08-08
  • Lombok的@Data等注解無(wú)效的解決

    Lombok的@Data等注解無(wú)效的解決

    這篇文章主要介紹了Lombok的@Data等注解無(wú)效的解決,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11

最新評(píng)論