首页 > 代码库 > 将字符串复制到剪贴板

将字符串复制到剪贴板

1.需要的Java包

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;

2.代码实现

  /**
     * copy支付链接
     */
    @RequestMapping("/copyLink.do")
    @ResponseBody
    public String CopyLink(HttpServletRequest request){
        String url = request.getParameter("url");
        Clipboard sysClip = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable text = new StringSelection(url);
        sysClip.setContents(text, null);
        return "success";
    }

 

将字符串复制到剪贴板