由供应商类型 查询 类型名称, 涉及两个表的一对一查询
SupplierType .java 供应商类型 | Supplier .java 供应商 |
public class SupplierType { private Integer supTypeId; private String supTypeName; private Supplier supplier; Get ... Set ... } | public class Supplier { private Integer supId; //编号 private String supName;//供应商名称 private String supLinkman;//联系人 private String supPhone;//电话 private String supAddress;//地址 private String supRemark;//备注 private double supPay ; //期初应付 private String supType ;//类型 private SupplierType supplierType; Get ... Set ... } |
Mapper配置文件
SupplierMapper.xml
<mapper namespace="ndd.ssm1.dao.SupplierMapper" >
<resultMap id="supplierMap" type="ndd.ssm1.entity.Supplier" >
<id column="sup_id" property="supId" jdbcType="INTEGER" />
<result column="sup_name" property="supName" jdbcType="VARCHAR" />
<result column="sup_linkman" property="supLinkman" jdbcType="VARCHAR" />
<result column="sup_phone" property="supPhone" jdbcType="VARCHAR" />
<result column="sup_address" property="supAddress" jdbcType="VARCHAR" />
<result column="sup_remark" property="supRemark" jdbcType="VARCHAR" />
<result column="sup_pay" property="supPay" jdbcType="VARCHAR" />
<result column="sup_type" property="supType" jdbcType="VARCHAR" />
<collection property="supplierType" resultMap="ndd.ssm1.dao.SupplierTypeMapper.supTypetMap"/>
</resultMap>
</mapper>
SupplierTypeMapper.xml
<mapper namespace="ndd.ssm1.dao.SupplierTypeMapper" >
<resultMap id="supTypetMap" type="ndd.ssm1.entity.SupplierType" >
<id column="sup_type_id" property="supTypeId" jdbcType="INTEGER" />
<result column="sup_type_Name" property="supTypeName" jdbcType="VARCHAR" />
</resultMap>
</mapper>
list.jsp dataGrid
columns:[[
{checkbox:true},
{field:'supId',title:'供应商编号',width:100},
{field:'supName',title:'供应商姓名',width:100},
{field:'supLinkman',title:'联系人价格',width:100},
{field:'supPhone',title:'电话',width:100},
{field:'supAddress',title:'地址',width:100},
{field:'supRemark',title:'备注',width:100},
{field:'supPay',title:'期初应付',width:100},
{field:'supplierType',
formatter : function(value,row,index){
if (row.supplierType){
return row.supplierType.supTypeName;
} else {
return value;
}},
title:'供应商类型',width:100}
]]
说明: 我的后台传给前台datagrid的数据有total和rows,它们的格式如下:
即rows里面的每个对象都有supId、supplierType、supName等属性,而属性supplierType本是一个对象,里面有supTypeId、supTypename这几个属性。现在需要把supplierType里面的supTypename给显示出来,因为直接在field中这样写
fileld:"field:supplierType.supTypename',这样在前台是显示出不来这一列的,因为fileld的格式不支持点操作符的用法。所以应该用easyui的api中的datagrid自带的一个格式化函数formatter(),formatter的具体说明请查阅api
{field:'supplierType',
formatter : function(value,row,index){
if (row.supplierType){
return row.supplierType.supTypeName;
} else {
return value;
}},
title:'供应商类型',width:100}
]]