当前位置: 首页 > news >正文

loveqq-framework 和 thymeleaf 整合遇到的 th:field 的坑,原来只有 spring 下才有效

相信大家在使用 thymeleaf 的时候,绝大部分都是和 springboot 一块儿使用的,所以 th:field 属性用的很舒服。

但实际上,th:field 只有在 spring 环境下下有用,单独的 thymeleaf 是不支持的!

为什么我知道呢,因为在把若依的底层 spring 剔除,替换为 loveqq 的时候,发现表单用的 th:field 的数据没有回显!!!

而网上都是 spring 环境下的,没办法,只能看看源码了。具体过程就不详细写了,这里直接贴一下如何实现 th:field。

其实很简单,只要自定义 AbstractAttributeTagProcessor 就可以了,代码如下:
首先是基础实现类 AbstractLoveqqAttributeTagProcessor:

package com.kfyty.loveqq.framework.boot.template.thymeleaf.autoconfig.processor;import com.kfyty.loveqq.framework.core.utils.BeanUtil;
import org.thymeleaf.context.ITemplateContext;
import org.thymeleaf.engine.AttributeDefinition;
import org.thymeleaf.engine.AttributeDefinitions;
import org.thymeleaf.engine.AttributeName;
import org.thymeleaf.engine.IAttributeDefinitionsAware;
import org.thymeleaf.model.IProcessableElementTag;
import org.thymeleaf.processor.element.AbstractAttributeTagProcessor;
import org.thymeleaf.processor.element.IElementTagStructureHandler;
import org.thymeleaf.templatemode.TemplateMode;
import org.thymeleaf.util.Validate;import java.util.HashMap;
import java.util.Map;/*** 描述: 标签处理器** @author kfyty725* @date 2024/6/05 18:55* @email kfyty725@hotmail.com*/
public abstract class AbstractLoveqqAttributeTagProcessor extends AbstractAttributeTagProcessor implements IAttributeDefinitionsAware {protected static final String ID_ATTR_NAME = "id";protected static final String TYPE_ATTR_NAME = "type";protected static final String NAME_ATTR_NAME = "name";protected static final String VALUE_ATTR_NAME = "value";protected static final String CHECKED_ATTR_NAME = "checked";protected static final String SELECTED_ATTR_NAME = "selected";protected static final String DISABLED_ATTR_NAME = "disabled";protected static final String MULTIPLE_ATTR_NAME = "multiple";protected AttributeDefinition idAttributeDefinition;protected AttributeDefinition typeAttributeDefinition;protected AttributeDefinition nameAttributeDefinition;protected AttributeDefinition valueAttributeDefinition;protected AttributeDefinition checkedAttributeDefinition;protected AttributeDefinition selectedAttributeDefinition;protected AttributeDefinition disabledAttributeDefinition;protected AttributeDefinition multipleAttributeDefinition;public AbstractLoveqqAttributeTagProcessor(final String dialectPrefix, final String elementName, final String attributeName, final int precedence) {super(TemplateMode.HTML, dialectPrefix, elementName, false, attributeName, true, precedence, false);}@Overridepublic void setAttributeDefinitions(AttributeDefinitions attributeDefinitions) {Validate.notNull(attributeDefinitions, "Attribute Definitions cannot be null");this.idAttributeDefinition = attributeDefinitions.forName(TemplateMode.HTML, ID_ATTR_NAME);this.typeAttributeDefinition = attributeDefinitions.forName(TemplateMode.HTML, TYPE_ATTR_NAME);this.nameAttributeDefinition = attributeDefinitions.forName(TemplateMode.HTML, NAME_ATTR_NAME);this.valueAttributeDefinition = attributeDefinitions.forName(TemplateMode.HTML, VALUE_ATTR_NAME);this.checkedAttributeDefinition = attributeDefinitions.forName(TemplateMode.HTML, CHECKED_ATTR_NAME);this.selectedAttributeDefinition = attributeDefinitions.forName(TemplateMode.HTML, SELECTED_ATTR_NAME);this.disabledAttributeDefinition = attributeDefinitions.forName(TemplateMode.HTML, DISABLED_ATTR_NAME);this.multipleAttributeDefinition = attributeDefinitions.forName(TemplateMode.HTML, MULTIPLE_ATTR_NAME);}@Overrideprotected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler structureHandler) {if (this.continueProcess(context, tag, attributeName, attributeValue, structureHandler)) {this.doProcessInternal(context, tag, attributeName, attributeValue, structureHandler);}}protected boolean continueProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler structureHandler) {return this.getMatchingAttributeName().getMatchingAttributeName().getAttributeName().equals(attributeName.getAttributeName());}protected abstract void doProcessInternal(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler structureHandler);public static Object buildEvaluatorContext(ITemplateContext context) {Map<String, Object> params = new HashMap<>();Object target = context.getSelectionTarget();// 先将目标属性放进去if (target != null) {params = BeanUtil.copyProperties(target);}// 搜索变量放进去for (String variableName : context.getVariableNames()) {Object variable = context.getVariable(variableName);params.put(variableName, variable);}return params;}
}

