我已下载实体“ BusinessPartner ”。
我将我的所有实体ID都作为字符串并自定义“ org.hibernate.id.UUIDGenerator ”,以便将相关前缀添加到我的ID ex:“ BPID_04a3e35b-12b3-447f-a982- 338739e537f1 “
当我尝试导航到包含“BusinessPartner”实体下拉列表的页面时,我收到以下异常。
在互联网上搜索解决方案,让我知道是否有人有任何线索。我已经指出了我在下面的片段中获得异常的地方。
Java版本: 1.8
Spring Boot版本: 1.5.10.RELEASE
实体订单:
@Entity
@Table(name = Order.TABLE_NAME)
public class Order extends Model implements Serializable {
@Enumerated(EnumType.STRING)
@Column(name = DOCUMENT_TYPE)
private DocumentType documentType;
@Column(name = DOCUMENT_NUMBER, updatable = false)
private String documentNumber;
@Column(name = ORDER_DESCRIPTION)
@NotEmpty
private String orderDescription;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = COL_OTHER_PARTY_ID, nullable = false)
private BusinessPartner otherParty;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = COL_AUTHORITY_BUSINESS_PARTNER_ID, nullable = false)
private BusinessPartner authority;
}
实体BusinessPartner:
@Entity
@Table(name = BusinessPartner.ENTITY_NAME)
public class BusinessPartner extends Model {
@Column(name = NAME)
private String name;
@Column(name = EMAIL)
private String email;
// Getters and Setters omitted for simplicity
}
家长实体:
@MappedSuperclass
public class Model {
public static final String ID = "id";
public static final String CREATED_AT = "createdAt";
public static final String UPDATED_AT = "updatedAt";
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "com.emisha.database.Generators.IDGenerator")
@Column(name = ID)
private String id;
@Version
private Long version;
@Column(name = CREATED_AT)
private Date createdAt;
@Column(name = UPDATED_AT)
private Date updatedAt;
public Model() {
// Empty Constructor
}
/* DEFINED METHODS */
@PrePersist
protected void onCreate() {
updatedAt = createdAt = new Date();
}
@PreUpdate
protected void onUpdates() {
updatedAt = new Date();
}
// GETTERS & SETTERS
}
填充businessPartners的控制器方法:
@Controller
@Secured(SecurityUtil.MANAGE_PURCHASEORDER)
@SessionAttributes("order")
@RequestMapping("Orders")
public class OrderController extends EmishaAdminBaseController {
//.........
@RequestMapping(value = "/{documentType}/form/{id}", method = RequestMethod.GET)
public String getOrder(@PathVariable("documentType") String documentType, @PathVariable("id") String id, Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) {
String view = "PurchaseOrder/form";
if (documentType.equalsIgnoreCase("SalesOrder")) {
view = "SalesOrder/form";
}
User user = Objects.requireNonNull(getCurrentUser()).getUser();
// Mapped Product Data
Order order;
// Default Form control data
String action = request.getContextPath() + "/Orders/" + documentType + "/form/" + id;
String mode = "EDIT_ORDER";
logger.debug("Default mode set to: " + mode + "\n" + "Default action set to: " + action);
if (documentType.equalsIgnoreCase("CreateSalesOrder")) {
action = request.getContextPath() + "/Orders/SalesOrder/form/" + id;
view = "SalesOrder/form";
if (id != null && !id.isEmpty()) {
Order purchaseOrder = orderService.getOrder(id);
order = OrderHelper.convertToSalesOrder(purchaseOrder);
} else {
redirectAttributes.addFlashAttribute("error", "Invalid Purchase Order.");
return "redirect:/Sales/Quotations";
}
} else {
if (id.equals("new")) {
mode = "CREATE_ORDER";
// Create new instance for creating new Procurement Requisition.
order = new Order();
if (documentType.toLowerCase().equals("PurchaseOrder".toLowerCase())) {
// Set default statuses for new Procurement Requisition
order.setStatus(Status.DRAFT);
order.setPublicationType(PublicationType.RESTRICTED);
// Set document type to Purchase Requirement.
order.setDocumentType(DocumentType.PURCHASE_ORDER);
// Set initial processing status to PR Created.
order.setProcessingStatus(ProcessingStatus.PO_CREATED);
} else if (documentType.toLowerCase().equals("SalesOrder".toLowerCase())) {
// Set default statuses for new RFQ ProcurementRequisition
order.setStatus(Status.DRAFT);
order.setPublicationType(PublicationType.RESTRICTED);
// Set document type to Request for Quotation.
order.setDocumentType(DocumentType.SALES_ORDER);
// Set initial processing status to REF Created.
order.setProcessingStatus(ProcessingStatus.SO_CREATED);
}
logger.debug("Mode set to: " + mode + "\n" + "Action set to: " + action);
} else {
order = orderService.getOrder(id);
}
}
addAllDropDowns(model, user);
// Add business data to model
model.addAttribute("order", order);
// Add form control data to model
model.addAttribute("action", action);
model.addAttribute("mode", mode);
return view;
}
//.........
private void addAllDropDowns(Model model, User user) {
// Add dropdown data to model
/* Products drop down */
List<Product> products = new ArrayList<>();
products = productService.getProducts(user.getBusinessPartner());
model.addAttribute("products", products);
/* Unit of Measurements drop down */
List<UnitOfMeasurement> unitOfMeasurements = new ArrayList<>();
unitOfMeasurements = unitOfMeasurementService.getAllUnitOfMeasurements();
model.addAttribute("unitOfMeasurements", unitOfMeasurements);
/* Users drop down */
List<User> users = new ArrayList<>();
users = userService.getUsersWhere(user.getBusinessPartner());
model.addAttribute("users", users);
/* Vendors drop down */
List<BusinessPartner> vendors = new ArrayList<>();
vendors = businessPartnerService.getVendors(user.getBusinessPartner());
model.addAttribute("vendors", vendors);
}
}
我的view.html文件中的Thyemeleaf下拉列表:
<label>Customer</label>
<select th:if="*{order?.quotation ==null}" class="form-control"
th:field="*{otherParty}"
data-placeholder="Select an option" data-allow-clear="true"
tabindex="-1"
style="width: 250px; background-color: #d2e1f3;">
<option value="">Select</option>
<option th:each="vendor,istat : ${vendors}"
th:value="${vendor?.id}" //<---- java.lang.NumberFormatException: For input string: "BPID_04a3e35b-12b3-447f-a982-338739e537f1"
th:text="${vendor?.name}">
Manufacturer
</option>
</select>
这是堆栈跟踪:
java.lang.NumberFormatException: For input string: "BPID_04a3e35b-12b3-447f-a982-338739e537f1"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_152]
at java.lang.Integer.parseInt(Integer.java:580) ~[na:1.8.0_152]
at java.lang.Integer.valueOf(Integer.java:766) ~[na:1.8.0_152]
at org.springframework.util.NumberUtils.parseNumber(NumberUtils.java:208) ~[spring-core-4.3.14.RELEASE.jar:4.3.14.RELEASE]...