看起来很简单的一个问题,其实要弄懂真不容易啊,至少我是还没完全明白,下面的代码都测试通过的。
struts的action如下
整个程序是可以运行的,我想问最正规的配置方法是这样的吗?或者还可以有别的配法吗?这种用法正确吗?
欢迎大家指教。
我遇到的情况是两张表BN_IN_DETAIL_TBL和BN_IN_STATION_TBL
分别生成了两个实体类
public class InDetail {
private Integer id;
private InStation inStation;
private String epcId;
//省略getter和setter
}
public class InStation {
private Integer inId;
private Date inTime;
private String packer;
private String keeper;
//省略getter和setter
}
对应的Map文件
<hibernate-mapping>
<class name="com.tfrd.tobacco.modle.InDetail" table="BN_IN_DETAIL_TBL" schema="tobacco_data.dbo">
<id name="id" type="integer">
<column name="ID" precision="10" scale="0" />
<generator class="identity" />
</id>
<many-to-one name="inStation" class="com.tfrd.tobacco.modle.InStation">
<column name="IN_ID"></column>
</many-to-one>
<property name="epcId" type="string">
<column name="EPC_ID" />
</property>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="com.tfrd.tobacco.modle.InStation" table="BN_IN_STATION_TBL" schema="tobacco_data.dbo">
<id name="inId" type="java.lang.Integer">
<column name="IN_ID" precision="10" scale="0" />
<generator class="identity" />
</id>
<property name="inTime" type="timestamp">
<column name="IN_TIME" />
</property>
<property name="packer" type="string">
<column name="PACKER" />
</property>
<property name="keeper" type="string">
<column name="KEEPER" />
</property>
</class>
</hibernate-mapping>
DAO层代码如下
public class InStationDAO extends BaseDAO implements IInStationDAO{
@Override
public void addInStation(InStation inStation) {
getHbaseDAO().saveOrUpdate(inStation);
}
@Override
public List<?> query(InStation inStation, Page page) {
StringBuilder sql = new StringBuilder();
List<Object> param = new ArrayList<Object>();
sql.append("from InStation");
sql.append(" order by inId desc");
return getHbaseDAO().findList(sql.toString(), param.toArray(), page);
}
@Override
public InStation read(InStation inStation) {
return (InStation) getHbaseDAO().findById(inStation.getInId(), InStation.class);
}
@Override
public void addInDetail(InDetail inDetail) {
getHbaseDAO().saveOrUpdate(inDetail);
}
@Override
public List<Map<String, Object>> queryEpc() {
StringBuilder sql = new StringBuilder();
List<Object> param = new ArrayList<Object>();
sql.append("select * from tobacco_bn.dbo.BN_MEM_STOCK_TBL where status=0");
return getJbaseDAO().findList(sql.toString(), param.toArray());
}
}
struts的action如下
public class InStationAction extends BaseAction {
/**
* 到添加入库单页面
* @return
*/
public String toAddInStation() {
return "toAddInStation";
}
/**
* 添加入库单
* @return
*/
public String addInStation() {
inStation.setInTime(new Date());
inStationDAO.addInStation(inStation);
if (inStation.getInId() > 0) {
List<Map<String, Object>> _list = inStationDAO.queryEpc();
for (Map<String, Object> _map : _list) {
InDetail _InDetail = new InDetail();
_InDetail.setInStation(inStation);
_InDetail.setEpcId(_map.get("epc").toString());
inStationDAO.addInDetail(_InDetail);
}
}
return "addInStation";
}
/**
* 入库单列表
* @return
*/
public String queryInStation() {
inStationList = inStationDAO.query(inStation, page);
return "queryInStation";
}
/**
* 到更新入库单页面
* @return
*/
public String toUpdateInStation() {
inStation = inStationDAO.read(inStation);
return "toUpdateInStation";
}
/**
* 删除入库单
* @return
*/
public String delInStation() {
return "delInStation";
}
private InStation inStation;
private IInStationDAO inStationDAO;
private List<?> inStationList;
//省略getter和setter
整个程序是可以运行的,我想问最正规的配置方法是这样的吗?或者还可以有别的配法吗?这种用法正确吗?