然后是 th:field 的实现:

package com.kfyty.loveqq.framework.boot.template.thymeleaf.autoconfig.processor;import com.kfyty.loveqq.framework.core.autoconfig.annotation.Component;
import com.kfyty.loveqq.framework.core.utils.OgnlUtil;
import org.thymeleaf.context.ITemplateContext;
import org.thymeleaf.engine.AttributeName;
import org.thymeleaf.model.IProcessableElementTag;
import org.thymeleaf.processor.element.IElementTagStructureHandler;
import org.thymeleaf.standard.util.StandardProcessorUtils;import java.util.Map;
import java.util.Objects;/*** 描述: input field 处理器** @author kfyty725* @date 2024/6/05 18:55* @email kfyty725@hotmail.com*/
@Component
public class LoveqqInputFieldTagProcessor extends AbstractLoveqqAttributeTagProcessor {public LoveqqInputFieldTagProcessor() {this("th");}public LoveqqInputFieldTagProcessor(String dialectPrefix) {super(dialectPrefix, "input", "field", 0);}@Overrideprotected void doProcessInternal(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler structureHandler) {Map<String, String> attributeMap = tag.getAttributeMap();String field = attributeValue.replaceAll("[*{}]", "");String value = OgnlUtil.compute(field, buildEvaluatorContext(context), String.class);if (!attributeMap.containsKey(NAME_ATTR_NAME)) {StandardProcessorUtils.setAttribute(structureHandler, this.nameAttributeDefinition, NAME_ATTR_NAME, field);}if (value != null && !attributeMap.containsKey(VALUE_ATTR_NAME)) {StandardProcessorUtils.setAttribute(structureHandler, this.valueAttributeDefinition, VALUE_ATTR_NAME, value);}if (value != null && Objects.equals(tag.getAttribute(TYPE_ATTR_NAME).getValue(), "radio")) {LoveqqInputCheckboxTagProcessor.processRadio(value, this.checkedAttributeDefinition, context, tag, structureHandler);}}
}

还有 th:checked 实现:

