08 JFinal Url 传参接参

本文详细介绍了如何在JSP页面与JFinal框架中处理各种类型的URL参数,包括无Key参数、有Key参数、默认值参数及Model参数。通过示例展示了如何使用JSTL标签库展示参数值,并在控制器中获取这些参数。
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<jsp:include page="../common/header.jsp"></jsp:include>
  <header class="navbar navbar-static-top" id="top" role="banner">
  <div class="container">
    <div class="navbar-header" style="text-align: center;">
      <a href="/" class="navbar-brand">WebDemoJFinal-参数</a>
    </div>
  </div>
</header>
<div id="main" class="container">
  <div class="row">
   <div class="col-lg-6 col-ms-6 col-sm-6">
       <h5>无Key 参数 根据常量配置分隔符 默认-</h5>
            <h6>示例参数:1-2</h6>
  	        <h6>参数1<c:out value="${empty param1 ? 'null...' : param1}" /></h6>
  	        <h6>参数2<c:out value="${empty param2 ? 'null...' : param2}" /></h6>
       <h5>有Key 参数</h5>
            <h6>示例参数:?name=zhangsan&sex=</h6>
            <h6>参数name: <c:out value="${empty name ? 'null...' : name}" /></h6>
            <h6>参数sex: <c:out value="${empty sex ? 'null...' : sex}" /></h6>
       <h5>默认值 参数</h5>
       <h6>参数defaultValue: <c:out value="${empty defaultValue ? 'null...' : defaultValue}" /></h6>
       <h6>Model 参数 </h6>
            <h6>示例参数:?user.name=name&user.sex=1&user.age=28</h6>
            <h6>user.name:<c:out value="${empty user.name ? 'null...' : user.name}" /></h6>
            <h6>user.sex: <c:out value="${empty user.sex ? 'null...' : user.sex}" /></h6>
            <h6>user.age: <c:out value="${empty user.age ? 'null...' : user.age}" /></h6>
       <br>
   <h5>备注后台可使用 getParaToInt() 等指定参数接参</h5>
   </div>
   </div>
</div>
<jsp:include page="../common/footer.jsp"></jsp:include>
//Controllerl类中==============================================================================
  
  public void testUrlParaSeparator(){

            setAttr("param1", getPara(0));
            setAttr("param2", getPara(1));
            setAttr("name", getPara("name"));
            setAttr("sex", getPara("sex"));
            setAttr("defaultValue",getPara("defaultValue","100"));
            setAttr("user", getModel(UserModel.class, "user"));


        render("param.jsp");


    }
//==================================================================================
package com.testjfinal.model;

import com.jfinal.plugin.activerecord.Model;

public class UserModel extends Model<UserModel> {
    public static final UserModel dao=new UserModel();
    public static final int SEX_MALE=1;//男
    public static final int  SEX_FEMALE=2;//女
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值