根据数据库中字段的不同数字,页面使用不同的html标签

当数据库中的 type为0的时候 要用  <input type= “text”>标签

当数据库中的type为1的时候 要用 <textarea></textarea>标签

及其他字段用其他标签。


 首先 从后台将需要的数据传入前台

Controller:

@RequestMapping(value = "/xxx", method =RequestMethod.GET)

    public Stringxxx(Page page,HttpServletRequest request) {

      request.setAttribute("list",systemLeimuService.getAll(page));

        return "/member/page/userData/xxxList";

}

Service:

publicList<UcSystemLeimu>getAll(Pagepage){

      List<UcSystemLeimu> ucSystemLeimu = ucSystemLeimuMapper.findAll(page.getSearchValue());

      returnucSystemLeimu;

  }


Mapper:

List<UcSystemLeimu> findAll(@Param("searchValue")String searchValue);


Mapper.xml:

<selectid="findAll"resultMap="BaseResultMap">

  select

    <includerefid="Base_Column_List"/>

  fromuc_system_leimu

  <where>

      <if test="searchValue != null">

         namelike concat ('%',#{searchValue},'%')

      </ if >

前台页面用c标签

第一种方法:逻辑简单,易于理解

<c:forEach var="xxx"items="${list}" varStatus="status">

       <li>

           <label><font color="red">*</font>${xxx.name}:</label>

           <c:if test="${xxx.type == 0}">

               <input class="${xxx.type}"name="${xxx.descri}">

           </c:if>

           <c:if test="${xxx.type == 1}">

               <textarea class="${xxx.type}"></textarea>

           </c:if>

           

       </li>

</c:forEach>

 

第二种方法 有点绕   当数据库中type=0时 需要显示的是input  textarea的class=0+1  所有用$(".1").hide();就把textarea隐藏了,当数据库中的type=1时,需要显示的是textarea   这时候 input的class=1  textarea 的class=2   所有用$(".1").hide();就把input隐藏了

 

<c:forEach var="xxx"items="${list}" varStatus="status">

                             

    <li><label><fontcolor="red">*</font>${xxx.name}:</label>

<input class="${xxx.type}"name="${xxx.applyforx}">

<textareaclass="${xxx.type+1}"></textarea>

</li>

  </c:forEach>






  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值