com.jfinal.kit.StrKit Java Examples

The following examples show how to use com.jfinal.kit.StrKit. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JbootJson.java    From jboot with Apache License 2.0 6 votes vote down vote up
public JbootJson() {

        //跳过 null 值输出到浏览器,提高传输性能
        setSkipNullValueField(true);

        //默认设置为 CamelCase 的属性模式
        if (isCamelCaseJsonStyleEnable) {
            setModelAndRecordFieldNameConverter((fieldName) -> StrKit.toCamelCase(fieldName, camelCaseToLowerCaseAnyway));
        }


        setToJsonFactory(o -> {
            if (o instanceof Model) {
                return jbootModelToJson;
            } else {
                return null;
            }
        });
    }
 
Example #2
Source File: MsgInterceptor.java    From jfinal-weixin with Apache License 2.0 6 votes vote down vote up
/**
 * 检测签名
 */
private boolean checkSignature(Controller controller) {
	String signature = controller.getPara("signature");
	String timestamp = controller.getPara("timestamp");
	String nonce = controller.getPara("nonce");
	if (StrKit.isBlank(signature) || StrKit.isBlank(timestamp) || StrKit.isBlank(nonce)) {
		controller.renderText("check signature failure");
		return false;
	}
	
	if (SignatureCheckKit.me.checkSignature(signature, timestamp, nonce)) {
		return true;
	}
	else {
		logger.error("check signature failure: " +
				" signature = " + controller.getPara("signature") +
				" timestamp = " + controller.getPara("timestamp") +
				" nonce = " + controller.getPara("nonce"));
		
		return false;
	}
}
 
