使用前端传来的文字进行精确匹配

博客提及使用前端传来的文字进行精确匹配,还涉及PS替换源码的内容,与信息技术相关,或在前端交互、代码处理方面有应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用前端传来的文字进行精确匹配

 /**
     * 使用前端传来的文字进行精确匹配,替换指定字符
     */
    @GetMapping("/findByWords")
    public void selectOneByText(HttpServletResponse response,String text) throws IOException{
        //替换搜索内容中制定的字符串
        if(text != null && !"".equals(text)){
            final String s2 = "?";
            final String s1 = ",";
            if(text.contains(s2)){
                text = text.replace(s2, "");
            }else if(text.contains(s1)){
                text = text.replace(s1, "");
            }
            SxVideoRecording recording = new SxVideoRecording();
            recording.setVName(text);
            List<SxVideoRecording> sxVideoRecordings = sxVideoRecordingService.selectSxVideoRecordingList(recording);
            if(sxVideoRecordings.size() > 0){
                SxVideoRecording recording1 = sxVideoRecordings.get(0);
                writeJSON(recording1, response, "200", "查询成功");
            }
            writeJSON(null, response, "201", "暂无此课程");
        }
        writeJSON(null, response, "201", "请输入您要搜索得内容");
    }

PS替换源码

 /**
     * Replaces each substring of this string that matches the literal target
     * sequence with the specified literal replacement sequence. The
     * replacement proceeds from the beginning of the string to the end, for
     * example, replacing "aa" with "b" in the string "aaa" will result in
     * "ba" rather than "ab".
     *
     * @param  target The sequence of char values to be replaced
     * @param  replacement The replacement sequence of char values
     * @return  The resulting string
     * @since 1.5
     */
    public String replace(CharSequence target, CharSequence replacement) {
        return Pattern.compile(target.toString(), Pattern.LITERAL).matcher(
                this).replaceAll(Matcher.quoteReplacement(replacement.toString()));
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值