恶心的Enum类型




public enum InvoiceType {

	VAT_INVOICE("增值税专用发票"),
	
	NORMAL_INVOICE("普通发票"),
	
	SPECIALIZED_INVOICE("专业发票");
	
	private String text;

	public String getText() {
		return text;
	}

	private InvoiceType(String text) {
		this.text = text;
	}
	
}




private InvoiceType[] invoiceTypeValues;
private Invoice invoiceBean;

public String index(){
	if(invoiceBean == null){
		invoiceBean = new Invoice();
		invoiceBean.setInvoiceType(InvoiceType.NORMAL_INVOICE);
		invoiceTypeValues = InvoiceType.values();
	}
	return "add";//这样做是为了绕过validateAdd()
}


发票类型:
<select id="invoicetype" name="invoiceBean.invoiceType">
	<c:forEach var="iType" items="${invoiceTypeValues }" varStatus="jump">
		<option value="${invoiceTypeValues[jump.index] }">${iType.text }</option>
	</c:forEach>
</select>



得到的结果是:


发票类型:
<select id="invoicetype" name="invoiceBean.invoiceType">
	
	<option value="VAT_INVOICE">增值税专用发票</option>

	<option value="NORMAL_INVOICE">普通发票</option>

	<option value="SPECIALIZED_INVOICE">专业发票</option>

</select>


你可能感兴趣的:(enum)