1. 程式人生 > >jfinal3.0+在SQL語句中使用if語句

jfinal3.0+在SQL語句中使用if語句

1、控制器中的寫法示例:

    /**
     * jfinal3.0+在SQL語句中使用if語句
     */
    public void user_list() {
        int pageNumber = getParaToInt("page",1);
        int pageSize = getParaToInt("rows",10);
        //登入人員賬號
        String username = getPara("username");
        //登入人員暱稱
        String nickname = getPara("nickname");
        if(StrKit.notBlank(nickname)) {
            nickname = "%" + nickname + "%";
        }
        Kv cond = Kv.by("username", username)
                .set("nickname", nickname);
        SqlPara sqlPara = Db.getSqlPara("sys.user_list", cond);
        Page<Record> pageRecord = Db.paginate(pageNumber, pageSize, sqlPara);
        //下面的render語句是我自己封裝的,以你們實際的為準喔  ^_^
        this.renderDataGrid(pageRecord);        
    }

2、SQL語句中的寫法示例:

#namespace("sys")
    #sql("user_list")
        select * from sys_user where 1=1
        #if(username)
            and username = #para(username)
        #end
        #if(nickname)
            and nickname like #para(nickname)
        #end
    #end
#end