You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
test/branch_zyx/ProdCatalogTM.java

70 lines
2.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.lingnan.supermarket.table; // 声明当前类所在的包
import java.util.List; // 导入List接口用于表示列表
import java.util.Vector; // 导入Vector类用于实现可增长的对象数组
import javax.swing.table.AbstractTableModel; // 导入AbstractTableModel类用于创建表格模型
import com.lingnan.supermarket.dto.Production; // 导入Production类表示产品数据传输对象
import com.lingnan.supermarket.dto.User; // 导入User类表示用户数据传输对象
import com.lingnan.supermarket.dao.UserService; // 导入UserService接口用于用户数据访问
import com.lingnan.supermarket.dao.impl.*; // 导入所有实现类,可能用于数据访问层的具体实现
public class ProdCatalogTM extends AbstractTableModel{ // 定义一个类继承自AbstractTableModel用于产品目录的表格数据模型
private String [] columnName = {"类别id","类别名称","商品id","商品名称"}; // 定义列名数组,用于表格的列标题
private productionImpl prodDao = new productionImpl(); // 创建productionImpl实例用于操作产品数据
private Vector<Production> prods; // 声明一个Vector用于存储产品列表
public void all() {
// 查找全部数据
prods = prodDao.findAllproduction(); // 调用findAllproduction方法获取所有产品数据
}
public void ById2(Production p) {
// 根据类别id查找数据
prods = prodDao.findProductionById2(p.getId2()); // 调用findProductionById2方法根据类别id获取产品数据
}
@Override
public int getRowCount() {
return prods.size(); // 返回产品列表的大小,即表格的行数
}
@Override
public int getColumnCount() {
return columnName.length; // 返回列名数组的长度,即表格的列数
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Production prod = prods.get(rowIndex); // 获取指定行的产品对象
// 以下注释掉的是打印语句,用于调试
/*System.out.println( "id="+users.get(rowIndex).getId());
System.out.println("rowIndex"+rowIndex);
System.out.println("columnIndex"+columnIndex);*/
if(columnIndex==0) {
return prod.getId2(); // 返回类别id
}else if(columnIndex==1) {
return prod.getName2(); // 返回类别名称
}else if(columnIndex==2) {
return prod.getId(); // 返回商品id
}else if(columnIndex==3) {
return prod.getName(); // 返回商品名称
}else {
return null; // 如果列索引不匹配返回null
}
}
@Override
public String getColumnName(int column) {
return columnName[column]; // 返回指定列的列名
}
}