gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
我希望通过java来生成一些html代码,要求如下: 1. 生成的代码包含两个p标签 2. 第一个p标签内包含一个img标签(主图) 3. 第二个p标签内包含若干个a标签 3.…
- User
我希望通过java来生成一些html代码,要求如下:
- 生成的代码包含两个p标签
- 第一个p标签内包含一个img标签(主图)
- 第二个p标签内包含若干个a标签
- 每个a标签的slot内包含一个img标签(附图) 以下代码是一个例子:
<p> <img class="alignnone size-medium wp-image-3139" src="https://www.hottopstyle.com/wp-content/uploads/2023/04/a072-452x600.png" alt="" /> </p> <p> <a href="https://www.amazon.com/Acelitt-Waisted-Jumpsuits-Rompers-Pockets/dp/B09YHG7SS2/ref=sr_1_18?crid=1VQ3JTVQLWN45&keywords=Jumpsuit%3A%2Bwhite%2Blinen%2C%2Bsquare%2Bneckline&qid=1681046367&sprefix=jumpsuit%2Bwhite%2Blinen%2C%2Bsquare%2Bneckline%2Caps%2C382&sr=8-18&th=12Bwhite%2Blinen%2C%2Bsquare%2Bneckline%2Caps%2C382&sr=8-18&th=1" ><img src="https://www.hottopstyle.com/wp-content/uploads/2023/04/a072-l1.jpeg" alt="" width="80" height="80" /></a> <a href="https://www.amazon.com/ASTR-label-Womens-Sleeveless-Jumpsuit/dp/B083PJYNMD/ref=sr_1_227?crid=Z1BE8RQM0Y8&keywords=white%2Blinen%2Bjumpsuit%2Bfor%2Bwomen&qid=1681046721&sprefix=Jumpsuit%3A%2Bwhite%2Blinen%2C%2Caps%2C489&sr=8-227&th=1" ><img src="https://www.hottopstyle.com/wp-content/uploads/2023/04/a072-l1.jpg" alt="" width="80" height="80" /></a> <a href="https://eur.shein.com/Double-Crazy-Cut-Out-Backless-Wide-Leg-Jumpsuit-p-14028938-cat-1860.html?src_identifier=st%3D2%60sc%3Dwhite%20linen%20jumpsuit%20for%20women%60sr%3D0%60ps%3D1&src_module=search&src_tab_page_id=page_goods_detail1681025897630&mallCode=1" ><img src="https://www.hottopstyle.com/wp-content/uploads/2023/04/a072-l2.jpeg" alt="" width="80" height="80" /></a> <a href="https://www.amazon.com/Fossil-ZB7412200-Ryder-Satchel-Brown/dp/B0781ZBGKQ/ref=sr_1_50?crid=1BWEPHXKTEITZ&keywords=leather%2Btote%2Bbag%2BTop%2BHandle%2BBag%2Bfor%2Bwomen&qid=1681048240&sprefix=leather%2Btote%2Bbag%2Btop%2Bhandle%2Bbag%2Bfor%2Bwomen%2Caps%2C811&sr=8-50&th=1" ><img src="https://www.hottopstyle.com/wp-content/uploads/2023/04/a072-l4.jpeg" alt="" width="80" height="80" /></a> </p> - Assistant
以下是用Java生成上述HTML代码的示例代码:
public static void main(String[] args) { String imgUrl = "https://www.hottopstyle.com/wp-content/uploads/2023/04/a072-452x600.png"; List<String> aUrls = Arrays.asList( "https://www.amazon.com/Acelitt-Waisted-Jumpsuits-Rompers-Pockets/dp/B09YHG7SS2/ref=sr_1_18?crid=1VQ3JTVQLWN45&keywords=Jumpsuit%3A%2Bwhite%2Blinen%2C%2Bsquare%2Bneckline&qid=1681046367&sprefix=jumpsuit%2Bwhite%2Blinen%2C%2Bsquare%2Bneckline%2Caps%2C382&sr=8-18&th=12Bwhite%2Blinen%2C%2Bsquare%2Bneckline%2Caps%2C382&sr=8-18&th=1", "https://www.amazon.com/ASTR-label-Womens-Sleeveless-Jumpsuit/dp/B083PJYNMD/ref=sr_1_227?crid=Z1BE8RQM0Y8&keywords=white%2Blinen%2Bjumpsuit%2Bfor%2Bwomen&qid=1681046721&sprefix=Jumpsuit%3A%2Bwhite%2Blinen%2C%2Caps%2C489&sr=8-227&th=1", "https://eur.shein.com/Double-Crazy-Cut-Out-Backless-Wide-Leg-Jumpsuit-p-14028938-cat-1860.html?src_identifier=st%3D2%60sc%3Dwhite%20linen%20jumpsuit%20for%20women%60sr%3D0%60ps%3D1&src_module=search&src_tab_page_id=page_goods_detail1681025897630&mallCode=1", "https://www.amazon.com/Fossil-ZB7412200-Ryder-Satchel-Brown/dp/B0781ZBGKQ/ref=sr_1_50?crid=1BWEPHXKTEITZ&keywords=leather%2Btote%2Bbag%2BTop%2BHandle%2BBag%2Bfor%2Bwomen&qid=1681048240&sprefix=leather%2Btote%2Bbag%2Btop%2Bhandle%2Bbag%2Bfor%2Bwomen%2Caps%2C811&sr=8-50&th=1" ); String html = generateHtml(imgUrl, aUrls); System.out.println(html); } private static String generateHtml(String imgUrl, List<String> aUrls) { StringBuilder sb = new StringBuilder(); sb.append("<p>\n") .append(" <img\n") .append(" class=\"alignnone size-medium wp-image-3139\"\n") .append(" src=\"").append(imgUrl).append("\"\n") .append(" alt=\"\"\n") .append(" />\n") .append("</p>\n") .append("<p>\n"); for (String aUrl : aUrls) { sb.append(" <a href=\"").append(aUrl).append("\">\n") .append(" <img\n") .append(" src=\"https://www.hottopstyle.com/wp-content/uploads/2023/04/a072-l1.jpeg\"\n") .append(" alt=\"\"\n") .append(" width=\"80\"\n") .append(" height=\"80\"\n") .append(" />\n") .append(" </a>\n"); } sb.append("</p>"); return sb.toString(); }