Java Code Examples for com.ruoyi.common.utils.StringUtils#format()

The following examples show how to use com.ruoyi.common.utils.StringUtils#format() . 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: CommonController.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * 通用下载请求
 * 
 * @param fileName 文件名称
 * @param delete 是否删除
 */
@GetMapping("common/download")
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
{
    try
    {
        if (!FileUtils.isValidFilename(fileName))
        {
            throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
        }
        String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
        String filePath = Global.getDownloadPath() + fileName;

        response.setCharacterEncoding("utf-8");
        response.setContentType("multipart/form-data");
        response.setHeader("Content-Disposition",
                "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
        FileUtils.writeBytes(filePath, response.getOutputStream());
        if (delete)
        {
            FileUtils.deleteFile(filePath);
        }
    }
    catch (Exception e)
    {
        log.error("下载文件失败", e);
    }
}
 
Example 2
Source File: CommonController.java    From RuoYi-Vue with MIT License 5 votes vote down vote up
/**
 * 通用下载请求
 * 
 * @param fileName 文件名称
 * @param delete 是否删除
 */
@GetMapping("common/download")
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
{
    try
    {
        if (!FileUtils.isValidFilename(fileName))
        {
            throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
        }
        String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
        String filePath = RuoYiConfig.getDownloadPath() + fileName;

        response.setCharacterEncoding("utf-8");
        response.setContentType("multipart/form-data");
        response.setHeader("Content-Disposition",
                "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
        FileUtils.writeBytes(filePath, response.getOutputStream());
        if (delete)
        {
            FileUtils.deleteFile(filePath);
        }
    }
    catch (Exception e)
    {
        log.error("下载文件失败", e);
    }
}
 
Example 3
Source File: AuthenticationEntryPointImpl.java    From RuoYi-Vue with MIT License 5 votes vote down vote up
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e)
        throws IOException
{
    int code = HttpStatus.UNAUTHORIZED;
    String msg = StringUtils.format("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI());
    ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg)));
}
 
Example 4
Source File: VelocityUtils.java    From supplierShop with MIT License 4 votes vote down vote up
/**
 * 获取文件名
 */
public static String getFileName(String template, GenTable genTable)
{
    // 文件名称
    String fileName = "";
    // 包路径
    String packageName = genTable.getPackageName();
    // 模块名
    String moduleName = genTable.getModuleName();
    // 大写类名
    String className = genTable.getClassName();
    // 业务名称
    String businessName = genTable.getBusinessName();

    String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/");
    String mybatisPath = MYBATIS_PATH + "/" + moduleName;
    String htmlPath = TEMPLATES_PATH + "/" + moduleName + "/" + businessName;

    if (template.contains("domain.java.vm"))
    {
        fileName = StringUtils.format("{}/domain/{}.java", javaPath, className);
    }
    else if (template.contains("mapper.java.vm"))
    {
        fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className);
    }
    else if (template.contains("service.java.vm"))
    {
        fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className);
    }
    else if (template.contains("serviceImpl.java.vm"))
    {
        fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className);
    }
    else if (template.contains("controller.java.vm"))
    {
        fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className);
    }
    else if (template.contains("mapper.xml.vm"))
    {
        fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className);
    }
    else if (template.contains("list.html.vm"))
    {
        fileName = StringUtils.format("{}/{}.html", htmlPath, businessName);
    }
    else if (template.contains("list-tree.html.vm"))
    {
        fileName = StringUtils.format("{}/{}.html", htmlPath, businessName);
    }
    else if (template.contains("tree.html.vm"))
    {
        fileName = StringUtils.format("{}/tree.html", htmlPath);
    }
    else if (template.contains("add.html.vm"))
    {
        fileName = StringUtils.format("{}/add.html", htmlPath);
    }
    else if (template.contains("edit.html.vm"))
    {
        fileName = StringUtils.format("{}/edit.html", htmlPath);
    }
    else if (template.contains("sql.vm"))
    {
        fileName = businessName + "Menu.sql";
    }
    return fileName;
}
 
Example 5
Source File: BaseController.java    From supplierShop with MIT License 4 votes vote down vote up
/**
 * 页面跳转
 */
public String redirect(String url)
{
    return StringUtils.format("redirect:{}", url);
}
 
Example 6
Source File: VelocityUtils.java    From RuoYi-Vue with MIT License 4 votes vote down vote up
/**
 * 获取文件名
 */
public static String getFileName(String template, GenTable genTable)
{
    // 文件名称
    String fileName = "";
    // 包路径
    String packageName = genTable.getPackageName();
    // 模块名
    String moduleName = genTable.getModuleName();
    // 大写类名
    String className = genTable.getClassName();
    // 业务名称
    String businessName = genTable.getBusinessName();

    String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/");
    String mybatisPath = MYBATIS_PATH + "/" + moduleName;
    String vuePath = "vue";

    if (template.contains("domain.java.vm"))
    {
        fileName = StringUtils.format("{}/domain/{}.java", javaPath, className);
    }
    else if (template.contains("mapper.java.vm"))
    {
        fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className);
    }
    else if (template.contains("service.java.vm"))
    {
        fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className);
    }
    else if (template.contains("serviceImpl.java.vm"))
    {
        fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className);
    }
    else if (template.contains("controller.java.vm"))
    {
        fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className);
    }
    else if (template.contains("mapper.xml.vm"))
    {
        fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className);
    }
    else if (template.contains("sql.vm"))
    {
        fileName = businessName + "Menu.sql";
    }
    else if (template.contains("api.js.vm"))
    {
        fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName);
    }
    else if (template.contains("index.vue.vm"))
    {
        fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
    }
    else if (template.contains("index-tree.vue.vm"))
    {
        fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
    }
    return fileName;
}
 
Example 7
Source File: BaseController.java    From ruoyiplus with MIT License 4 votes vote down vote up
/**
 * 页面跳转
 */
public String redirect(String url)
{
    return StringUtils.format("redirect:{}", url);
}
 
Example 8
Source File: VelocityUtils.java    From supplierShop with MIT License 2 votes vote down vote up
/**
 * 获取权限前缀
 * 
 * @param moduleName 模块名称
 * @param businessName 业务名称
 * @return 返回权限前缀
 */
public static String getPermissionPrefix(String moduleName, String businessName)
{
    return StringUtils.format("{}:{}", moduleName, businessName);

}
 
Example 9
Source File: VelocityUtils.java    From RuoYi-Vue with MIT License 2 votes vote down vote up
/**
 * 获取权限前缀
 * 
 * @param moduleName 模块名称
 * @param businessName 业务名称
 * @return 返回权限前缀
 */
public static String getPermissionPrefix(String moduleName, String businessName)
{
    return StringUtils.format("{}:{}", moduleName, businessName);

}