package com.kfyty.loveqq.framework.boot.template.thymeleaf.autoconfig.processor;import com.kfyty.loveqq.framework.core.autoconfig.annotation.Component;
import com.kfyty.loveqq.framework.core.utils.OgnlUtil;
import org.thymeleaf.context.ITemplateContext;
import org.thymeleaf.engine.AttributeDefinition;
import org.thymeleaf.engine.AttributeName;
import org.thymeleaf.exceptions.TemplateProcessingException;
import org.thymeleaf.model.IProcessableElementTag;
import org.thymeleaf.processor.element.IElementTagStructureHandler;
import org.thymeleaf.standard.util.StandardProcessorUtils;import java.util.Map;
import java.util.Objects;/*** 描述: input checkbox 处理器** @author kfyty725* @date 2024/6/05 18:55* @email kfyty725@hotmail.com*/
@Component
public class LoveqqInputCheckboxTagProcessor extends AbstractLoveqqAttributeTagProcessor {public LoveqqInputCheckboxTagProcessor() {this("th");}public LoveqqInputCheckboxTagProcessor(String dialectPrefix) {super(dialectPrefix, "input", "checked", 0);}@Overrideprotected void doProcessInternal(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler structureHandler) {Map<String, String> attributeMap = tag.getAttributeMap();String express = attributeValue.replaceAll("[*${}]", "");String value = OgnlUtil.compute(express, buildEvaluatorContext(context), String.class);// radio checked 处理if (value != null && Objects.equals(tag.getAttribute(TYPE_ATTR_NAME).getValue(), "radio")) {processRadio(value, this.checkedAttributeDefinition, context, tag, structureHandler);}// 其他 checked 处理else {if (value != null && !attributeMap.containsKey(CHECKED_ATTR_NAME)) {StandardProcessorUtils.setAttribute(structureHandler, this.checkedAttributeDefinition, CHECKED_ATTR_NAME, value);}}}public static void processRadio(String value, AttributeDefinition checkedAttributeDefinition, ITemplateContext context, IProcessableElementTag tag, IElementTagStructureHandler structureHandler) {String checkedValue;if (tag.getAttribute("value") != null) {checkedValue = tag.getAttributeValue("value");} else if (tag.getAttribute("th:value") != null) {String express = tag.getAttributeValue("th:value").replaceAll("[*${}]", "");checkedValue = OgnlUtil.compute(express, buildEvaluatorContext(context), String.class);} else {throw new TemplateProcessingException("The input radio tag not found value.");}if (Objects.equals(checkedValue, value)) {StandardProcessorUtils.setAttribute(structureHandler, checkedAttributeDefinition, CHECKED_ATTR_NAME, value);}}
}

最后,需要把他们放入方言实现中:

package com.kfyty.loveqq.framework.boot.template.thymeleaf.autoconfig.dialect;import lombok.RequiredArgsConstructor;
import org.thymeleaf.processor.IProcessor;
import org.thymeleaf.standard.StandardDialect;import java.util.Set;/*** 描述: loveqq 方言实现** @author kfyty725* @date 2024/6/05 18:55* @email kfyty725@hotmail.com*/
@RequiredArgsConstructor
public class LoveqqStandardDialect extends StandardDialect {private final Set<IProcessor> processors;@Overridepublic Set<IProcessor> getProcessors(String dialectPrefix) {Set<IProcessor> processorSet = super.getProcessors(dialectPrefix);if (this.processors != null) {processorSet.addAll(this.processors);}return processorSet;}
}

使用 LoveqqStandardDialect 方言实现,并创建的时候将上面的两个处理器放进来就可以了。

相关文章:

loveqq-framework 和 thymeleaf 整合遇到的 th:field 的坑,原来只有 spring 下才有效

相信大家在使用 thymeleaf 的时候&#xff0c;绝大部分都是和 springboot 一块儿使用的&#xff0c;所以 th:field 属性用的很舒服。 但实际上&#xff0c;th:field 只有在 spring 环境下下有用&#xff0c;单独的 thymeleaf 是不支持的&#xff01; 为什么我知道呢&#xff…...

hugging face:大模型时代的github介绍

1. Hugging Face是什么&#xff1a; Hugging Face大模型时代的“github”&#xff0c;很多人有个这样的认知&#xff0c;但是我觉得不完全准确&#xff0c;他们相似的地方在于资源丰富&#xff0c;github有各种各样的软件代码和示例&#xff0c;但是它不是系统的&#xff0c;没…...

如何快速绘制logistic回归预测模型的ROC曲线?

临床预测模型&#xff0c;也是临床统计分析的一个大类&#xff0c;除了前期构建模型&#xff0c;还要对模型的预测能力、区分度、校准度、临床获益等方面展开评价&#xff0c;确保模型是有效的&#xff01; 其中评价模型的好坏主要方面还是要看区分度和校准度&#xff0c;而区分…...

实现具有多个实现类的接口并为每个实现类定义一个名字的方法

在Java中&#xff0c;实现具有多个实现类的接口并为每个实现类定义一个名字的方法&#xff0c;可以通过使用工厂模式或服务定位器模式来完成。以下是使用工厂模式的一个示例&#xff1a; 定义接口和实现类 首先&#xff0c;定义一个接口和多个实现类&#xff1a; // 接口 publ…...

Linux解压缩命令

文章目录 前言1. tar - 打包和压缩文件2. gzip - 压缩文件3. gunzip - 解压缩gzip文件4. bzip2 - 压缩文件5. unzip - 解压缩zip文件6. zip - 压缩文件为zip格式7. 7z - 7-Zip压缩工具8. unrar - 解压缩RAR文件 前言 解压缩文件在Linux中是常见的任务&#xff0c;以下是一些常…...

如何在 Ubuntu 14.04 上使用 Iptables 实现基本防火墙模板

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到网站。 简介 实施防火墙是保护服务器的重要步骤。其中很大一部分是决定强制执行对网络流量的限制的个别规则和策略。像 iptables 这样的防火墙…...

jasypt对yml文件进行加密解密

目录 0.背景 1.依赖 2.yml文件 3.加密操作 0.背景 在日常开发中&#xff0c;我们一般会把账号密码以及一些用到的各种第三方服务的Access_Key都放入yml文件中&#xff0c;这时就有必要对yml文件进行加密处理了&#xff0c; jasypt是一款简单的对yml加密的工具 1.依赖 &l…...

vue3-openlayers 使用tianditu,wmts和xyz等source加载天地图切片服务

本篇介绍一下使用vue3-openlayers加载天地图切片&#xff0c;三种方法&#xff1a; 使用tianditu&#xff08;ol-source-tianditu内部实现其实用的wmts&#xff09;使用wmts&#xff08;ol-source-wmts&#xff09;使用xyz&#xff08;ol-source-xyz&#xff09; 1 需求 vue…...

npm、yarn、pnpm 最新国内镜像源设置和常见问题解决

1. npm 设置国内镜像源 1.1 镜像源概述 镜像源是软件包管理工具用来下载和安装软件包的服务器地址。由于网络原因&#xff0c;直接使用官方源可能会导致速度慢或连接失败的问题。国内镜像源可以提供更快的访问速度和更稳定的连接。 1.2 镜像源的选择 国内有许多可用的npm镜…...

Qt Object:智能即时聊天室项目

目录 1.项目介绍 2.设计思路 3.Pro文件配置 4.项目演示 5.项目开源 项目介绍 智能即时聊天室系统&#xff08;AIChatProject&#xff09;是一个高效、灵活的即时通讯解决方案。它融合了百度的开源大型语言模型——文心一言&#xff0c;通过API接口实现深度集成。系统专为聊天和…...

php,python aes加密反解

1. python版本 import base64 from Crypto.Cipher import AES from Crypto.Util.Padding import pad, unpadclass AESUtilCBC:def __init__(self, key, iv):self.key key.encode(utf-8)self.iv iv.encode(utf-8)self.pad_length AES.block_sizedef encrypt(self, data):try…...

基于Java学生选课管理系统设计和实现(源码+LW+调试文档+讲解等)

&#x1f497;博主介绍&#xff1a;✌全网粉丝10W,CSDN作者、博客专家、全栈领域优质创作者&#xff0c;博客之星、平台优质作者、专注于Java、小程序技术领域和毕业项目实战✌&#x1f497; &#x1f31f;文末获取源码数据库&#x1f31f; 感兴趣的可以先收藏起来&#xff0c;…...

阅读笔记——《Large Language Model guided Protocol Fuzzing》

【参考文献】Meng R, Mirchev M, Bhme M, et al. Large language model guided protocol fuzzing[C]//Proceedings of the 31st Annual Network and Distributed System Security Symposium (NDSS). 2024.&#xff08;CCF A类会议&#xff09;【注】本文仅为作者个人学习笔记&a…...

C#委托:事件驱动编程的基石

目录 了解委托 委托使用的基本步骤 声明委托(定义一个函数的原型&#xff1a;返回值 参数类型和个数&#xff09; 根据委托定义的函数原型编写需要的方法 创建委托对象&#xff0c;关联“具体方法” 通过委托调用方法&#xff0c;而不是直接使用方法 委托对象所关联的方…...

Git的下载安装及可视化工具小乌龟

一、 Git 的下载 第1步&#xff1a;下载Git&#xff0c;下载地址&#xff1a;Git for Windows 这个就需要去 Git 官网下载对应系统的软件了&#xff0c;下载地址为 git-scm.com或者gitforwindows.org&#xff0c;或者阿里镜像&#xff08;感谢评论区的星悸迷航同学&#…...

【面试实战】# 并发编程之线程池配置实战

1.先了解线程池的几个参数含义 corePoolSize (核心线程池大小): 作用: 指定了线程池维护的核心线程数量&#xff0c;即使这些线程处于空闲状态&#xff0c;它们也不会被回收。用途: 核心线程用于处理长期的任务&#xff0c;保持最低的线程数量&#xff0c;以减少线程的创建和…...

Pytest 读取excel文件参数化应用

本文是基于Pytest框架&#xff0c;读取excel中的文件&#xff0c;传入页面表单中&#xff0c;并做相应的断言实现。 1、编辑媒体需求 首先明确一下需求&#xff0c;我们需要对媒体的表单数据进行编辑&#xff0c;步骤如下&#xff1a; 具体表单如下图所示 1、登录 2、点击我…...

qt 一个可以拖拽的矩形

1.概要 2.代码 2.1 mycotrl.h #ifndef MYCOTRL_H #define MYCOTRL_H#include <QWidget> #include <QMouseEvent>class MyCotrl: public QWidget {Q_OBJECT public://MyCotrl();MyCotrl(QWidget *parent nullptr); protected:void paintEvent(QPaintEvent *even…...

C# 启动exe 程序

(1) publicbool Start () System.Diagnostics.Process process new System.Diagnostics.Process(); process.StartInfo.FileName "iexplore.exe"; //IE浏览器&#xff0c;可以更换 process.StartInfo.Arguments "http://www.baidu.com"; process.…...

Netty中的Reactor模型实现

Netty版本&#xff1a;4.1.17 Reactor模型是Doug Lea在《Scalable IO in Java》提出的&#xff0c;主要是针对NIO的。 其中的主从Reactor模式在Netty中的配置如下&#xff1a; EventLoopGroup bossGroup new NioEventLoopGroup(1); EventLoopGroup workerGroup new NioEv…...

dll丢失应该怎么解决,总结5种解决DLL丢失问题的方法

在数字时代&#xff0c;我们与计算机的每一天都密不可分。然而&#xff0c;就像所有技术产品一样&#xff0c;我们的计算设备也时不时地会出现一些问题&#xff0c;让人头疼不已。就在上周&#xff0c;我遭遇了一个令人崩溃的技术挑战——DLL文件丢失。这个看似微不足道的小问题…...

dial tcp 10.96.0.1:443: connect: no route to host

1、创建Pod一直不成功&#xff0c;执行kubectl describe pod runtime-java-c8b465b98-47m82 查看报错 Warning FailedCreatePodSandBox 2m17s kubelet Failed to create pod sandbox: rpc error: code Unknown desc failed to setup network for…...

VScode创建ROS项目 ROS集成开发环境

ROS使用VScode创建项目步骤 1.创建ROS工作空间2.启动VScode3.VScode编译ROS4.创建ROS功能包C语言开发Python语言开发 本文章介绍了如何在Ubuntu18.04系统下搭建VScode 的ROS项目 搭建项目分为一下几个步骤&#xff1a; 1.创建ROS工作空间 创建一个demo的ROS工作空间&#xff0…...

nodejs从基础到实战学习笔记-nodejs简介

一、Node.js简介 • Node.js是一个能够在服务器端运行JavaScript的开放源代码、跨平台JavaScript运行环境。 • Node采用Google开发的V8引擎运行js代码&#xff0c;使用事件驱动、非阻塞和异步I/O模型等技术来提高性能&#xff0c;可优化应用程序的传输量和规模。 1.1 特性 …...

2024年最新版------二进制安装部署Kubernetes(K8S)集群

Kubernetes二进制集群部署 文章目录 Kubernetes二进制集群部署资源列表基础环境一、环境准备1.1、绑定映射关系1.2、所有主机安装Docker1.3、所有主机设置iptables防火墙 二、生成通信加密证书2.1、master上成功CA证书2.2.1、创建证书存放位置并安装证书生成工具2.2.2、拷贝证书…...

【mysql】关键词搜索实现

关键词搜索实现两种方式 -- 方式1 模糊匹配搜索 -- 场景一&#xff1a;搜索出来地址内包含‘李’和‘中国’的 select * from tn_md_cust_link where address like concat (%李%) or address like concat (%中国%) -- 场景二&#xff1a;搜索地址或者名称包含 ‘181’ 的 …...

Python面试十问2

一、如何使用列表创建⼀个DataFrame # 导入pandas库 import pandas as pd# 创建一个列表&#xff0c;其中包含数据 data [[A, 1], [B, 2], [C, 3]]# 使用pandas的DataFrame()函数将列表转换为DataFrame df pd.DataFrame(data, columns[Letter, Number]) # 列名# 显示创建的…...

C# OpenCvSharp 图像处理函数-颜色通道-cvtColor

使用 OpenCvSharp 中的 cvtColor 函数进行图像颜色转换 在图像处理领域,颜色空间转换是一个非常常见的操作。OpenCvSharp 提供了一个强大的函数 cvtColor 来处理这类转换。本文将详细介绍 cvtColor 函数的使用方法,并通过具体的示例演示如何在实际项目中应用这些知识。 函数…...

总结之LangChain(三)——模型IO缓存

一、聊天模型缓存 LangChain为聊天模型提供了一个可选的缓存层。这有两个好处&#xff1a; 如果您经常多次请求相同的完成结果&#xff0c;它可以通过减少您对LLM提供程序的API调用次数来帮您节省费用。 它可以通过减少您对LLM提供程序的API调用次数来加快您的应用程序速度。…...

判断一个Java服务是不是GateWay

方法 直接在对应服务的url后变加上后缀/actuator/gateway/routes&#xff0c;看是否会返回Gateway的路由信息。 如果返回了GateWay的路由列表&#xff0c;则该服务为Gateway服务。...

网站怎么推广怎么做/百度网站收录

断点调试的启动方式android studio启动断点调试的方法有两种&#xff0c;其一是下好断点&#xff0c;然后点击以Debug的形式编译运行程序。第二种方式是在程序运行中启动断点调试。方式&#xff1a;启动app后&#xff0c;点击RUN—>,弹出如下的提示框&#xff1a;在需要的地…...

江苏省建设工程信息服务平台/怎样优化关键词到首页

1.RLC电路 2.孙鑫视频 3.ADO数据库 4.SQL Server 5.验证读txt文件的同时压缩保存是否正常。写一个压缩程序z-ip_utils_src.zip 参考这个。搞清楚一般C压缩文件是调系统的压缩软件还是自己利用开源算法写压缩方法&#xff1f; 6.使用数据库开发的桌面程序发布的时候怎么办&…...

cm域名网站/成人馆店精准引流怎么推广

某培训机构的课程表&#xff0c;不想去培训的&#xff0c;可以按照这个自学。 1 第一阶段JAVASCRIPT高级 1 1 JavaScript高级 1 1 1 call、apply、bind、new等原理解析1 1 2 原型链深入1 1 3 闭包深入1 1 4 执行上下文和作用域链1 1 5 作用域链1 2 ES6深入学习 1 2 1 常量1 2 2…...

徐州手机网站建设公司哪家好/搜索引擎优化答案

2017 年 10 月 15 日&#xff0c;Kubernetes End User Conference (KEUC) 即将揭开神秘面纱。聚焦 Kubernetes 中国行业应用与技术落地&#xff0c;致力于为业界带来最新 Kubernetes 与容器技术和行业应用案例展示&#xff0c;本次大会邀请到了 Google、VMware、华为、IBM、网易…...

校园微网站建设方案ppt模板/百度品牌推广

Myeclipse中其实不止tomcat支持的jre和项目工程编译环境jre版本不一致这一种原因会导致异常&#xff1a;Bad version in .class file&#xff1b;数据库链接也会报这种异常&#xff0c;很奇怪&#xff0c;不知道的话就被引入歧途了。转载于:https://blog.51cto.com/3596022/122…...

模板网站可以做seo吗/有做网站的吗

题目描述 求一张图的严格次小生成树的边权和&#xff0c;保证存在。 输入 第一行包含两个整数N 和M&#xff0c;表示无向图的点数与边数。 接下来 M行&#xff0c;每行 3个数x y z 表示&#xff0c;点 x 和点y之间有一条边&#xff0c;边的权值为z。 输出 包含一行&#xff0c;…...