Example #3
Source File: SmartField.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Object doGetDataFromControllerByName(String name) {
    Controller controller = JbootControllerContext.get();
    if (name.contains(".")) {
        String[] modelAndAttr = name.split("\\.");
        String modelName = modelAndAttr[0];
        String attr = modelAndAttr[1];
        Object object = controller.getAttr(modelName);
        if (object == null) {
            return null;
        } else if (object instanceof Model) {
            return ((Model) object).get(attr);
        } else if (object instanceof Map) {
            return ((Map) object).get(attr);
        } else {
            try {
                Method method = object.getClass().getMethod("get" + StrKit.firstCharToUpperCase(attr));
                return method.invoke(object);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    } else {
        return controller.getAttr(name);
    }
}
 
Example #4
Source File: OptionDirective.java    From jboot-admin with Apache License 2.0 6 votes vote down vote up
@Override
public void exec(Env env, Scope scope, Writer writer) {
    LogKit.info("option====="+typeCode);
    if (exprList.length() > 2) {
        throw new ParseException("Wrong number parameter of #date directive, two parameters allowed at most", location);
    }

    typeCode = getParam(0, scope);
    if (StrKit.isBlank(typeCode)) {
        throw new ParseException("typeCode is null", location);
    }

    if (exprList.length() > 1) {
        value = getParam(1, "", scope);
    }

    List<Data> list = dataApi.getListByTypeOnUse(typeCode);
    for (Data data : list) {
        if (value != null && data.getCode().equals(value)) {
            write(writer, "<option selected value=\"" + data.getCode()  + "\">" + data.getCodeDesc() + "</option>");
        } else {
            write(writer, "<option value=\"" + data.getCode()  + "\">" + data.getCodeDesc() + "</option>");
        }
    }
}
 
Example #5
Source File: ImageUtils.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 过文件扩展名,判断是否为支持的图像文件
 *
 * @param fileName
 * @return 是图片则返回 true,否则返回 false
 */
public static boolean isImageExtName(String fileName) {
    if (StrKit.isBlank(fileName)) {
        return false;
    }
    fileName = fileName.trim().toLowerCase();
    String ext = getExtName(fileName);
    if (ext != null) {
        for (String s : imgExts) {
            if (s.equals(ext)) {
                return true;
            }
        }
    }
    return false;
}
 
Example #6
Source File: DataTplDirective.java    From jboot-admin with Apache License 2.0 6 votes vote down vote up
@Override
public void exec(Env env, Scope scope, Writer writer) {
    if (exprList.length() > 2) {
        throw new ParseException("Wrong number parameter of #date directive, two parameters allowed at most", location);
    }

    typeCode = getParam(0, scope);
    if (StrKit.isBlank(typeCode)) {
        throw new ParseException("typeCode is null", location);
    }

    if (exprList.length() > 1) {
        attrName = getParam(1, "type", scope);
    }
    List<Data> list = dataApi.getListByTypeOnUse(typeCode);

    write(writer, "<div>");
    for (Data data : list) {
        write(writer, "{{#  if(d." + attrName + " == \\'" + data.getCode() + "\\') { }}");
        write(writer, data.getCodeDesc());
        write(writer, "{{#  } }}");
    }
    write(writer, "</div>");
}
 
Example #7
Source File: ServiceProviderGenerator.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void generate(List<TableMeta> tableMetas) {
    System.out.println("Generate base model ...");
    System.out.println("Base Model Output Dir: " + baseModelOutputDir);

    Engine engine = Engine.create("forServiceImpl");
    engine.setSourceFactory(new ClassPathSourceFactory());
    engine.addSharedMethod(new StrKit());
    engine.addSharedObject("getterTypeMap", getterTypeMap);
    engine.addSharedObject("javaKeyword", javaKeyword);

    for (TableMeta tableMeta : tableMetas) {
        genBaseModelContent(tableMeta);
    }
    writeToFile(tableMetas);
}
 
Example #8
Source File: LogServiceImpl.java    From jboot-admin with Apache License 2.0 6 votes vote down vote up
@Override
public Page<Log> findPage(Log log, int pageNumber, int pageSize) {
    Columns columns = Columns.create();

    if (StrKit.notBlank(log.getIp())) {
        columns.like("ip", "%"+log.getIp()+"%");
    }
    if (StrKit.notBlank(log.getUrl())) {
        columns.like("url", "%"+log.getUrl()+"%");
    }
    if (StrKit.notBlank(log.getLastUpdAcct())) {
        columns.like("lastUpdAcct", "%"+log.getLastUpdAcct()+"%");
    }

    return DAO.paginateByColumns(pageNumber, pageSize, columns.getList(), "id desc");
}
 
Example #9
Source File: ResController.java    From jboot-admin with Apache License 2.0 6 votes vote down vote up
/**
 * 修改提交
 */
@Before({POST.class, ResValidator.class})
public void postUpdate() {
    Long pid = getParaToLong("pid");
    Res sysRes = getBean(Res.class, "res");

    if (StrKit.isBlank(sysRes.getIconCls())) {
        sysRes.setIconCls("");
    }

    sysRes.setPid(pid);
    sysRes.setLastUpdAcct(AuthUtils.getLoginUser().getName());
    sysRes.setLastUpdTime(new Date());
    sysRes.setNote("修改系统资源");

    if (!resService.update(sysRes)) {
        throw new BusinessException("修改失败,请重试");
    }

    renderJson(RestResult.buildSuccess());
}
 
Example #10
Source File: AppJbootServiceImplGenerator.java    From jboot-admin with Apache License 2.0 6 votes vote down vote up
@Override
public void generate(List<TableMeta> tableMetas) {
    System.out.println("Generate base model ...");
    System.out.println("Base Model Output Dir: " + baseModelOutputDir);

    Engine engine = Engine.create("forServiceImpl");
    engine.setSourceFactory(new ClassPathSourceFactory());
    engine.addSharedMethod(new StrKit());
    engine.addSharedObject("getterTypeMap", getterTypeMap);
    engine.addSharedObject("javaKeyword", javaKeyword);

    for (TableMeta tableMeta : tableMetas) {
        genBaseModelContent(tableMeta);
    }
    writeToFile(tableMetas);
}
 
Example #11
Source File: NodeController.java    From zooadmin with MIT License 6 votes vote down vote up
public void modify() {
    ResultData result = new ResultData();
    String parentPath = getPara("parentPath");
    if (StrKit.isBlank(parentPath)) {
        parentPath = "/";
    }
    String nodeData = getPara("nodeData");
    try {
        ZkClient zkClient = getSessionAttr("zk-client");
        ZKPlugin zkPlugin = new ZKPlugin(zkClient);
        if (zkClient.exists(parentPath)) {
            zkPlugin.edit(parentPath, nodeData.getBytes());
            result.setMessage("数据修改成功");
        } else {
            result.setSuccess(false);
            result.setMessage("节点路径不存在失败");
        }
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage("数据修改失败");
        log.error("数据修改失败,错误", e);
    }
    renderJson(result);
}
 
Example #12
Source File: ModelMappingClient.java    From my_curd with Apache License 2.0 6 votes vote down vote up
/**
 * 生成 ModelMapping
 *
 * @param tableMetas 表元数据集合
 * @throws IOException 文件读写异常
 */
public static Map<String, String> generate(List<TableMeta> tableMetas) throws IOException {
    log.debug("(*^▽^*) start generate MappingKit");
    Map<String, String> ret = new HashMap<>();


    String tplContent = FileUtils.readFileToString(new File(mappingKitTplPath), Constant.DEFAULT_ENCODEING);
    Map<String, Object> params = new HashMap<>();
    params.put("basePackageName", GeneratorConfig.basePackageName);
    params.put("moduleName", GeneratorConfig.moduleName);
    params.put("tableMetas", tableMetas);
    params.put("author", GeneratorConfig.author);
    params.put("since", new DateTime().toString("yyyy-MM-dd HH:mm:ss"));

    ret.put(mappingKitOutPath + StrKit.firstCharToUpperCase(GeneratorConfig.moduleName) + "ModelMapping.java", FreemarkerUtils.renderAsText(tplContent, params));
    log.debug("(*^▽^*) generate MappingKit over");
    return ret;
}
 
Example #13
Source File: JsonUtils.java    From my_curd with Apache License 2.0 6 votes vote down vote up
/**
 * Record转为Map,驼峰命名
 *
 * @param record
 * @return
 */
public static Map<String, Object> recordToCamelCaseMap(Record record) {
    if (null == record) {
        return null;
    }
    String[] keys = record.getColumnNames();
    Map<String, Object> map = new HashMap<>();
    for (String key : keys) {
        Object value = record.get(key);
        key = StrKit.toCamelCase(key.toLowerCase());
        if (null != value) {
            map.put(key, value);
        }
    }
    return map;
}
 
Example #14
Source File: NodeController.java    From zooadmin with MIT License 6 votes vote down vote up
public void create() {
    ResultData result = new ResultData();
    String parentPath = getPara("parentPath");
    if (StrKit.isBlank(parentPath)) {
        parentPath = "/";
    }
    String nodeName = getPara("nodeName");
    nodeName = StringUtil.rtrim(nodeName, new char[]{'/'});
    String nodeData = getPara("nodeData");
    Integer mode = getParaToInt("nodeType");
    try {
        ZkClient zkClient = getSessionAttr("zk-client");
        ZKPlugin zkPlugin = new ZKPlugin(zkClient);
        if (!parentPath.equals("/")) {
            nodeName = parentPath + "/" + nodeName;
        } else {
            nodeName = "/" + nodeName;
        }
        zkPlugin.create(nodeName, nodeData.getBytes(), mode);
        result.setMessage("创建成功");
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage("创建失败");
    }
    renderJson(result);
}
 
Example #15
Source File: JsonUtils.java    From my_curd with Apache License 2.0 6 votes vote down vote up
/**
 * 把model转为map,驼峰命名
 *
 * @param model
 * @return
 */
public static Map<String, Object> modelToCamelCaseMap(Model model) {
    if (null == model) {
        return null;
    }
    String[] keys = model._getAttrNames();
    Map<String, Object> map = new HashMap<>();
    for (String key : keys) {
        Object value = model.get(key);
        key = StrKit.toCamelCase(key.toLowerCase());
        if (null != value) {
            map.put(key, value);
        }
    }
    return map;
}
 
Example #16
Source File: SendMsgUtils.java    From my_curd with Apache License 2.0 6 votes vote down vote up
/**
 * 送 消息给部分用户发
 *
 * @param userIds sys_user id
 * @param msg     消息文本
 */
public static void sendToUsers(Set<String> userIds, String msg) {
    for (String userId : userIds) {
        ExecutorServiceUtils.pool.submit(() -> {
            String sessionId = OnlineUserContainer.USERID_SESSIONID.get(userId);
            if (StrKit.isBlank(sessionId)) {
                log.debug("用户:{} websocket 不在线,不使用 WebSocket 推送。", userId);
                return;
            }
            Session session = OnlineUserContainer.SESSIONID_SESSION.get(sessionId);
            if (session == null) {
                log.debug("用户:{} 找不到 websocket session,不使用 WebSocket 推送。", userId);
                return;
            }
            try {
                session.getBasicRemote().sendText(msg);
            } catch (IOException e) {
                WebSocketServer.closeSession(session);
                log.error(e.getMessage(), e);
            }
        });
    }
}
 
Example #17
Source File: ModelExt.java    From jfinal-ext3 with Apache License 2.0 6 votes vote down vote up
/**
 * Get attr names
 */
public List<String> attrNames() {
	String[] names = this._getAttrNames();
	if (null != names && names.length != 0) {
		return Arrays.asList(names);
	}
	Method[] methods = this._getUsefulClass().getMethods();
	String methodName;
	List<String> attrs = new ArrayList<String>();
	for (Method method : methods) {
		methodName = method.getName();
		if (methodName.startsWith("set") ) {
			String attr = methodName.substring(3).toLowerCase();
			if (StrKit.notBlank(attr)) {
				attrs.add(attr);
			}
		}
	}
	return attrs;
}
 
Example #18
Source File: PaymentKit.java    From jfinal-weixin with Apache License 2.0 6 votes vote down vote up
/**
 * 微信下单,map to xml
 * @param params 参数
 * @return String
 */
public static String toXml(Map<String, String> params) {
	StringBuilder xml = new StringBuilder();
	xml.append("<xml>");
	for (Entry<String, String> entry : params.entrySet()) {
		String key   = entry.getKey();
		String value = entry.getValue();
		// 略过空值
		if (StrKit.isBlank(value)) continue;
		xml.append("<").append(key).append(">");
			xml.append(entry.getValue());
		xml.append("</").append(key).append(">");
	}
	xml.append("</xml>");
	return xml.toString();
}
 
Example #19
Source File: JbootServiceJoinerImpl.java    From jboot with Apache License 2.0 6 votes vote down vote up
/**
 * 添加关联数据到某个model中去,避免关联查询,提高性能。
 *
 * @param model
 * @param joinOnField
 * @param attrs
 */
@Override
public <M extends Model> M join(M model, String joinOnField, String[] attrs) {
    if (model == null)
        return model;
    Object id = model.get(joinOnField);
    if (id == null) {
        return model;
    }
    JbootModel m = joinById(id);
    if (m != null) {
        m = m.copy();
        m.keep(attrs);
        model.put(StrKit.firstCharToLowerCase(m.getClass().getSimpleName()), m);
    }
    return model;
}
 
Example #20
Source File: NodeController.java    From zooadmin with MIT License 6 votes vote down vote up
public void create() {
    ResultData result = new ResultData();
    String parentPath = getPara("parentPath");
    if (StrKit.isBlank(parentPath)) {
        parentPath = "/";
    }
    String nodeName = getPara("nodeName");
    nodeName = StringUtil.rtrim(nodeName, new char[]{'/'});
    String nodeData = getPara("nodeData");
    Integer mode = getParaToInt("nodeType");
    try {
        ZkClient zkClient = getSessionAttr("zk-client");
        ZKPlugin zkPlugin = new ZKPlugin(zkClient);
        if (!parentPath.equals("/")) {
            nodeName = parentPath + "/" + nodeName;
        } else {
            nodeName = "/" + nodeName;
        }
        zkPlugin.create(nodeName, nodeData.getBytes(), mode);
        result.setMessage("创建成功");
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage("创建失败");
    }
    renderJson(result);
}
 
Example #21
Source File: JbootServiceInterfaceGenerator.java    From jboot with Apache License 2.0 6 votes vote down vote up
@Override
public void generate(List<TableMeta> tableMetas) {
    System.out.println("Generate base model ...");
    System.out.println("Base Model Output Dir: " + baseModelOutputDir);

    Engine engine = Engine.create("forService");
    engine.setSourceFactory(new ClassPathSourceFactory());
    engine.addSharedMethod(new StrKit());
    engine.addSharedObject("getterTypeMap", getterTypeMap);
    engine.addSharedObject("javaKeyword", javaKeyword);

    for (TableMeta tableMeta : tableMetas) {
        genBaseModelContent(tableMeta);
    }
    writeToFile(tableMetas);
}
 
Example #22
Source File: JbootServiceImplGenerator.java    From jboot with Apache License 2.0 6 votes vote down vote up
/**
 * base model 覆盖写入
 */
protected void writeToFile(TableMeta tableMeta) throws IOException {
    File dir = new File(outputDir);
    if (!dir.exists()) {
        dir.mkdirs();
    }

    String target =outputDir + File.separator + tableMeta.modelName + "Service" + StrKit.firstCharToUpperCase(implName) + ".java";

    File targetFile = new File(target);
    if (targetFile.exists()) {
        return;
    }


    FileWriter fw = new FileWriter(target);
    try {
        fw.write(tableMeta.baseModelContent);
    } finally {
        fw.close();
    }
}
 
Example #23
Source File: OneToManyClient.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * 多表代码生成器
 *
 * @param mainTableMeta 主表表元信息
 * @param sonTableMetas 字表表元信息集合
 * @throws IOException 写文件异常
 */
public static Map<String, String> generate(TableMeta mainTableMeta, List<TableMeta> sonTableMetas) throws IOException {
    log.debug("(*^▽^*) start generate oneToMany ");
    Map<String, String> ret = new HashMap<>();

    Map<String, Object> params = new HashMap<>();
    params.put("basePackageName", GeneratorConfig.basePackageName);
    params.put("moduleName", GeneratorConfig.moduleName);
    params.put("author", GeneratorConfig.author);
    params.put("since", new DateTime().toString("yyyy-MM-dd HH:mm:ss"));
    params.put("generateDate", new DateTime().toString("yyyy-MM-dd HH:mm:ss"));
    params.put("excludeFields", GeneratorConfig.excludeFields);
    params.put("mainTableMeta", mainTableMeta);
    params.put("sonTableMetas", sonTableMetas);
    params.put("mainId", mainId);
    params.put("mainIdCamel", StrKit.toCamelCase(mainId));

    // controller
    String tplContent = FileUtils.readFileToString(new File(controllerTplPath), Constant.DEFAULT_ENCODEING);
    ret.put(controllerOutPath + mainTableMeta.nameCamelFirstUp + "Controller.java", FreemarkerUtils.renderAsText(tplContent, params));
    // index.ftl
    tplContent = FileUtils.readFileToString(new File(indexTplPath), Constant.DEFAULT_ENCODEING);
    ret.put(pageOutDirPath + mainTableMeta.nameCamel + ".ftl", FreemarkerUtils.renderAsText(tplContent, params));
    // form.ftl
    tplContent = FileUtils.readFileToString(new File(formTplPath), Constant.DEFAULT_ENCODEING);
    ret.put(pageOutDirPath + mainTableMeta.nameCamel + "_form.ftl", FreemarkerUtils.renderAsText(tplContent, params));

    log.debug("(*^▽^*)  generate oneToMany over ");
    return ret;
}
 
Example #24
Source File: IndexController.java    From zooadmin with MIT License 5 votes vote down vote up
public void dologin() {
    ResultData result = new ResultData();
    String addr = getPara("addr");
    String password = getPara("password");
    String pwd = PropKit.use("user.properties").get("root");
    if (StrKit.isBlank(password) || !password.equals(pwd)) {
        result.setSuccess(false);
        result.setMessage("请输入正确的密码登陆!");
        renderJson(result);
    } else {
        if (StrKit.notBlank(addr)) {
            try {
                ZKPlugin zkPlugin = new ZKPlugin(addr);
                if (getSessionAttr("zk-client") == null) {
                    setSessionAttr("zk-client", zkPlugin.getClient());
                    setSessionAttr("addr", addr);
                }
            } catch (Exception e) {
                log.error("ZKPlugin error.", e);
                result.setSuccess(false);
                result.setMessage("连接到ZooKeeper失败,请复核!");
            }

        } else {
            result.setSuccess(false);
            result.setMessage("ZooKeeper 地址不能为空!");
        }
        renderJson(result);
    }
}
 
Example #25
Source File: JbootCron4jPlugin.java    From jboot with Apache License 2.0 5 votes vote down vote up
TaskInfo(String cron, Object task, boolean daemon, boolean enable) {
    if (StrKit.isBlank(cron)) {
        throw new IllegalArgumentException("cron 不能为空.");
    }
    if (task == null) {
        throw new IllegalArgumentException("task 不能为 null.");
    }

    Aop.inject(task);

    this.cron = cron.trim();
    this.task = task;
    this.daemon = daemon;
    this.enable = enable;
}
 
Example #26
Source File: JbootCron4jPlugin.java    From jboot with Apache License 2.0 5 votes vote down vote up
private void addTask(Prop configProp, String configName) throws Exception {
    String configNameValue = configProp.get(configName);
    if (StrKit.isBlank(configNameValue)) {
        throw new IllegalArgumentException("The value of configName: " + configName + " can not be blank.");
    }
    String[] taskNameArray = configNameValue.trim().split(",");
    for (String taskName : taskNameArray) {
        if (StrKit.isBlank(taskName)) {
            throw new IllegalArgumentException("taskName can not be blank.");
        }
        taskName = taskName.trim();

        String taskCron = configProp.get(taskName + ".cron");
        if (StrKit.isBlank(taskCron)) {
            throw new IllegalArgumentException(taskName + ".cron" + " not found.");
        }
        taskCron = taskCron.trim();

        String taskClass = configProp.get(taskName + ".class");
        if (StrKit.isBlank(taskClass)) {
            throw new IllegalArgumentException(taskName + ".class" + " not found.");
        }
        taskClass = taskClass.trim();

        Object taskObj = Class.forName(taskClass).newInstance();
        if (!(taskObj instanceof Runnable) && !(taskObj instanceof Task)) {
            throw new IllegalArgumentException("Task 必须是 Runnable、ITask、ProcessTask 或者 Task 类型");
        }

        boolean taskDaemon = configProp.getBoolean(taskName + ".daemon", false);
        boolean taskEnable = configProp.getBoolean(taskName + ".enable", true);
        taskInfoList.add(new JbootCron4jPlugin.TaskInfo(taskCron, taskObj, taskDaemon, taskEnable));
    }
}
 
Example #27
Source File: JbootServiceImplGenerator.java    From jboot with Apache License 2.0 5 votes vote down vote up
public void generate(List<TableMeta> tableMetas) {
    System.out.println("Generate Service Impl ...");
    System.out.println("Service Impl Output Dir: " + outputDir);

    Engine engine = Engine.create("forServiceImpl");
    engine.setSourceFactory(new ClassPathSourceFactory());
    engine.addSharedMethod(new StrKit());
    engine.addSharedObject("getterTypeMap", getterTypeMap);
    engine.addSharedObject("javaKeyword", JavaKeyword.me);

    for (TableMeta tableMeta : tableMetas) {
        genBaseModelContent(tableMeta);
    }
    writeToFile(tableMetas);
}
 
Example #28
Source File: WechatApis.java    From jboot with Apache License 2.0 5 votes vote down vote up
/**
 * http GET请求获得jsapi_ticket(有效期7200秒,开发者必须在自己的服务全局缓存jsapi_ticket)
 *
 * @param jsApiType jsApi类型
 * @return JsTicket
 */
public static JsTicket getTicket(JsApiType jsApiType) {
    String access_token = AccessTokenApi.getAccessTokenStr();
    String appId = ApiConfigKit.getApiConfig().getAppId();
    String key = appId + ':' + jsApiType.name();
    final ParaMap pm = ParaMap.create("access_token", access_token).put("type", jsApiType.name());

    // 2016.07.21修改By L.cm 为了更加方便扩展
    String jsTicketJson = ApiConfigKit.getAccessTokenCache().get(key);
    JsTicket jsTicket = null;
    if (StrKit.notBlank(jsTicketJson)) {
        jsTicket = new JsTicket(jsTicketJson);
    }
    if (null == jsTicket || !jsTicket.isAvailable()) {
        // 最多三次请求
        jsTicket = RetryUtils.retryOnException(3, new Callable<JsTicket>() {

            @Override
            public JsTicket call() throws Exception {
                return new JsTicket(HttpUtils.get(apiUrl, pm.getData()));
            }

        });

        if (null != jsApiType) {
            ApiConfigKit.getAccessTokenCache().set(key, jsTicket.getCacheJson());
        }

    }
    return jsTicket;
}
 
Example #29
Source File: JbootServiceJoinerImpl.java    From jboot with Apache License 2.0 5 votes vote down vote up
/**
 * 添加关联数据到某个model中去,避免关联查询,提高性能。
 *
 * @param model       要添加到的model
 * @param joinOnField model对于的关联字段
 */
@Override
public <M extends Model> M join(M model, String joinOnField) {
    if (model == null)
        return model;
    Object id = model.get(joinOnField);
    if (id == null) {
        return model;
    }
    Model m = joinById(id);
    if (m != null) {
        model.put(StrKit.firstCharToLowerCase(m.getClass().getSimpleName()), m);
    }
    return model;
}
 
Example #30
Source File: OAController.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * 流程实例表单申请详情
 */
public void processInstanceFormDetail() {
    String businessForm = getPara("businessForm");
    String businessKey = getPara("businessKey");
    if (StringUtils.isEmpty(businessForm)) {
        renderText("businessForm 缺失");
        return;
    }
    if (StringUtils.isEmpty(businessKey)) {
        renderText("businessKey 缺失");
        return;
    }
    String redirecturl = "/" + StrKit.toCamelCase(businessForm) + "/detail?id=" + businessKey;
    redirect(redirecturl);
}