In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to create a federated index in Spring DataJpa". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to create a federated index by Spring DataJpa".
SpringDataJpa creates federated index
Create a joint index corresponding class / * author: guoyzh * time: 14:58 on 2019-12-30 * function: eyeglass vision review joint primary key * / @ Data@Embeddablepublic class VisualReexaminationUnionKey implements Serializable {@ Column (name = "id") private String id; @ Column (name = "c_review_date") private java.sql.Timestamp cReviewDate } create a mapped entity class @ Table (name = "qy_visual_reexamination") @ Entity@Datapublic class QyVisualReexamination {/ * @ Id @ Column (nullable = true, name = "id") private String id; @ Id @ Column (nullable = true, name = "c_review_date") private java.sql.Timestamp cReviewDate;*/ compound primary key @ EmbeddedId private VisualReexaminationUnionKey id; @ Column (nullable = true, name = "c_clientid") private String cClientid @ Column (nullable = true, name = "c_ygscode") private String cYgscode; @ Column (nullable = true, name = "c_primary_vision_r") private String cPrimaryVisionR; @ Column (nullable = true, name = "c_primary_vision_l") private String cPrimaryVisionL; @ Column (nullable = true, name = "c_ball_r") private String cBallR; @ Column (nullable = true, name = "c_ball_l") private String cBallL @ Column (nullable = true, name = "c_pole_r") private String cPoleR; @ Column (nullable = true, name = "c_pole_l") private String cPoleL; @ Column (nullable = true, name = "c_axes_r") private String cAxesR; @ Column (nullable = true, name = "c_axes_l") private String cAxesL; @ Column (nullable = true, name = "c_add_r") private String cAddR @ Column (nullable = true, name = "c_add_l") private String cAddL; @ Column (nullable = true, name = "c_check_r") private String cCheckR; @ Column (nullable = true, name = "c_check_l") private String cCheckL; @ Column (nullable = true, name = "c_proposal") private String cProposal; @ Column (nullable = true, name = "c_com") private String cCom } add new data @ Overridepublic Object addVisualReexamination (String id, String clientId, String reviewDate, String ygsCode, String primaryVisionR, String primaryVisionL, String ballR, String ballL, String poleR, String poleL, String axesR, String axesL, String addR, String addL, String checkR, String checkL, String proposal, String comId) {QyVisualReexamination bean = new QyVisualReexamination () / / generate a joint index VisualReexaminationUnionKey unionId = new VisualReexaminationUnionKey (); unionId.setCReviewDate (Timestamp.valueOf (reviewDate)); unionId.setId (id); bean.setId (unionId); bean.setCClientid (clientId); bean.setCYgscode (ygsCode); bean.setCPrimaryVisionR (primaryVisionR); bean.setCPrimaryVisionL (primaryVisionL); bean.setCBallR (ballR); bean.setCBallL (ballL); bean.setCPoleR (poleR); bean.setCPoleL (poleL) Bean.setCAxesR (axesR); bean.setCAxesL (axesL); bean.setCAddR (addR); bean.setCAddL (addL); bean.setCCom (comId); bean.setCCheckR (checkR); bean.setCCheckL (checkL); bean.setCProposal (proposal); QyVisualReexamination save = mQyVisualReexaminationDao.save (bean); return save.getId ();} SpringDataJpa specifies the federated index
How, now that I use order ID and product ID as the unique index in my table, I need to define the table entity class when defining
Specify UniqueConstraintimport lombok.AllArgsConstructor;import lombok.Getter;import lombok.NoArgsConstructor;import lombok.Setter;import javax.persistence.*;/** * product table * * @ author wulinfeng * @ since 2019-12-13 * / @ Entity@Table (name = "t_product", uniqueConstraints = @ UniqueConstraint (columnNames = {"orderId", "productId"})) @ Getter@Setter@AllArgsConstructor@NoArgsConstructorpublic class ProductItem {@ Id @ GeneratedValue (strategy = GenerationType.IDENTITY) private Long id in @ Table / / order Id @ Column (nullable = false, length = 32) private String orderId; / / accepted Product Code @ Column (length = 32) private String productId; / / Product name @ Column (length = 32) private String productName; / / timestamp @ Column (length = 13) private Long timest}
Drop off the original t_product table, restart spring boot, and then look at the table
Automatically add a unique index mysql > show index from t_product +- -+-+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +- -+ -+ | t_product | 0 | PRIMARY | 1 | id | A | 2 | NULL | NULL | | BTREE | | | | t_product | 0 | UK1mvw2lcd07t4cuicl4awfbgkw | 1 | order_id | A | 2 | NULL | NULL | | BTREE | | t_product | 0 | UK1mvw2lcd07t4cuicl4awfbgkw | 2 | product_id | A | 2 | NULL | NULL | YES | BTREE | | | +-- -+-+ 3 rows in set (0.00 sec) so far I believe you have a deeper understanding of "how to create federated indexes in Spring DataJpa", so you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.