Spring Boot 后端代码导出公钥并使用 $.modal.alertError() 提示错误

后端代码

public void exportPk(@PathVariable('id') Long id, HttpServletRequest request, HttpServletResponse response) throws IOException {
        String fixedStr = '3059301306072A8648CE3D020106082A811CCF5501822D03420004';//固定字符
        SpAsymKeyValue spAsymKeyValue = spAsymKeyValueService.selectSpAsymKeyValueById(id);
        String pkValue = spAsymKeyValue.getPkValue();
        response.setCharacterEncoding('utf-8');
        if(StringUtils.isEmpty(pkValue)){
            //此处我向返回信息给前端但不知道怎么写
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            response.getWriter().write('该记录公钥值为空');
            return;
        }

    }

前端代码

window.location.href = prefix + '/exportPk/' + rows.join();
$.table.refresh();

您可以尝试以下代码来使用$.modal.alertError()来提示用户:

window.location.href = prefix + '/exportPk/' + rows.join();
$.table.refresh();

// 在后端代码中,将错误信息返回给前端
if(StringUtils.isEmpty(pkValue)){
    $.modal.alertError('该记录公钥值为空');
    return;
}

这样,当pkValue为空时,前端页面会弹出一个错误提示框,显示'该记录公钥值为空'。

Spring Boot 后端代码导出公钥并使用 $.modal.alertError() 提示错误

原文地址: http://www.cveoy.top/t/topic/bldc 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录