products.java
来自「基于Tapestry4」· Java 代码 · 共 43 行
JAVA
43 行
package com.tapestry4;
import java.util.ArrayList;
import java.util.List;
public class Products {
private static List<Fruit> productList;
public static List<Fruit> getProductList() {
if(productList==null) {
productList = new ArrayList<Fruit>();
productList.add(createFruit(1, "苹果", 1.00f, 20));
productList.add(createFruit(2, "西瓜", 0.80f, 10));
productList.add(createFruit(3, "桔子", 1.50f, 25));
productList.add(createFruit(4, "梨子", 2.00f, 30));
}
return productList;
}
public static Fruit createFruit(Integer ig, String name, float price, int mount) {
Fruit fruit = new Fruit();
fruit.setId(ig);
fruit.setName(name);
fruit.setPrice(price);
fruit.setMount(mount);
return fruit;
}
public static Fruit findFruitById(Integer ig) {
if(productList == null) {
productList = getProductList();
}
Fruit fruit = null;
for(Fruit f : productList) {
if(f.getId().intValue() == ig.intValue()) {
fruit = f;
}
}
return fruit;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?