• 截取a标签,获取a标签href 中的链接,获取,href 中的文本值,替换


        
    新任务信息:<br/>型号任务:【<a href='/sysware/task/wbs/wbsTaskMain.sitemesh?navigationHandlerBeanName=singleProjectMenuHandler&displayMenu=true&centerId=-1&currentMenuId=C97C34F16BD3E0CFE040007F01003309&taskId=82DC3AB8AC1C4525A376B2AE6B38D4BA' style='text-decoration:underline;color:blue;' target='_blank'>型号项目/0718/</a>】<br/>任务:【<a href='/sysware/task/wbs/taskTabs.sitemesh?currentMenuId=C96BB3B5C4B75752E040007F01001FF7&navigationHandlerBeanName=myTaskMenuHandler&displayMenu=true&taskId=5C6B0F79640144129E49F2C59B5F9FC1' style='text-decoration:underline;color:blue;' target='_blank'>a/a(校对)/</a>】。
    
    
    
    
    
    private void replaceA(MessageVo vo) {
            //获取taskId,判断是如果审签任务,不要链接
            String countAhref =vo.getMessageContent();
            String aString =countAhref.substring(countAhref.lastIndexOf("【"), countAhref.lastIndexOf("】"));
            String str = "<a href='(.+?)'";
            //Pattern p = Pattern.compile("<a[^>]*>([^<]*)</a>"); 
            Pattern p = Pattern.compile(str); 
             Matcher m = p.matcher(aString);
             String string="" ;
              while(m.find()) { 
                  string =m.group(1);//获取字符串,获取 href 链接 /sysware/task/wbs/taskTabs.sitemesh?currentMenuId=C96BB3B5C4B75752E040007F01001FF7&navigationHandlerBeanName=myTaskMenuHandler&displayMenu=true&taskId=5C6B0F79640144129E49F2C59B5F9FC1
              }
             String taskId = string.substring((string.lastIndexOf("="))+1, string.length());//获取taskId
             TaskObject taskObject =this.taskObjectService.getTaskObjectById(taskId);
             if(!SyswareUtil.isEmpty(taskObject)){
                 if(taskObject.getTaskFlag().equals("approvalTask")){
                     //去除链接
                     String n =countAhref.substring(countAhref.lastIndexOf("【"), countAhref.lastIndexOf("】")+1);
                     Pattern p2 = Pattern.compile("<a[^>]*>([^<]*)</a>"); //获取a标签中的内容
                     Matcher m2 = p2.matcher(n);
                     String string2="" ;
                      while(m2.find()) { 
                          string2 =m2.group(1);//获取a标签中的内容
                          vo.setMessageContent(countAhref.replace(n, string2));
                      }
                 }
             }
        }
     
    

      

  • 相关阅读:
    leetcode 309. Best Time to Buy and Sell Stock with Cooldown
    leetcode 714. Best Time to Buy and Sell Stock with Transaction Fee
    leetcode 32. Longest Valid Parentheses
    leetcode 224. Basic Calculator
    leetcode 540. Single Element in a Sorted Array
    leetcode 109. Convert Sorted List to Binary Search Tree
    leetcode 3. Longest Substring Without Repeating Characters
    leetcode 84. Largest Rectangle in Histogram
    leetcode 338. Counting Bits
    git教程之回到过去,版本对比
  • 原文地址:https://www.cnblogs.com/chizizhixin/p/9334012.html
Copyright © 2020-2023  润新知