test-data 相关问题


使用 group by [duplicate] 计算单词总数

我想按id统计文本组中的单词总数: 自由<- data.frame(id=rep(1:3, 2), tx=c("test one. test two", "this is a test. again test", "test two",...


Bootstrap Popover - 如何在文本弹出窗口中添加链接?

我使用 bootstrap 3 popover。 现在我想要文本 popvover 上的链接。 代码: 我使用 bootstrap 3 popover. 现在我想要文本 popvover 上的链接。 代码: <a href="#" role="button" class="btn popovers" data-toggle="popover" title="" data-content="test content <a href="" title="test add link">link on content</a>" data-original-title="test title" > test link </a> 但是当我在 html 中开始代码时,我看到: <a href="#" role="button" class="btn popovers" data-toggle="popover" title="" data-content="test content &lt;a href=" "="">link on content</a> " data-original-title="test title" &gt; test link 我知道符号中的问题"但我不知道在链接中添加链接... 请告诉我如何编写正确的代码? 附言:如果问题已经存在,请给我链接。 您需要在初始化弹出窗口时传递具有值html的true选项,如下所示。 演示 JS: $("[data-toggle=popover]") .popover({html:true}) HTML: <a href="#" role="button" class="btn popovers" data-toggle="popover" title="" data-content="test content <a href='' title='test add link'>link on content</a>" data-original-title="test title" target="_blank" > test link </a> 只需使用属性data-html="true". <button data-toggle="popover" data-content="Link: <a href='xyz.com'>XYZ</a>" data-html="true"> CLICK </button> 我使用了 data-trigger="focus" 并且弹出窗口内容中的链接有问题。如果在链接上单击鼠标按钮并按住一段时间,则弹出窗口会消失并且链接“不起作用”。一些客户对此表示抱怨。 HTML <a href="#" role="button" class="btn popovers" data-toggle="popover" data-trigger="focus" title="" data-content="test content <a href='/' title='test add link'>link on content</a>" data-original-title="test title">test link</a> JS $("[data-toggle=popover]").popover({html:true}) 您可以在这里重现问题. 我使用以下代码来解决问题: data-trigger="manual" 在 html 和 $("[data-toggle=popover]") .popover({ html: true}) .on("focus", function () { $(this).popover("show"); }).on("focusout", function () { var _this = this; if (!$(".popover:hover").length) { $(this).popover("hide"); } else { $('.popover').mouseleave(function() { $(_this).popover("hide"); $(this).off('mouseleave'); }); } }); 如果你想使用焦点 and 弹出窗口内的链接,你需要防止弹出窗口在点击内部时关闭。我找到的最干净的解决方案是在具有preventDefault类的Popup中.popover点击 $('body') .on('mousedown', '.popover', function(e) { e.preventDefault() }); }); <a href="#" class="btn popovers" data-toggle="popover" title="" data-content="test content <a href='' title='test add link'>link on content</a>" data-html="true"><i class="glyphicon glyphicon-info-sign"></i></a> 只需添加 data-html="true" 即可使用链接属性 :) 值得注意的是,虽然给出的答案是正确的 - 当应用 data-trigger="focus" 时,链接会导致问题。正如我从客户发现如果在弹出窗口上快速发生单击,链接将被操作,如果用户按住他们的鼠标按钮然后不幸的是触发器启动并出现弹出窗口。因此,简而言之,请考虑是否需要链接并计划点击次数。 $("body").on("mousedown",".my-popover-content a",function(e){ document.location = e.target.href; }); 对我有用:基本上,把事情掌握在自己手中。同样,这是带有弹出选项 html: true、sanitize: false 和 trigger : "focus"


sklearn:MinMaxScaler rowwise 在训练和测试集上

我试过了 定标器 = MinMaxScaler() train = scaler.fit_transform(train.T).T test = scaler.transform(test.T).T 但我发现尺寸不匹配。


在 R 中进行测试/训练拆分的有效方法

在仔细阅读 R 测试/训练拆分参考后,以下模式似乎很流行: 参考资料之一:SPLITTING DATA INTO TRAINING AND TEST SET WITH R 以下代码拆分 70% o...


Springboot + postgresql 数组查询无效

我收到错误 java.lang.IllegalArgumentException:org.postgresql.util.PSQLException:查询未返回任何结果。 当我调用 itemrepository.findByName("test") 时 我的项目M...


Spring Boot + PostgreSQL 数组无效查询

我收到错误 java.lang.IllegalArgumentException:org.postgresql.util.PSQLException:查询未返回任何结果。 当我调用 itemrepository.findByName("test") 时 我的项目M...


Docker 复制并更改所有者

给出以下 Dockerfile 来自 ubuntu 运行组添加我的组 运行 useradd -ms /bin/bash -G mygroup john MKDIR /数据 COPY test/ /data/测试数据 运行 chown -R john:mygroup /data 命令 /bin/bash 在我...


Backtransformation coefficients, confidence intervals from Box-Cox in R

我创建了模型并对响应使用了 box cox 变换: model1.5 <- lm(tas1 ~ station1, data=test, x=TRUE, y=TRUE) bc <-boxcox(model1.5) lambda <- bc$x[which.max(bc$y)]


如何使用正则表达式来匹配img标签和html字符串?

var str = '"一些文本"; 变量 reg = ??? 如何制作 ' var str = '<img src="test>test" alt="test > test test" > "some text'; var reg = ??? 如何制作'<img src="test>test" alt="test > test test" >">'.match(reg)[0] === '<img src="test>test" alt="test > test test" >' 尝试过这个正则表达式/<\s*(img)[^>]+(>[\r|\n|\s]*<\/\1>|\/?>)/,但没有成功。 var str = '<img src="test>test" alt="test > test test" > "some text'; var reg = /<img[^>]*>/; var result = str.match(reg)[0]; console.log(result); Output: '<img src="test>test" alt="test > test test" >'


在使用JPA的情况下,无法从表中获取updateBy字段。

我有一个表entity_detail,它的结构如下: id detail_id center_code Comments updated_by updated_on created_on created_by 1 121 0 Test user ...


lmer:“错误:每个分组因子的级别数必须是< number of observations

我正在使用以下模型: 适合嵌套<- lmer(value.my ~ value.open + age.true + (1|year/curveID), data = test, REML = F) I am receiving this error in R: number of lev...


如何在 python pandas 中生成用于促销计划用例的数据?

背景:业务目标是建立一个机器学习模型,根据产品在促销期间和非促销期间的历史表现来预测利润的提升...


如何使用Jquery从Json字符串数据中删除双引号

我的 jQuery 脚本如下: jQuery.ajax({ 类型:“获取”, 网址:网址, 数据:'action=getStatus', }).done(函数(响应){ var data = jQuery.parseJSON(response); var test = 数据['


从命令行运行arangodb文本文件

描述 在 MySQL 世界中,可以创建一个 SQL 文件并从命令行执行它。 mysql -h 主机名 -u 用户数据库 < path/to/sqlfile.sql This is especially useful for test data. I've


重采样方法与 scipy.stats.chi2_contigency 的卡方检验 P 值

此问题参考书籍“O'Relly Practical Statistics for Data Scientists 2nd Edition”第 3 章,session Chi-Square Test。 该书提供了一个卡方测试用例的示例,


将嵌套的 JSON 数组转换为 CSV 文件中的单独列

我有一个如下所示的 JSON 文件: { “id”:10011, "title": "测试程序", “蛞蝓”:“蛞蝓”, "url": "http://test.test", “电子邮件”:“[email protected]”, “链接”:“http://测试...


Jest 中的错误“TestingLibraryElementError:无法通过以下方式找到元素:[data-testid="sample-data-test-id"]”

预期行为 让 Jest 渲染并找到我正在测试的元素,这样我的规范就可以通过 当前行为 我想我正在尝试编写的规范应该很简单。我有一个组件(我们...


引导复选框表

我有以下引导表。我想获得选择复选框,但是当我单击该按钮时它不起作用。 这是我的桌子: 我有以下引导表。我想获得选择复选框,但是当我单击按钮时它不起作用。 这是我的桌子: <div class="main"> <button class="btn btn-default" id="get-selections"> Get Selections </button> <table id="table-methods-table" data-toggle="table" data-url="data_out.json" data-height="200"> <thead> <tr> <th data-field="state" data-checkbox="true"></th> <th data-field="PatName">Name</th> <th data-field="KinID">Stars</th> <th data-field="Service">Forks</th> </tr> </thead> </table> </div> 这是我的 JavaScript: <script> $(document).ready(function(){ $("#table-methods").next().click(function () { $(this).hide(); var id = 0, getRows = function () { var rows = []; for (var i = 0; i < 10; i++) { rows.push({ id: PatName, name: 'test' + PatName, price: '$' + PatName }); id++; } return rows; }, // init table use data $table = $("#table-methods-table").bootstrapTable({ data: getRows() }); $("#get-selections").click(function () { alert("Selected values: " + JSON.stringify($table.bootstrapTable("getSelections"))); }); }); }); 如何获得选择复选框? 你可以做一些非常简单的事情: $('#get-selections').click(function() { var dataFieldValue = $('#table-methods-table th[data-checkbox="true"]').data('field'); alert (dataFieldValue) }); 在您的示例中,代码显示“状态”。 更新1: 在JSFiddle上查看 将 #get-selections 回调放在文档就绪事件之后,如下所示: $(document).ready(function() { $('#get-selections').click(function() { var dataFieldValue = $('#table-methods-table th[data-checkbox="true"]').data('field'); alert (dataFieldValue) }); // ... and your script here }); 编辑此内容 <table id="table-methods-table" data-toggle="table" data-url="data_out.json" data-height="200" data-click-to-select="true">


解压一些文件并创建一些同名文件夹

我有以下问题: 如果我有 .zip 文件,则会创建文件夹,但不会提取任何数据并将其放置在完整文件夹中。 zipfiles = [os.path.basename(x) for x in glob.glob('C:/Data/Test/


如何使用adf中的派生列和列模式将多列除以4?

如何使用adf中的派生列和列模式将多个列除以4? 我有多个以字符开头的列:“test” 所有这些列都必须除以 4。我...


PayPal 捐赠的 IPN 监听器未被正确调用 PHP

我有一个 PayPal 捐赠 IPN 的监听器。然而,它没有被调用,PayPal 沙箱中也没有日志。代码是: donations.php: 我有一个 PayPal 捐赠 IPN 的监听器。然而,它没有被调用,PayPal 沙箱中也没有日志。代码是: donations.php: <?php // For test payments we want to enable the sandbox mode. If you want to put live // payments through then this setting needs changing to `false`. $enableSandbox = true; // Database settings. Change these for your database configuration. $dbConfig = [ 'host' => 'localhost', 'username' => 'xxxx', 'password' => 'xxxx', 'name' => 'xxxx' ]; // PayPal settings. Change these to your account details and the relevant URLs // for your site. $paypalConfig = [ 'email' => $enableSandbox ? '[email protected]' : '[email protected]', 'return_url' => 'https://example.com/index.php?page=/donation-successful.php', 'cancel_url' => 'https://example.com/index.php?page=/donation-cancelled.php', 'notify_url' => 'https://example.com/donations.php', ]; $paypalUrl = $enableSandbox ? 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr' : 'https://ipnpb.paypal.com/cgi-bin/webscr'; function verifyTransaction($data) { global $paypalUrl; $req = 'cmd=_notify-validate'; foreach ($data as $key => $value) { $value = urlencode(stripslashes($value)); //$value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i', '${1}%0D%0A${3}', $value); // IPN fix $req .= "&$key=$value"; } $ch = curl_init($paypalUrl); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $req); curl_setopt($ch, CURLOPT_SSLVERSION, 6); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close')); $res = curl_exec($ch); if (!$res) { $errno = curl_errno($ch); $errstr = curl_error($ch); curl_close($ch); throw new Exception("cURL error: [$errno] $errstr"); } $info = curl_getinfo($ch); // Check the http response $httpCode = $info['http_code']; if ($httpCode != 200) { throw new Exception("PayPal responded with http code $httpCode"); } curl_close($ch); return $res == 'VERIFIED'; } function checkTxnid($txnid) { $db = new mysqli($dbConfig['host'], $dbConfig['username'], $dbConfig['password'], $dbConfig['name']); $txnid = $db->real_escape_string($txnid); $results = $db->query('SELECT * FROM `donations` WHERE txnid = \'' . $txnid . '\''); return ! $results->num_rows; } function addPayment($data) { $db = new mysqli($dbConfig['host'], $dbConfig['username'], $dbConfig['password'], $dbConfig['name']); if (is_array($data)) { if ($db->query("INSERT INTO 'donations' (txnid, payment_amount, payment_status, createdtime) VALUES('" . $data["txn_id"] . "', '" . $data["payment_amount"] . "', '" . $data["payment_status"] . "', '" . date("Y-m-d H:i:s") . "')")) { return true; } } return false; } // Check if paypal request or response // STEP 1: read POST data // Reading POSTed data directly from $_POST causes serialization issues with array data in the POST. // Instead, read raw POST data from the input stream. $raw_post_data = file_get_contents('php://input'); $raw_post_array = explode('&', $raw_post_data); $data = array(); foreach ($raw_post_array as $keyval) { $keyval = explode ('=', $keyval); if (count($keyval) == 2) { $data[$keyval[0]] = urldecode($keyval[1]); } } if (!isset($data["txn_id"]) && !isset($data["txn_type"])) { // Set the PayPal account. $data['business'] = $paypalConfig['email']; // Set the PayPal return addresses. $data['return'] = stripslashes($paypalConfig['return_url']); $data['cancel_return'] = stripslashes($paypalConfig['cancel_url']); $data['notify_url'] = stripslashes($paypalConfig['notify_url']); // Set the currency so that these aren't overridden by the form data. $data['currency_code'] = 'GBP'; // Build the query string from the data. $queryString = http_build_query($data); // Redirect to paypal IPN header('location:' . $paypalUrl . '?' . $queryString); exit(); } else { // Handle the PayPal response. // Create a connection to the database. $db = new mysqli($dbConfig['host'], $dbConfig['username'], $dbConfig['password'], $dbConfig['name']); // We need to verify the transaction comes from PayPal and check we've not // already processed the transaction before adding the payment to our // database. if (verifyTransaction($data) && checkTxnid($data['txn_id'])) { // Assign posted variables to local data array. $data = [ 'item_name' => $data['item_name'], 'item_number' => $data['item_number'], 'payment_status' => $data['payment_status'], 'payment_amount' => $data['mc_gross'], 'payment_currency' => $data['mc_currency'], 'txn_id' => $data['txn_id'], 'receiver_email' => $data['receiver_email'], 'payer_email' => $data['payer_email'], ]; if (addPayment($data) !== false) { // Payment successfully added. } } } ?> 替换了一些地方的敏感信息,但你明白了。 PayPal 日志中没有任何内容。我的捐赠数据库中没有添加任何内容。付款在交易列表中显示为已完成。


在 Spring WebFlux 中选择性读取 multipart/form-data 请求中的 body 内容

我有内容类型的请求:例如,多部分/表单数据 发布 http://myUrl/test 标头 内容类型:多部分/表单数据;边界=xxxx --xxxx Content-Disposition:表单数据;名字=“...


使用 CSS3 attr 函数在子级中使用父级的属性值

我想在其(嵌套)子元素之一上设置父元素的数据索引值。期望的结果:字符串“index”应该出现在 h2.heading 周围。 标记: 我想在其(嵌套)子元素之一上设置父元素的 data-index 值。期望的结果:字符串“index”应该出现在 h2.heading 周围。 标记: <div class="foo" data-index="index"> <div> <h2 class="heading"><span>title</span></h2> </div> </div> CSS(第一个 data-index 规则有效 - 但不在正确的位置): div.foo[data-index] .heading span { display: none; } div.foo[data-index]::after { content: attr(data-index); color: green; } div.foo[data-index] .heading::after { content: attr(data-index); color: red; border: 1px solid red; } http://codepen.io/anon/pen/jyxdoz 更新 解决方法可能是直接在 html 元素上设置 CSS 变量并使用它。 div.foo[data-index] .heading span { display: none; } div.foo[data-index] .heading::after { content: var(--index); color: red; border: 1px solid red; } <div class="foo" style="--index:'test';" data-index> <div> <h2 class="heading"><span>title</span></h2> </div> </div> 原创 当前无法完成(如上所述,attr仅适用于当前元素)。 将来当attr()可以用于content以外的属性时,结合css变量就可以这样了 div.foo[data-index] .heading span { display: none; } div.foo[data-index] { --data: attr(data-index); --index: var(--data); } div.foo[data-index] .heading::after { content: var(--index); color: red; border: 1px solid red; } <div class="foo" data-index="index"> <div> <h2 class="heading"><span>title</span></h2> </div> </div> 还有一种选择: 如果该值是可继承的,并且没有直接在子级上设置。然后,您还可以使用 attr() 将其分配给父级,并让继承完成其任务。 你可以使用这个CSS。 div.foo[data-index]::after, div.foo[data-index]::before { content: attr(data-index); color: green; } div.foo[data-index] .heading::after { content: attr(data-index); border: 1px solid red; } 注意:before伪元素的使用。 我想这就是您正在寻找的。


测试中 Antd Select 的 onFocus 事件

我有来自 AntD 的 Select 组件,它在激活时获取其选项。 我有来自 AntD 的 Select 组件,它在激活时获取其选项。 <Select data-testid="test-select" defaultValue="org1" style={{ width: 120 }} onSelect={some-action} onFocus={fetch_some_data} > {orgs.map((org) => { return ( <Option key={org} value={org}> {org} </Option> ); })} </Select> 我在测试此组件时遇到问题,因为 onFocus 事件未在测试中运行。我尝试了 click 事件和 mouseDown 事件,两者都不起作用。 测试是这样的 test("onFocus 事件获取选项", async () => { 常量 { getByTestId, getByText } = render(); const select = getByTestId("test-select"); fireEvent.click(select); await waitFor(() => expect(getByText).toBeInTheDocument()); }) 这里是这个例子的codesandbox


In testing 2 input or gate (cocotb) with for asynchronous data transfer using ready and enable signals, input value is always 'z' and output is 'x'?

我正在测试一个 DUT,它是一个双输入或门,使用 ready 和 enable 信号在 coco tb 和 verilog 中进行异步数据传输。当我运行这个测试时,我面临以下问题: ...


在SPSS上用于目标的最简单、最合适的统计分析是什么;

在 SPSS 上最简单、最合适的统计分析有哪些? 调查 COVID-19 对年龄、性别和社会性别的影响,其中性别是名义性的,年龄和性别是规模的......


空手道中无法获取背景颜色

我有这个代码: 我有这个代码: <div class="react-data-field separated-area case-overview-field-root important"> <div class="row"> <div class="col-xs-6"> <div class="data-label">Test is important</div> </div> <div class="col-xs-6"><div class="data-value"> <div class="easy-edit-wrapper">Click to edit</div> </div> </div> </div> 我使用此代码来匹配行的背景颜色: * match script("//div[text()='Test - is important']", "function(e){ return getComputedStyle(e)['background-color']}") == "#7d7d80" 问题在于该行的背景颜色仅位于具有“重要”类别的父级 div 中。 我该如何检查家长? 也许可以尝试getComputedStyle(e.parentElement)? 只要是JS可以的-空手道都可以执行。我不确定“重要”部分。你可以尝试在浏览器开发者工具中的控制台运行JS并实验。


Google数据流API调用失败-

我正在尝试使用数据流运算符从 composer airflow 调用数据流作业,但在调用它时出现以下错误: googleapiclient.errors.HttpError: 我正在尝试使用数据流运算符从 composer airflow 调用数据流作业,但在调用它时出现以下错误: googleapiclient.errors.HttpError: <HttpError 400 when requesting https://test returned "Invalid value at 'launch_parameters.parameters' (type.googleapis.com/google.dataflow.v1beta3.LaunchTemplateParameters.ParametersEntry), "{'test1': 'SELECT distinct data\nFROM project.dataset.table1\nWHERE ace_date="2022-05-12"', 'test2': 'SELECT distinct data\nFROM project.dataset.table2\nWHERE ace_date="2022-05-12"', 'priority_data': 'SELECT distinct data\nFROM project.dataset.table3\nWHERE ace_date="2022-05-12"', 'test3': 'SELECT distinct data\nFROM project.dataset.table4\nWHERE ace_date="2022-05-12"', 'test4': 'SELECT distinct data\nFROM project.dataset.table5\nWHERE ace_date="2022-05-12"', 'test5': 'SELECT distinct data\nFROM project.dataset.tabl6 \nWHERE ace_date="2022-05-12"', 'pack_rules': 'SELECT distinct data\nFROM project.dataset.table7\nWHERE ace_date="2022-05-12"', 'test6': 'SELECT distinct row_key_data as data\nFROM peoject.dataset.table7\nWHERE date_of_run="2022-05-16"'}"" 下面是从 Airflow 调用它时的相同代码: def dataflow_trigger( task, ): """ Dynamic task for calling dataflow job """ return DataflowTemplatedJobStartOperator( task_id=task, project_id="{{task_instance.xcom_pull(key='dataflow_settings', task_ids='get_settings')['project']}}", job_name="{{task_instance.xcom_pull(key='dataflow_settings', task_ids='get_settings')['job_name']}}", template="{{task_instance.xcom_pull(key='dataflow_settings', task_ids='get_settings')['template_path']}}", parameters="{{task_instance.xcom_pull(key='parameters', task_ids='get_settings')}}", location='europe-west2', ) Airflow xcom pull 只返回字符串 这有助于解决问题,因为 xcom push 将其存储为字符串;在 DAG 构造函数中使用 render_template_as_native_obj=True 解决了这个问题。


PHP + 正则表达式来查找和替换源代码中特定类中的任何 <a> 标签

我在 PHP 变量中有一个 HTML 代码,我需要替换包含在另一个具有“混淆”类的标签中的每个链接,例如: ... 我在 PHP 变量中有一个 HTML 代码,我需要替换包含在另一个具有 "obfuscate" 类的标签中的每个链接,例如: <div class="obfuscate foobar"> <strong> <a href="https://example.com" class="randomclass" target="_BLANK">test</a> </strong> </div> 我需要将 <a> 标签替换为 <span> ,它继承了原始标签的所有内容,添加了 "akn-obf-link" 类,并在 base64_encode() 属性下通过 "data-o" 传递了混淆链接,以及一个"data-b" 属性具有值 "1" 如果链接有一个目标 _blank 或 "0" 否则。 在上面的例子中,<a>标签应该转换为: <span class="akn-obf-link randomclass" data-o="aHR0cHM6Ly9leGFtcGxlLmNvbQ==" data-b="1">test</span> 我已经有一个代码可以在 <a> 标签本身具有 "obfuscate" 类时执行此操作,如果这可能有帮助的话: $result = preg_replace_callback('#<a[^>]+((?<=\s)href=(\"|\')([^\"\']*)(\'|\")[^>]+(?<=\s)class=(\"|\')[^\'\"]*(?<!\w|-)obfuscate(?!\w|-)[^\'\"]*(\"|\')|(?<=\s)class=(\"|\')[^\'\"]*(?<!\w|-)obfuscate(?!\w|-)[^\'\"]*(\"|\')[^>]+(?<=\s)href=(\"|\')([^\"\']*)(\'|\"))[^>]*>(.*)<\/a>#miUs', function($matches) { preg_match('#<a[^>]+(?<=\s)class=[\"|\\\']([^\\\'\"]+)[\"|\\\']#imUs',$matches[0],$matches_classes); $classes = trim(preg_replace('/\s+/',' ',str_replace('obfuscate','',$matches_classes[1]))); return '<span class="akn-obf-link'.($classes?' '.$classes:'').'" data-o="'.base64_encode($matches[3]?:$matches[10]).'" data-b="'.((strpos(strtolower($matches[0]),'_blank')!==false)?'1':'0').'">'.$matches[12].'</span>'; }, $code); 我需要相同的但只要标签在另一个具有"obfuscate"类的标签中。


模拟redis模板

我在模拟 Redis 模板中遇到问题。 任何人都可以帮我为下面的课程编写单元测试吗? @存储库 公共类 CasheRepo { @Autowired 私有Redis模板 我在模拟 Redis 模板中遇到问题。 任何人都可以帮我为下面的课程编写单元测试吗? @Repository public class CasheRepo { @Autowired private RedisTemplate<String, Object> template; public Object getObject(final String key) { return template.opsForValue().get(key); } } 下面是单元测试类。但它不起作用。它显示空点异常 @RunWith(MockitoJUnitRunner.class) public class CashRepoTest { @InjectMocks private CasheRepo casheRepo = new CasheRepo(); private @Mock RedisConnection redisConnectionMock; private @Mock RedisConnectionFactory redisConnectionFactoryMock; private RedisTemplate redisTemplate; @Before public void setUp() { Mockito.when(redisConnectionFactoryMock.getConnection()).thenReturn(redisConnectionMock); redisTemplate = new RedisTemplate(); redisTemplate.setConnectionFactory(redisConnectionFactoryMock); redisTemplate.afterPropertiesSet(); } @Test public void getObjectTest() { Mockito.doNothing().when(redisTemplate).opsForValue().set("spring", "data"); redisTemplate.afterPropertiesSet(); System.out.println(redisTemplate.opsForValue().get("spring")); } } 你可以像这样模拟 redisTemplate : @Mock RedisTemplate<String, String> redisTemplate; @Mock private ValueOperations valueOperations; @Before public void setUp() { MockitoAnnotations.initMocks(this); Mockito.when(redisTemplate.opsForValue()).thenReturn(valueOperations); Mockito.doNothing().when(valueOperations).set(anyString(), anyString()); } 您正在通过构造函数创建redisTemplate,并且它不是通过DI获取的。尝试使用@Spy注释: @Spy private RedisTemplate redisTemplate = new RedisTemplate(); 它将允许 DI 注入您的 RedisTemplate 实例。 对于那些想要对 HashOperations get() 和 put() 做同样事情的人 @Mock RedisTemplate<String, String> redisTemplate; @Mock private HashOperations hashOperations; @Test void getFromCache() { Mockito.when(redisTemplate.opsForHash()).thenReturn(hashOperations); when(hashOperations.get("test-key", "test-hash-key")).thenReturn("value123"); RedisCacheServiceImpl cacheService = new RedisCacheServiceImpl(redisTemplate); assertEquals("value123", cacheService.getFromCache("test-key", "test-hash-key")); } 希望对您有帮助;) 当我面临类似的任务时,我制作了一个基于 mock-jedis 的工具(注释)来以简单的方式解决它。您可以在这里阅读:https://github.com/incu6us/redis-mock-template 或者只是向您的项目添加依赖项: <dependency> <groupId>com.github.incu6us.redis</groupId> <artifactId>redis-mock-template</artifactId> <version>0.0.1</version> </dependency> 我尝试了各种 jedis 模拟库,这是唯一一个使用池资源的库。其他库,服务器甚至没有启动,有些需要本地 redis 启动并运行。这对 junit 来说是最好的 https://github.com/50onRed/mock-jedis 即使我也面临着类似的问题。 我修复它的步骤 - 向我的测试类添加了 @ExtendWith(SpringExtension.class) 注释。 使用@MockBean注释RedisTemplate @MockBean private RedisTemplate<Integer, String> redisTemplate; 在我的测试方法中,我使用ReflectionTestUtils来设置redisTemplate字段。 ReflectionTestUtils.setField(rm, "redisTemplate", redisTemplate); 到达这里有点晚了。下面是我用 Junit5 的回答 @ExtendWith(MockitoExtension.class) class CashRepoTest { @InjectMocks CashRepo cashRepo; @Mock RedisTemplate<String, Object> template; @Mock ValueOperations<String, Object> valueOperations; @Test void getTest() { Mockito.when(template.opsForValue()) .thenReturn(valueOperations); String expectedValue = "ev"; when(valueOperations.get("test")).thenReturn(expectedValue); assertEquals(expectedValue, cashRepo.getObject("test")); } } 如果您使用 JUnit-5,这些是您需要注意的事情。 @BeforeEach void setUp() { MockitoAnnotations.openMocks(this); Mockito.when(redisTemplate.opsForHash()).thenReturn(hashOperations); } HashOperations 或 ValueOperations 基于您的要求。


显示 component.ts 的输出

我想打印component.ts生成的输出,但我不要console.log,而是component-html上的返回值。 这是我的 component.html(只是最后一部分): 我想打印 component.ts 生成的输出,但我不要 console.log,而是 component-html 上的返回值。 这是我的component.html(只有最后一部分): <div class="col-md-12 pt-2"> <button type="button" class="btn btn-success btn-sm" (click)="addField()">Add TTP</button> <button type="submit" class="btn btn-outline-primary" [disabled]="!ttp_form.valid">Submit</button> //the call of onSubmit() is done by the formGroup tag at the beginning </div> 这是组件.ts: onSubmit() { //return the data this.firebase.getData(this.url) .subscribe((data: any) =>{ this.ttp_db = Object.keys(data).map((key)=> {return data[key]}) this.ttp_field = Object.keys(this.ttp_form.value).map((key)=> {return this.ttp_form.value[key]}) this.appartenenza(this.ttp_field, this.ttp_db) --> this is the function that I want to return the value }) } 功能附件的一小部分: appartenenza(ttp_field: any, ttp_db: any) { const massimo = Math.max(...punteggi); if (massimo === 0) { return "Nessuna stringa in comune"; } const indice = punteggi.indexOf(massimo); return console.log("Gruppo con più affinità: ", this.ttp_db[0][indice]); --> I put console log to see the output on the console for test the programm } 您需要将返回值存储在一个属性中,然后在您的模板中使用数据绑定来显示它。确保你总是返回一个字符串,不要返回 console.log 函数。 myValue = ''; onSubmit() { //return the data this.firebase.getData(this.url) .subscribe((data: any) =>{ this.ttp_db = Object.keys(data).map((key)=> {return data[key]}) this.ttp_field = Object.keys(this.ttp_form.value).map((key)=> {return this.ttp_form.value[key]}) this.myValue = this.appartenenza(this.ttp_field, this.ttp_db); }) } appartenenza(ttp_field: any, ttp_db: any) { const massimo = Math.max(...punteggi); if (massimo === 0) { return "Nessuna stringa in comune"; } const indice = punteggi.indexOf(massimo); return "Gruppo con più affinità: " + this.ttp_db[0][indice]; } 在你的模板中 <p>My Value: {{ myValue }}</p> 只需存储函数 this.appartenza() 的返回值 const data = this.appartenenza(this.ttp_field, this.ttp_db)


为什么这个regex可以拆分第二个双引号而不是第一个双引号?

我有这样的regex: let regex = (?=/...; test = "\"test.test/"" test.split(regex) 输出: [""test", ".test", """] 而我想要[""", "test", ".test", """] 我不明白为什么...


如何通过从 CDN 包含它来将 PhotoSwipe 用于旧版本的 JavaScript?

PhotoSwipe 仅显示 ESM 模块的代码。 从 'photoswipe/dist/photoswipe-lightbox.esm.js' 导入 PhotoSwipeLightbox; 常量灯箱 = 新的 PhotoSwipeLi ...</desc> <question vote="2"> <p><a href="https://photoswipe.com/getting-started" rel="nofollow noreferrer">PhotoSwipe</a> 仅显示 ESM 模块的代码。</p> <pre><code>&lt;script type=&#34;module&#34;&gt; import PhotoSwipeLightbox from &#39;photoswipe/dist/photoswipe-lightbox.esm.js&#39;; const lightbox = new PhotoSwipeLightbox({ gallery: &#39;#my-gallery&#39;, children: &#39;a&#39;, pswpModule: () =&gt; import(&#39;photoswipe/dist/photoswipe.esm.js&#39;) }); lightbox.init(); &lt;/script&gt; </code></pre> <p>这不适用于我当前的设置。我在 Visual Studio 中从事一个项目,该项目使用 jQuery 和通过 <pre><code>&lt;script&gt;</code></pre> 标签和 CDN 在 HTML 中包含 JS 文件的旧方法。</p> <p>如果我使用 <pre><code>&lt;script src=&#39;/path-to/photoswipe.esm.js&#39;&gt;</code></pre> 它显然不会工作,因为这个文件中包含一个 <pre><code>export</code></pre> 关键字并且它在控制台中显示错误:</p> <blockquote> <p>未捕获的语法错误:意外的令牌“导出”</p> </blockquote> <p>那么,有没有办法让我使用这个库,但使用老式代码?</p> </question> <answer tick="false" vote="1"> <p>v5 版本提供 umd 构建,您可以使用该构建以旧方式运行</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Test Gallery&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;script src=&#34;./photoswipe.umd.min.js&#34;&gt;&lt;/script&gt; &lt;script src=&#34;./photoswipe-lightbox.umd.min.js&#34;&gt;&lt;/script&gt; &lt;link rel=&#34;stylesheet&#34; href=&#34;../photoswipe.css&#34;&gt; &lt;div class=&#34;test-gallery&#34;&gt; &lt;a href=&#34;https://dummyimage.com/1200x600/000/fff&#34; data-pswp-width=&#34;1200&#34; data-pswp-height=&#34;600&#34;&gt; &lt;img src=&#34;https://dummyimage.com/120x60/000/fff&#34; alt=&#34;&#34; /&gt; &lt;/a&gt; &lt;a href=&#34;https://dummyimage.com/1200x1200/000/fff&#34; data-pswp-width=&#34;1200&#34; data-pswp-height=&#34;1200&#34;&gt; &lt;img src=&#34;https://dummyimage.com/60x60/000/fff&#34; alt=&#34;&#34; /&gt; &lt;/a&gt; &lt;a href=&#34;https://dummyimage.com/600x1200/000/fff&#34; data-pswp-width=&#34;600&#34; data-pswp-height=&#34;1200&#34;&gt; &lt;img src=&#34;https://dummyimage.com/30x60/000/fff&#34; alt=&#34;&#34; /&gt; &lt;/a&gt; &lt;/div&gt; &lt;script type=&#34;text/javascript&#34;&gt; var lightbox = new PhotoSwipeLightbox({ gallery: &#39;.test-gallery&#39;, children: &#39;a&#39;, // dynamic import is not supported in UMD version pswpModule: PhotoSwipe }); lightbox.init(); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> </answer> <answer tick="false" vote="0"> <p>你只需要如下替换js文件的链接。不要忘记在脚本标签上添加<pre><code>type=&#39;module&#39;</code></pre>。</p> <p></p><div data-babel="false" data-lang="js" data-hide="false" data-console="true"> <div> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta name=&#34;viewport&#34; content=&#34;width=device-width&#34;/&gt; &lt;link rel=&#34;stylesheet&#34; href=&#34;https://cdn.jsdelivr.net/npm/[email protected]/dist/photoswipe.css&#34;&gt; &lt;/head&gt; &lt;body&gt; &lt;div id=&#34;app&#34;&gt; &lt;div class=&#34;pswp-gallery&#34; id=&#34;my-gallery&#34;&gt; &lt;a href=&#34;https://cdn.photoswipe.com/photoswipe-demo-images/photos/1/img-2500.jpg&#34; data-pswp-width=&#34;1875&#34; data-pswp-height=&#34;2500&#34; target=&#34;_blank&#34; &gt; &lt;img src=&#34;https://cdn.photoswipe.com/photoswipe-demo-images/photos/1/img-200.jpg&#34; alt=&#34;&#34; /&gt; &lt;/a&gt; &lt;a href=&#34;https://cdn.photoswipe.com/photoswipe-demo-images/photos/2/img-2500.jpg&#34; data-pswp-width=&#34;1669&#34; data-pswp-height=&#34;2500&#34; target=&#34;_blank&#34; &gt; &lt;img src=&#34;https://cdn.photoswipe.com/photoswipe-demo-images/photos/2/img-200.jpg&#34; alt=&#34;&#34; /&gt; &lt;/a&gt; &lt;a href=&#34;https://cdn.photoswipe.com/photoswipe-demo-images/photos/3/img-2500.jpg&#34; data-pswp-width=&#34;2500&#34; data-pswp-height=&#34;1666&#34; target=&#34;_blank&#34; &gt; &lt;img src=&#34;https://cdn.photoswipe.com/photoswipe-demo-images/photos/3/img-200.jpg&#34; alt=&#34;&#34; /&gt; &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;script type=&#39;module&#39;&gt; import PhotoSwipeLightbox from &#39;https://cdn.jsdelivr.net/npm/[email protected]/dist/photoswipe-lightbox.esm.js&#39;; const lightbox = new PhotoSwipeLightbox({ gallery: &#39;#my-gallery&#39;, children: &#39;a&#39;, pswpModule: () =&gt; import(&#39;https://cdn.jsdelivr.net/npm/[email protected]/dist/photoswipe.esm.js&#39;) }); lightbox.init(); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt;</code></pre> </div> </div> <p></p> </answer> </body></html>


如何在 PHP 和 curl 中输出嵌套对象的 api 响应?

我正在尝试使用 curl 和 PHP 发布到端点 URL,但没有收到仅收到错误 404 和 null 的响应。只需遵循网络上的一些 API 文档 这是我的PHP代码 我正在尝试使用 curl 和 PHP 发布到端点 URL,但没有收到仅收到错误 404 和 null 的响应。只需遵循网络上的一些 API 文档 这是我的 php 代码 <?php $jsonString = [ "identifier" => "ghgfhgf", "currency" => "USD", "amount" => "50", "details" => "pen", "ipn_url" => "https://script.viserlab.com/paymenthub/ipn_url.php", "success_url" => "https://script.viserlab.com/paymenthub/test-api/success.php", "cancel_url" => "https://script.viserlab.com/paymenthub/test-api/failed.php", "site_name" => "fwew332", "public_key" => "pro_zlzdbehyqspvehw427tw2ia7nxpu9z4vj9g36x6y1kj64mgg0t1", "customer" => [ "first_name" => "John", "last_name" => "Doe", "email" => "[email protected]", "mobile" => "555-555-5555" ] ]; $jsonString = http_build_query($jsonString); $jsonData = json_decode($jsonString); // Encode the JSON data as a string $endpoint = "https://script.viserlab.com/paymenthub/payment/initiate"; $curl = curl_init($endpoint); // Initialize cURL session curl_setopt($curl, CURLOPT_URL, $endpoint); // Set the URL for the request curl_setopt($curl, CURLOPT_POST, true); // Set the request type to POST curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonData); // Set the JSON data as the request body curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Return the response as a string // For debug purposes only! Disable SSL verification (remove in production) curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); // Execute the cURL request curl_close($curl); // Close the cURL session echo $response; // Display the response ?> API 的响应应该是这样的 //Error Response. { "status": "error", "message": [ "Not Paid" ] } //Success Response. { "status": "success", "message": [ "Paid" ], "redirect_url": "https://example.com/payment/checkout" } 但是我的 PHP 端代码没有输出响应


导入org.springframework.data.jpa.repository.JpaRepository无法解析

我正在使用 Spring 工具套件版本 4。我创建了一个新的 spring boot 项目。 Pom.xml 如下: 我正在使用 Spring 工具套件版本 4。我创建了一个新的 spring boot 项目。 Pom.xml 如下: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>StudentCRUD</artifactId> <version>0.0.1-SNAPSHOT</version> <name>StudentCRUD</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 我创建了一个实体类。这没有问题。但是当我尝试创建一个扩展接口 JpaRepository 的接口时,以下导入未得到解决: 导入org.springframework.data.jpa.repository.JpaRepository; 我已经做了几次 Maven 更新,并且也清理了项目,但没有任何变化。如果有人能指导我哪里做错了,那将会非常有帮助吗? 也许您的 IDE 有问题?我用你的 pom.xml 导入 JpaRepository 没有问题。 import org.springframework.data.jpa.repository.JpaRepository; public interface Repo extends JpaRepository<Long, Object> { }


创建类路径资源中定义的名为“cassandraSession”的 bean 时出错:调用 init 方法失败

我正在编写一个 Springboot 项目来实现使用 cassandra db 的 ISO20022。 我的 POM.xml: 我正在写一个Springboot项目来实现ISO20022它使用cassandra db. 我的POM.xml: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>untitled</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>Simple Wallet</name> <description>Powered with ISO20022</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.1.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-cassandra-reactive</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.restdocs</groupId> <artifactId>spring-restdocs-mockmvc</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-transport-native-epoll</artifactId> </dependency> <!-- API, java.xml.bind module --> <dependency> <groupId>jakarta.xml.bind</groupId> <artifactId>jakarta.xml.bind-api</artifactId> <version>2.3.2</version> </dependency> <!-- Runtime, com.sun.xml.bind module --> <dependency> <groupId>org.glassfish.jaxb</groupId> <artifactId>jaxb-runtime</artifactId> <version>4.0.2</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-autoconfigure</artifactId> <version>2.0.1.RELEASE</version> </dependency> </dependencies> </project> 我的Cassandra配置: @Configuration @EnableReactiveCassandraRepositories(basePackages = "org.example.repository") public class CassandraConfig extends AbstractReactiveCassandraConfiguration { @Override protected String getKeyspaceName() { return "isodb"; } @Bean public CassandraClusterFactoryBean cluster() { CassandraClusterFactoryBean cluster = super.cluster(); cluster.setContactPoints("127.0.0.1"); cluster.setPort(9142); return cluster; } @Bean public CassandraMappingContext cassandraMapping() { return new CassandraMappingContext(); } @Override protected boolean getMetricsEnabled() { return false; } } 当我运行项目时,我得到这个错误: org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.class] 中创建名为“cassandraSession”的 bean 时出错:调用 init 方法失败;嵌套异常是 com.datastax.driver.core.exceptions.NoHostAvailableException: 所有主机尝试查询失败(尝试:localhost/0:0:0:0:0:0:0:1:9042(com.datastax .driver.core.exceptions.TransportException: [localhost/0:0:0:0:0:0:0:1:9042] 无法连接), localhost/127.0.0.1:9042 (com.datastax.driver.core. exceptions.TransportException: [localhost/127.0.0.1:9042] 无法连接)) 我该如何解决这个问题?我错过了什么? 所以看到这个: Cannot connect), localhost/127.0.0.1:9042 还有这个: cluster.setContactPoints("127.0.0.1"); cluster.setPort(9142); 不确定 Cassandra 期望连接到哪个端口,但 9142 仅用于版本 >= 4.0 中的 SSL。否则,它是 9042。另外,我不会在代码中指定端口或接触点,而是在 src/main/resources/application.[yaml|properties] 文件中指定。这些设置可能有冲突。 <java.version>1.8</java.version> 此外,Cassandra JVM 的 Java 版本不必与服务层代码中使用的 JVM 版本相匹配。我会 highly 建议至少使用 Java 17.


如果 URL 中没有参数,Ajax POST 将无法工作

谷歌显然不是我的朋友,因为我已经尝试了许多发现的建议,但没有一个对我有用。 我有两个简单的输入,如下所示: 谷歌显然不是我的朋友,因为我已经尝试了许多发现的建议,但没有一个对我有用。 我有 2 个简单的输入,如下: <form id="form"> <fieldset id="frmTest"> <div class="form-outline"> @Html.TextBoxFor(m => m.TextBox1, new { @id = "TextBox1", @class = "form-control" }) @Html.LabelFor(m => m.TextBox1, new { @class = "form-label" }) </div> <div class="form-outline mb-4"> @Html.TextBoxFor(m => m.TextBox2, new { @id = "TextBox2", @class = "form-control" }) @Html.LabelFor(m => m.TextBox2, new { @class = "form-label" }) </div> </fieldset> </form> 还有 JS: $("#SaveTest").click(function (e) { e.preventDefault(); var data = { TextBox1: $('#TextBox1').val(), TextBox2: $('#TextBox2').val(), }; $.ajax({ type: "POST", url: "http://localhost/api/api/ConfigurationManagement/TestAjax", data: JSON.stringify(data), dataType: "json", contentType: "application/json; charset=utf-8", success: function (result) { alert(result.message); }, error: function (response) { alert(response); } }); 控制器: [HttpPost] public async Task<ActionResult> SaveTest(string TextBox1, string TextBox2) { Test model = new Test(); model.TextBox1 = TextBox1; model.TextBox2 = TextBox2; _applicationDbContext.Test.Add(model); try { await _applicationDbContext.SaveChangesAsync(); return Ok(new UserManagerResponse { Status = "Success", Message = "Successfully added test" }); } catch (Exception ex) { return BadRequest(new UserManagerResponse { Status = "Failed", Message = ex.ToString() }); } } 当我单击“SaveTest”按钮时,我看到响应为“错误请求”,指示以下内容,就好像未传递参数一样: {"errors":{"TextBox1":["The TextBox1 field is required.", "TextBox2":["The TextBox2 field is required."]} 关于奇怪的部分,如果我更改“url”并在末尾添加参数,它就可以工作。 url: "http://localhost/api/api/ConfigurationManagement/TestAjax?textBox1=" + $('#TextBox1').val() + "&TextBox2=" + $('#TextBox2').val(), 虽然这个问题可能看起来是重复的,但我们每个场景都是不同的。我想在不使用 URL 中的参数的情况下执行此操作,我只是不明白为什么在没有 URL 中的参数的情况下它对我不起作用。 谢谢 操作参数默认绑定到查询参数。为了绑定帖子正文中的参数,您需要接受 class 参数,并将 TextBox1 和 TextBox2 作为属性。 public class TxtModel { public string TextBox1 { get; set; } public string TextBox2 { get; set; } } [HttpPost] public async Task<ActionResult> SaveTest(TxtModel model)


告诉 FlinkSQL 按顺序读取 Parquet 文件的目录

是否可以让FlinkSQL按照特定顺序读取目录中的Parquet文件?即我在文件夹 test/ 中有文件 test-a.parquet、test-b.parquet、test-c.parquet。当我指向弗林...


如何强制div的内容在一行?

我有一个使用 Tailwind CSS 设计的 Vite/Vue 应用程序。我不明白为什么几个自动生成的的内容被包裹而不是在一行上。 我尝试重现... 我有一个使用 Tailwind CSS 设计的 Vite/Vue 应用程序。我不明白为什么几个自动生成的<div>的内容被包裹而不是在一行。 我尝试从头开始重现这一点,但无论我尝试什么,其行为都符合预期。 我最终复制了生成的HTML,问题重现。代码如下,也可在Tailwind Play获取。 <div class="flex flex-row items-start gap-5"> <!--v-if--> <div data-v-c5bff582="" class=""> <!-- important events within 8 days --> <div data-v-c5bff582="" class="flex flex-auto flex-row gap-3"> <div data-v-c5bff582="" class="w-32 rounded-3xl bg-green-200 px-5 py-1 text-center text-2xl text-gray-400">test later 1</div> <div data-v-c5bff582="" class="w-32 rounded-3xl bg-green-200 px-5 py-1 text-center text-2xl text-gray-400">test 2 later</div> </div> </div> <button class="self-end rounded-md bg-slate-500 px-5 py-2 text-4xl text-white">dump store</button> </div> 我的问题是“稍后测试1”和“稍后测试2”。为什么它们不是在一根线上而是包裹在 <div> 中? 我尝试了各种类的组合(坦率地说,当我阅读 Tailwind CSS 文档时,我尝试了一些我能想到的任何组合),但没有成功(不过我学到了很多 Tailwind CSS) w-32类在元素上设置固定宽度(在本例中为8 rems);内容需要更多空间,因此换行到下一行。 如果希望按钮是统一的固定尺寸,请选择较大的固定宽度;否则你可以删除 w-* 类并让元素找到它们的自然大小。


Spring Data JPA:从 JPA 查询映射到实体(无投影)?

我正在尝试使用以下存储库方法填充事务模型(实际上它是一个实体类): 公共接口 TransactionRepository 扩展了 JpaRepository 我正在尝试使用以下存储库方法填充Transaction模型(实际上它是一个实体类): public interface TransactionRepository extends JpaRepository<Transaction, Long> { @Query(value = "SELECT t.id, t.description, t.date " + "FROM Account a " + "LEFT JOIN Transaction t ON a.id = t.account.id " + "WHERE a.customer.id = :customerId " + "ORDER BY t.date DESC") List<Transaction> findAllByCustomerId(@Param("customerId") Long customerId); } 但是,当我从服务中调用此方法时: List<Transaction> transactions = transactionRepository.findAllByCustomerId(id); 我得到这个错误: 2023-02-21 16:20:52,391 错误 GlobalExceptionHandler:无法从类型 [java.lang.Object[]] 转换为类型 [@org.springframework.data.jpa.repository.Query com.demo.model。 Transaction] for value '{3, description test, 2023-02-20T14:53:31.468950}' 这里是Transaction实体: @Entity public class Transaction { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String description; private LocalDateTime date; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "account_id", referencedColumnName = "id") private Account account; } 那么,问题的原因是什么?据我所知,我之前可以在 Spring Data JPA 中使用本机查询来映射实体类。另一方面,查询正在运行(我在数据库端检查过)并且我不想使用投影。


错误:活动类 {com.testApp/com.testApp.MainActivity} 不存在

已更新** 我正在尝试修复我的 react-native 应用程序中突然停止工作(可能是由于更新)的动态链接问题。 当我添加 已更新** 我正在尝试修复我的 react-native 应用程序中突然停止工作(可能是由于更新)的动态链接问题。 当我添加 <action android:name="android.intent.action.VIEW"/> <intent-filter> 应用程序时,我得到一个 Error: Activity class {com.testApp/com.testApp.MainActivity} does not exist. 但没有它,链接无法打开应用程序。 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.testApp"> <uses-permission android:name="android.permission.INTERNET"/> <application android:networkSecurityConfig="@xml/network_security_config" android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:allowBackup="false" android:theme="@style/AppTheme" package="com.testApp" > <activity android:usesCleartextTraffic="true" android:name=".MainActivity" android:label="@string/app_name" android:launchMode="singleTask" > <intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.BROWSABLE"/> <data android:scheme="com.testApp"/> <data android:scheme="testApp"/> </intent-filter> </activity> </application> </manifest> *我正在尝试像这样打开此链接: npx uri-scheme open https://my-firebase-test-link.com/profile --android 它在 iOS 上运行良好但在 android 上不再运行,当我们更新到 react native 0.71.4 时可能会破坏它。我没有看到清单有任何其他变化 我们正在使用@react-native-firebase/dynamic-links ** 当我评论它时,它有效但没有动态链接 如果我添加<data android:scheme="testApp"/>或<data android:host="my-firebase-test-link.com" android:scheme="https"/> 我又遇到问题了 您遇到的问题似乎与活动标签的android:name 属性有关。报错提示找不到MainActivity类,提示android:name attribute is incorrect or that the class itself is missing. 尝试检查以下内容: 确保 MainActivity 类存在于您的项目中并且位于正确的包中。它应该位于 com.testApp 包中,因为这是您的清单文件中指定的包名称。 检查清单文件中活动标签的 android:name 属性是否与 MainActivity 类的完全限定类名匹配,包括包名。在这种情况下,它应该是android:name=".MainActivity". 验证您的 MainActivity 类是否扩展了适当的 Activity 类。在这种情况下,它应该扩展 ReactActivity 或 ReactFragmentActivity,具体取决于您使用的 React Native 版本。 如果一切看起来都正确,请尝试清理并重建您的项目以确保所有更改都已正确应用。您还可以尝试重新启动开发服务器并重置应用程序的缓存和数据,以确保没有导致问题的冲突依赖项。 如果您仍然遇到问题,您可能需要考虑使用不同的方法来处理应用程序中的动态链接,例如第三方库或服务。 希望这有帮助!!! 好吧,解决办法就是这样拆分 <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.BROWSABLE"/> <data android:host="my-firebase-test-link.com" android:scheme="https"/> </intent-filter>


如何在没有@PoweMockito -UNit Test 的情况下使用ClassPathResource

ClassPathResource classPathResource = mock(ClassPathResource.class); whenNew(ClassPathResource.class).withArguments("studentInfo.json").thenReturn(classPathResource); 我该怎么写


为什么以下 R 代码会因为第一个 if 条件后缺少大括号而失败?

以下 R 代码会导致“错误:未找到对象‘test’”。 条件 <- 1 if(condition == 0) if(condition == 1) { test <- "Pass" } print(test) But if I add a


Flutter 集成测试:如何在 Firebase 测试实验室上的同一个 apk 中运行多个测试类(例如“class1_test.dart”、“class2_test.dart”...)?

我在文件夹“integration-test”下有多个测试类(例如“class1_test.dart”,“class2_test.dart”...); 我找到了生成 app-apk 和 test-apk 并运行的脚本...


如何使用 Jest 和 React 测试库测试组件导入 CSS 文件

我有横幅组件,我想测试它是否应该使用 CSS 呈现。下面是我的代码: // 横幅.tsx 导入“./Banner.css”; 导出默认函数 Banner() { 返回 我有横幅组件,我想测试它是否应该使用 CSS 呈现。下面是我的代码: // Banner.tsx import "./Banner.css"; export default function Banner() { return <div data-testid="banner" className="banner" />; } // Banner.css .banner { margin-top: var(--banner-mt); height: 30vh; background-image: linear-gradient( to right, rgba(54, 214, 62, 0.794), rgba(53, 201, 157, 0.794), rgba(32, 155, 212, 0.794) ), url("../../assets/images/mountain.jpg"); background-position: center; color: "red"; } 我想测试 Banner Component 是否使用 backgroundImage 进行渲染。我试过console.log(bannerElement.styles)但我没有看到属性背景图像。 import { render } from "@testing-library/react"; import Banner from "../Banner"; describe("Checking Banner Component", () => { test("Banner Element should contain background image", () => { const { getByTestId } = render(<Banner />); const bannerElement = getByTestId("banner"); const styles = window.getComputedStyle(bannerElement); expect(bannerElement).toHaveStyle("background-image: ../../assets/images/mountain.jpg"); }); });


使用热线时如何突出显示活动导航链接

我想突出显示当前页面的菜单链接。这样做的最佳方法是什么? 例如 我想突出显示当前页面的菜单链接。这样做的最佳方法是什么? 例如 <!-- navigation --> <nav class="nav font-semibold text-md"> <ul class="flex items-center"> <li class="p-4 border-b-2 border-blue-600 border-opacity-0 hover:border-opacity-100 hover:text-blue-600 duration-200 cursor-pointer <%= current? "border-opacity-100", posts_path %>"> <%= link_to 'Posts', posts_path, data: { turbo_frame: :main, turbo_action: 'replace' } %> </li> <li class="p-4 border-b-2 border-blue-600 border-opacity-0 hover:border-opacity-100 hover:text-blue-600 duration-200 cursor-pointer <%= current? "border-opacity-100", users_path %>"> <%= link_to 'Users', users_path, data: { turbo_frame: :main, turbo_action: 'replace' } %> </li> </ul> </nav> # helper def current?(key, path) "#{key}" if current_page? path end 不能正常工作,因为页眉保持原样。当然,如果我删除 data: { turbo_frame: :main, turbo_action: 'replace' } 它会正常工作。那么如何使它起作用呢?如果有人可以提出完全不同的更好方法,欢迎您 我不认为你真的可以在这里过多地利用 Rails,因为导航链接不会被 Rails 重新渲染。那是除非你想把导航包裹在它自己的涡轮框架之类的东西里,但这很快就会变得非常复杂...... 你可以做的是使用 Rails 来确定页面加载时的初始活动链接,然后在单击其他链接时使用 JavaScript 更新,或者使用 JavaScript 来完成整个事情。由于链接不会重新呈现,因此您无需担心链接的 url;最后点击的内容应该是活动选项卡。但是,如果您遇到不正确的情况,您可以根据 turbo 框架的 src 属性确定活动链接。 一个简单的 Stimulus 控制器看起来像这样: // javascript/controllers/navbar_controller.js navigate(e) { const activeButton = this.element.querySelector('.active') if (activeButton) { activeButton.classList.remove('active') } e.target.classList.add('active') } 和 HTML(这里稍微简化以关注重要部分): <nav data-controller="navbar"> <%= link_to "Posts", posts_path, class: ["class1 class2 etc", { active: current_page?(posts_path) }], data: { turbo_frame: :main, action: "navbar#navigate" } %> <%= link_to "Users", users_path, class: ["class1 class2 etc", { active: current_page?(users_path) }], data: { turbo_frame: :main, action: "navbar#navigate" } %> </nav> 使用 gem active_link_to 例如: <%= active_link_to "TEST", link, wrap_tag: :div, wrap_class: 'class', class_active: 'active class' %> [https://github.com/comfy/active_link_to] 这是我基于@rhelminen 回答的结果 <!-- navigation --> <div data-controller="navs" class="flex font-semibold text-md"> <%= link_to "Posts", posts_path, class: ["p-3 border-b-2 border-blue-600 border-opacity-0 hover:border-opacity-100 hover:text-blue-600 duration-200 cursor-pointer", { "border-opacity-100": current_page?(posts_path) } ], data: { turbo_frame: :main, navs_target: "nav", action: "click->navs#toggle" } %> <%= link_to "Users", users_path, class: ["p-3 border-b-2 border-blue-600 border-opacity-0 hover:border-opacity-100 hover:text-blue-600 duration-200 cursor-pointer", { "border-opacity-100": current_page?(users_path) } ], data: { turbo_frame: :main, navs_target: "nav", action: "click->navs#toggle" } %> </div> // navs_controller.js import { Controller } from "@hotwired/stimulus" export default class extends Controller { static targets = ["nav"]; toggle(event) { this.navTargets.forEach(nav => { if (nav === event.target) { nav.classList.add("border-opacity-100"); } else { nav.classList.remove("border-opacity-100"); } }); } } 完美工作


Gitlab CI 变量,带引号的选项

我有以下 gitab-ci.yml 文件: 阶段: - 测试 .test:&test_job 图像: 名称:test.com/test:latest 入口点: [””] 脚本: - py.test /test -v $EXTRA_OPTION...


Bash - 无输出

文件名 01.sh #!/bin/庆典 test=$(top -b -i -E=g -n 1 > top.txt | grep "%Cpu" | cut -b 9-13) 回声“${test}” 命令“top -b -i -E=g -n 1 > top.txt | grep &qu...


在您的夹具数据中发现外键违规。确保您没有引用关联中不存在的标签

我运行了一个测试 耙子测试 TEST=test/system/my_test.rb 并看到这个: 耙子测试 TEST=test/system/my_test.rb 在单个进程中运行 1 个测试(并行化阈值为 50) 运行选项...


如何使用 Laravel 发送电子邮件?

我正在尝试发送电子邮件,但我不能再移动了,这就是我的观点: 联系 TODOParrot 我正在尝试发送电子邮件,但我不能再移动了,这就是我的观点: <h1>Contact TODOParrot</h1> <form action="contact" method="post"> <div class="form-group"> <label>Your First Name</label> <input type="text" name="Fname" placeholder="Your First Name" /> </div> <div class="form-group"> <label>Your Last Name</label> <input type="text" name="Lname" placeholder="Your Last Name" /> </div> <div class="form-group"> <label>Your Email</label> <input type="email" name="Email" placeholder="Your Email" /> </div> <div class="form-group"> <label>Your Phone Number</label> <input type="text" name="Phone" placeholder="Your Phone" /> </div> <div class="form-group"> <label>Your Order</label> <input type="text" name="Order" placeholder="Your Order" /> </div> <div class="form-group"> <button class="btn btn-default" name="Submit" type="Submit">Send Order</button> </div> </form> 那是我的控制器: <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests\ContactFormRequest; class aboutController extends Controller { // public function create() { return view('about.contact'); } public function store(ContactFormRequest $request) { \Mail::send('about.contact', array( 'Fname' => $request->get('Fname'), 'Lname' => $request->get('Lname'), 'Email' => $request->get('Email'), 'Phone' => $request->get('Phone'), 'Order' => $request->get('Order') ), function($message) { $message->from('[email protected]'); $message->to('[email protected]', 'elbiheiry')->subject('TODOParrot Feedback'); }); return \Redirect::route('contact') ->with('message', 'Thanks for contacting us!'); } } 那是我的路线: Route::get('contact', ['as' => 'contact', 'uses' => 'AboutController@create']); Route::post('contact', ['as' => 'contact', 'uses' => 'AboutController@store']); 这就是 .env 文件中的配置: MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=465 MAIL_USERNAME= MAIL_PASSWORD= MAIL_ENCRYPTION=ssl 当我按下发送时,我删除了问题中的名称和密码,它给我“禁止”作为消息。 有人能帮忙吗? 和OP聊天后,这里是答案 主要问题: 您的ContactFormRequest.php具有以下规则功能: public function rules() { return [ 'name' => 'required', 'email' => 'required|email', 'message' => 'required', ]; } 但是您的表单没有名称和消息,因此您需要删除不存在的元素或根据需要修改它们,出于测试目的,我只保留了电子邮件: public function rules() { return [ 'Email' => 'required|email', ]; } 保持名称约定是一种很好的做法,例如如果您使用带有大写字母E的电子邮件而不是在任何地方使用电子邮件。 因此表格从未提交发送。 我还建议你构建你的 store 功能,我已经做过并测试它有效,你可以修改它以满足你的要求: $data = [ 'no-reply' => '[email protected]', 'admin' => '[email protected]', 'Fname' => $request->get('Fname'), 'Lname' => $request->get('Lname'), 'Email' => $request->get('Email'), 'Phone' => $request->get('Phone'), 'Order' => $request->get('Order'), ]; \Mail::send('about.contact', ['data' => $data], function ($message) use ($data) { $message ->from($data['no-reply']) ->to($data['admin'])->subject('Some body wrote to you online') ->to($data['Email'])->subject('Your submitted information') ->to('[email protected]', 'elbiheiry')->subject('Feedback'); }); 它应该有效, 我只使用 Mandrill API 电子邮件服务对其进行了测试,但您可以尝试使用 SMTP 或 API,这取决于您。 如果您想进行电子邮件确认,您需要创建电子邮件确认视图,将您的数据转发给它,如下所示: \Mail::send('about.emailconfirmation', ['data' => $data], 您的视图可能如下所示: <tr> <td> <h1>Contact form</h1> <p>Dear {{ $data['Fname'] }},</p> <p>Thank you for contacting me.</p> <p>I will respond to your inquiry as quickly as possible.</p> <hr/> <p><b>Provided email</b></p> <p>Email: {{ $data['Email'] }},</p> </td> </tr> 这只是示例,但您可以进一步修改它。 根据我的理解,我认为你在你的authorize中缺少ContactFormRequest部分转到你的这个App/Http/Request/ContactFormRequest你会这个方法 public function authorize() { return false; } 所以只需将 return 设置为 true 即可。它将允许进一步的过程。 public function authorize() { return true; } 已编辑 把你的Contact POST Route改成这个 Route::post('contact/store',['as' => 'contact-store', 'uses' => 'AboutController@store']); 在你的表格动作中,改变这个。 <form action="contact/store" ........ MAIL_DRIVER=sendmail MAIL_HOST=smtp.gmail.com MAIL_PORT=587 MAIL_USERNAME= MAIL_PASSWORD= MAIL_ENCRYPTION=tls 我有一些类似的问题并从 smtp 更改了 MAIL_DRIVER = sendmail Laravel 应用程序 MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=465 MAIL_USERNAME=<<your email address>> MAIL_PASSWORD=<<app password>> MAIL_ENCRYPTION= ssl 在您的控制器设置中 面对 use Illuminate\Support\Facades\Mail; 发送邮件 $to_name = "RECEIVER_NAME"; $to_email = "[email protected]"; $data = array("name"=>"Cloudways (sender_name)", "body" => "A test mail"); Mail::send([], $data, function($message) use ($to_name, $to_email) { $message->to($to_email, $to_name) ->subject("Laravel Test Mail"); $message->from("[email protected]","Test Mail"); }); 注意:从邮件到邮件 确保 在 gmail 设置中启用SucureLess mail Here are three methods to send email in laravel 8. First one is through our email id. Second one is through Mailgun. Third one is through SendinBlue. # For smtp # MAIL_MAILER=smtp # MAIL_HOST=smtp.gmail.com # MAIL_PORT=587 # [email protected] # MAIL_PASSWORD=xxxxxxxxxxxxxxx # MAIL_ENCRYPTION=tls # [email protected] # MAIL_FROM_NAME="${APP_NAME}" # For Mailgun # MAIL_MAILER=mailgun # MAIL_HOST=smtp.mailgun.org # MAIL_PORT=587 # MAIL_USERNAME=sandboxxxxxxxxxxxxxxxxxxxxxxxxx.mailgun.org # MAIL_PASSWORD=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # MAIL_ENCRYPTION=tls # MAIL_FROM_ADDRESS=xxxxxxxxxxxxxxxxxxxxxxxxx # MAIL_FROM_NAME="${APP_NAME}" # MAILGUN_SECRET=API private key # MAILGUN_DOMAIN=sandboxxxxxxxxxxxxxxxxxxxxx.mailgun.org # For sendinblue # MAIL_DRIVER=smtp # MAIL_HOST=smtp-relay.sendinblue.com # MAIL_PORT=587 # [email protected] # MAIL_PASSWORD=xxxxxxxxxxxxxxxxxxxxxx # MAIL_ENCRYPTION=tls # [email protected] # MAIL_FROM_NAME="${APP_NAME}" 欢迎来到 Opedie,这是您获取技术、Web 开发和面试问题的最新消息和趋势的首选来源。 我们的使命是提供有价值的见解和实用技巧,帮助我们的读者了解最新的科技行业发展动态。无论您是初学者还是经验丰富的专业人士,我们都能为您提供深入的教程、操作指南和专家意见。 在 opedie,我们对 Web 开发的所有方面都充满热情,从最新的 JavaScript 框架到响应式设计的最佳实践。我们不断探索新技术并试验新技术,为您的 Web 项目带来最具创新性和最有效的解决方案。 我们经验丰富的作家和贡献者团队来自不同的背景,具有网络开发方面的专业知识。我们致力于提供高质量、经过深入研究的内容,既信息丰富又引人入胜。 感谢您访问 opedie,我们希望您发现我们的内容对您有所帮助和启发。如果您有任何问题或建议,请随时与我们联系。我们总是很高兴收到读者的来信! 请访问-https://opedie.com


© www.soinside.com 2019 - 2023. All rights reserved.