我如何使用@ManyToMany 在另一个类别中获得价值类别和类别产品 [英] How i get value category and categories product in another class with using @ManyToMany

查看:25
本文介绍了我如何使用@ManyToMany 在另一个类别中获得价值类别和类别产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 3 节课.

产品类别

package com.eziz.warehouse;导入 com.eziz.clients.Clients;导入 org.springframework.format.annotation.DateTimeFormat;导入 javax.persistence.*;@实体@Table(名称=产品")公共类产品{@Id@GeneratedValue(策略 = GenerationType.IDENTITY)私人长产品ID;@Column(可为空 = 假,长度 = 20)私人字符串产品名称;@ManyToOne@JoinColumn(name = "category_id")私人产品类别产品类别;@Column(可为空 = 假,长度 = 10)私人 int productCount;@DateTimeFormat(pattern = "yyyy-MM-dd")@Column(可为空 = 假)私人字符串 productDateCreated;@Column(可为空 = 假)私人双品采购价格;公共长 getProductId() {返回产品ID;}public void setProductId(Long productId) {this.productId = productId;}公共字符串 getProductName() {返回产品名称;}public void setProductName(String productName) {this.productName = productName;}公共 int getProductCount() {返回产品数量;}public void setProductCount(int productCount) {this.productCount = productCount;}公共字符串 getProductDateCreated() {返回 productDateCreated;}public void setProductDateCreated(String productDateCreated) {this.productDateCreated = productDateCreated;}公共双 getProductPurchasePrice() {返回产品购买价格;}public void setProductPurchasePrice(double productPurchasePrice) {this.productPurchasePrice = productPurchasePrice;}公共产品类别 getProductCategory() {返回产品类别;}public void setProductCategory(ProductCategory productCategory) {this.productCategory = productCategory;}@覆盖公共字符串 toString() {返回 this.productName;}}

ProductCategory 类.

package com.eziz.warehouse;导入 javax.persistence.*;导入 java.util.HashSet;导入 java.util.Set;@实体@Table(name = "productcategory")公共类产品类别{@Id@GeneratedValue(策略 = GenerationType.IDENTITY)私人 Long productCategoryId;@Column(可为空 = 假,长度 = 30)私人字符串产品类别名称;//@ManyToOne//@JoinColumn(name = "productCategory")//私有产品产品;@OneToMany(mappedBy = "productCategory")私人集<产品>产品 = 新 HashSet<>();公共长 getProductCategoryId() {返回 productCategoryId;}public void setProductCategoryId(Long productCategoryId) {this.productCategoryId = productCategoryId;}公共字符串 getProductCategoryName() {返回产品类别名称;}public void setProductCategoryName(String productCategoryName) {this.productCategoryName = productCategoryName;}//公共产品 getProduct() {//返回产品;//}////public void setProduct(Product product) {//this.product = 产品;//}公共集<产品>获取产品(){退货产品;}public void setProducts(Set products) {this.products = 产品;}}

和请求类.

package com.eziz.requestForWarehouse;导入 com.eziz.requests.Requests;导入 com.eziz.user.User;导入 com.eziz.warehouse.Product;导入 com.eziz.warehouse.ProductCategory;导入 org.springframework.format.annotation.DateTimeFormat;导入 javax.persistence.*;导入 java.util.HashSet;导入 java.util.Set;@实体@Table(name = "requestWH")公共类请求仓库{@Id@GeneratedValue(策略 = GenerationType.IDENTITY)私人长请求WHId;@Column(可为空 = 假,长度 = 10)私人 int requestWHCount;@Column(可为空 = 假,长度 = 15)私人字符串请求WHStatus;@DateTimeFormat(pattern = "yyyy-MM-dd")@Column(可为空 = 假)私人字符串 requestWHDateCreated;@DateTimeFormat(pattern = "yyyy-MM-dd")@Column(可为空 = 假)私人字符串请求WHExpiryTime;@ManyToMany@JoinColumn(name = "requestWHProductId")私人集productCategory = new HashSet<>();@ManyToOne@JoinColumn(name = "requestWHRequestId")私人请求请求;公共长 getRequestWHId() {返回请求WHId;}public void setRequestWHId(Long requestWHId) {this.requestWHId = requestWHId;}公共 int getRequestWHCount() {返回请求WHCount;}public void setRequestWHCount(int requestWHCount) {this.requestWHCount = requestWHCount;}公共字符串 getRequestWHStatus() {返回请求WHStatus;}public void setRequestWHStatus(String requestWHStatus) {this.requestWHStatus = requestWHStatus;}公共字符串 getRequestWHDateCreated() {返回请求WHDateCreated;}public void setRequestWHDateCreated(String requestWHDateCreated) {this.requestWHDateCreated = requestWHDateCreated;}公共字符串 getRequestWHExpiryTime() {返回请求WHExpiryTime;}public void setRequestWHExpiryTime(String requestWHExpiryTime) {this.requestWHExpiryTime = requestWHExpiryTime;}//公共产品类别 getProductCategory() {//返回产品类别;//}////public void setProductCategory(ProductCategory productCategory) {//this.productCategory = productCategory;//}公共集获取产品类别(){返回产品类别;}public void setProductCategory(Set productCategory) {this.productCategory = productCategory;}公共请求 getRequests() {退货要求;}公共无效setRequests(请求请求){this.requests = 请求;}}

我需要在请求中使用它,首先选择类别,然后使用选择选项选择类别产品.

html 代码:

 

<p对齐=中心"class=font-aziz">Avadanlıq/Detal Kateqoriya</p><select th:field="*{productCategory}";class="form-control un";id=产品"需要><th:block th:each="pro : ${productCategoryList}"><option th:text="${pro.productCategoryName}";th:value=${pro.productCategoryId}"/></th:block></选择>

<!-- <div class="form-group">--><!-- <p align="center";class=font-aziz">Avadanlıq/Detal</p>--><!--

发送“验证码”获取 | 15天全站免登陆