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

What is the encapsulation of Spring-Data-Jpa crud and JQuery utility classes

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

What is the encapsulation of Spring-Data-Jpa crud and JQuery tool classes? in view of this problem, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Spring-Data-Jpa crud:

Create a business logic framework:

Create API under org.ramer.demo: service.UserService, and the corresponding implementation class service.impl.UserServiceImpl

UserService.java:

UserServiceImpl.java:

UserRepository.java:

Here are some things to pay attention to:

The difference between userRepository getOne and findOne: the method description is clear: the former returns an object and the latter returns a reference to an object. In general, it can be generic, but if the entity of a given id does not exist, using getOne will throw an exception.

UserRepository already has a delete (Integer id) method by default, but it is recommended to implement it yourself. Because the default method will first query the corresponding entity of the id, and then perform the deletion. There will be one more query statement, which is not necessary here.

Specify a collation using new Sort (Sort.Direction.ASC, "id")

Page is the page number, and the first page is 0. 0.

CommonController.java:

The above completed the background of the addition, deletion, modification and search. Please check the source code for the display and operation on the page.

JQuery tool class encapsulation (JQuery closure): encapsulate the commonly used code into a separate js file to simplify and reuse the code.

Create a JQuery closure as follows:

$.functionName: extend JQuery by calling: $.functionName (opts)

$.fn.functionName: extends the JQuery object by calling $(selector) .functionName (opts)

Parameter automatic override:

Opts is the user parameter. Use opts | {}, which means that if the user passes a given parameter value, it will be used, otherwise the default parameter value will be used.

Writing in the body of a method is the same as ordinary external js code.

This is the answer to the question about the encapsulation of Spring-Data-Jpa crud and JQuery tools. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

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