Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How SpringBoot integrates Gradle+Spring Data JPA Development

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how SpringBoot integrates Gradle+Spring Data JPA development, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

The first step to create a project

1.1 if you have not created a project using idea, the new project steps should look like the following figure

1.2 if you have created a project, the new project steps should look like the following figure

1.3 create a new SpringBoot project

The specific creation steps are shown below.

1.3.2 fill in the project details, as shown in the following figure

After clicking Next, select the project to initialize jar

After clicking Next, select our project directory and confirm the project name

Click Finish may appear the following prompt, do not worry, click Ok, this is a prompt to tell us that this file has not been found whether to create or not

After clicking ok, you will enter our idea editor and a prompt box will pop up. Don't worry, just click ok.

After clicking ok, Gradle will automatically download the required jar package. After waiting for the jar package to be downloaded, our project will be completed. The following figure shows a detailed description of the main directory of the project, in which the test file is usually used when writing unit tests, so we will not introduce it because we do not need it for the time being.

The second step is to add the dependencies required by Gradle

The specific dependencies used are shown in the following figure

Step 3: create a three-tier directory

The specific names of the three layers are shown in the following figure

Step 4 hierarchical development

First of all, let's create the entity class-- User

First add lombok annotations in turn (omitting a lot of get set methods)

@ Getter

@ Setter

Then add the comments used in our JPA entity class mapping table

@ Entity

@ Table

Then inherit our public parameter class in the user entity class

Public class User extends BaseEntity {

This is followed by defining the fields we need to use.

/ * *

* Primary key identification

, /

@ Id / / Mark that this field maps to the primary key in the database

@ GeneratedValue (strategy = GenerationType.IDENTITY)

/ / @ GeneratedValue primary key generation strategy, this article adopts self-growth strategy (IDENTITY)

Private Integer id

/ * *

* Real name

, /

@ Column (length = 30) / / length 30

/ / in this article, we use @ Column to restrict fields in the database.

Private String name

/ * *

* ID card number

, /

@ Column (length = 30) / / length 30

Private String idCard

...

And then we write our dao layer.

Need to define comments

@ Repository

And inheritance.

Extends PagingAndSortingRepository

Otherwise, there is no way to use encapsulated query methods (find), save (save), delete (deleteById), etc.

Service and controller are completely consistent with the previously familiar development patterns, and there is nothing special about them. This article will not be reviewed.

These are all the contents of the article "how SpringBoot integrates Gradle+Spring Data JPA Development". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report