1.entity如下:
2.Mybatis的Mapper.xml文件如下
<resultMap id="BaseResultMapPlus" type="dicItem"> <id column="ID" jdbcType="VARCHAR" property="id" /> <result column="TYPE_ID" jdbcType="VARCHAR" property="typeId" /> <result column="ITEM_CODE" jdbcType="VARCHAR" property="itemCode" /> <result column="ITEM_NAME" jdbcType="VARCHAR" property="itemName" /> <result column="SORT_VALUE" jdbcType="SMALLINT" property="sortValue" /> <result column="DEFAULT_FLAG" jdbcType="TINYINT" property="defaultFlag" /> <association property="dicType" javaType="dicType"> <result column="DIC_NAME" jdbcType="VARCHAR" property="dicName" /> </association> </resultMap>
3.layui table頁面 代碼如下--重點
layui.use(["form","table"], function(){ var table = layui.table; var form = layui.form; //方法級別渲染 table.render({ elem: '#dataDicTable' ,url: '${pageContext.request.contextPath}/dataDictionaryItem/findDataDictionaryItem.do' ,method: 'post' ,request: { pageName: 'curr' //頁碼的參數名稱,默認:page ,limitName: 'limit' //每頁數據量的參數名,默認:limit } ,page:true ,id: 'dataDicTableReload' ,limit: 10 ,limits:[10,15,20,50]//每頁條數的選擇項,默認:[10,20,30,40,50,60,70,80,90]。優先級低於 page 參數中的 limits 參數。 ,cols: [[ {templet:'<div>{{createrFormat(d.dicType.dicName)}}</div>',align: 'left', title:'字典類型'} ,{field:'itemName',align: 'left', title:'項目名稱'} ,{field:'itemCode',align: 'left', title:'項目值'} ]] }); //模板方法 function createrFormat(o){ return o; }
4.強調
,cols: [[ {templet:'<div>{{createrFormat(d.dicType.dicName)}} //模板方法 function createrFormat(o){ return o; }