⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pageindex.java

📁 简单就是美 java dbwheel框架
💻 JAVA
字号:
package cn.webwheel.tutorials.params;

import cn.webwheel.Action;
import cn.webwheel.Result;
import cn.webwheel.WebContext;
import cn.webwheel.WebContextAware;
import cn.webwheel.parammap.*;
import cn.webwheel.plugin.template.BaseTemplateResultFactory;
import cn.webwheel.plugin.template.Component;

import java.util.Arrays;
import java.util.List;

public class PageIndex implements Action, Component, WebContextAware, BindExceptionAware {

    // 参数绑定工具
    private static ComponentBinder<PageIndex> binder;

    private WebContext context;

    private String a;
    private int b;
    private boolean c;
    private List<String> d;

    // 使用cn.webwheel.parammap.Input注释标记需要参数绑定的的属性
    @Input
    public void setA(String a) {
        this.a = a;
    }

    @Input
    public void setB(int b) {
        this.b = b;
    }

    @Input
    public void setC(boolean c) {
        this.c = c;
    }

    @Input
    public void setD(String[] d) {
        if (d != null) {
            this.d = Arrays.asList(d);
        }
    }

    @SuppressWarnings("unchecked")
    public Result execute() throws Exception {
        // 创建一个参数绑定工具
        if (binder == null) {
            binder = new ComponentBinderBuilder<PageIndex>(PageIndex.class).build().newInstance();
        }
        // 将request中的参数绑定到this对象,需要绑定的参数使用cn.webwheel.parammap.Input注释进行标记
        binder.bind(context.getRequest().getParameterMap(), this);
        BaseTemplateResultFactory resultFactory = (BaseTemplateResultFactory) context.getContext().getAttribute("resultFactory");
        return resultFactory.findResult(this);
    }

    public boolean beginRender() {
        return true;
    }

    public void afterRender() {
    }

    public void setWebContext(WebContext context) {
        this.context = context;
    }

    public String getA() {
        return a;
    }

    public int getB() {
        return b;
    }

    public boolean isC() {
        return c;
    }

    public String[] getD() {
        if(d==null) return null;
        return d.toArray(new String[d.size()]);
    }

    public boolean containsd(String s) {
        return d!=null && d.contains(s);
    }

    public String format(String[] ss) {
        if(ss==null) return null;
        return Arrays.toString(ss);
    }

    // 当参数绑定出错时此方法被调用
    public void bindError(BindException e) {
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -