我正在Laravel的一个项目上工作.我有一个帐户模型,可以有父母或可以有孩子,所以我的模型设置如下:
public function immediateChildAccounts()
{
return $this->hasMany('Account', 'act_parent', 'act_id');
}
public function parentAccount()
{
return $this->belongsTo('Account', 'act_parent', 'act_id');
}
Run Code Online (Sandbox Code Playgroud)
这很好用.我想做的是让所有孩子都在某个帐户下.目前,我这样做:
public function allChildAccounts()
{
$childAccounts = $this->immediateChildAccounts;
if (empty($childAccounts))
return $childAccounts;
foreach ($childAccounts as $child)
{
$child->load('immediateChildAccounts');
$childAccounts = $childAccounts->merge($child->allChildAccounts());
}
return $childAccounts;
}
Run Code Online (Sandbox Code Playgroud)
这也有效,但我不得不担心它是否很慢.这个项目是我们在工作中使用的旧项目的重写.我们将有几千个帐户迁移到这个新项目.对于我所拥有的少数测试帐户,此方法不会产生任何性能问题.
有更好的解决方案吗?我应该只运行原始查询吗?是否Laravel有东西来处理呢?
总结 我想做什么,对于任何给定的帐户,是在单个列表/集合中获取每个子帐户及其子项的每个子项等.图:
A -> B -> D
|--> C -> E
|--> F
G -> H
Run Code Online (Sandbox Code Playgroud)
如果我运行A-> immediateChildAccounts(),我应该得到{B,C}
如果我运行A-> allChildAccounts(),我应该得到{B,D,C,E,F}(顺序无所谓)
同样,我的方法有效,但似乎我做了太多的查询.
另外,我不确定在这里问这个是否可以,但它是相关的.如何获取不包含子帐户的所有帐户的列表?所以基本上是上述方法的逆.这是一个用户不会尝试给帐户一个已经是它的孩子的父母.使用上面的图表,我想要(在伪代码中):
Account :: where(account_id不在(A-> allChildAccounts())).所以我会{G,H} …
我使用libGDX生成一些我现在需要导入Eclipse的gradle项目.所以,我打开Eclipse,安装了gradle插件,然后转到File - > Import - > Gradle Project.那时,我选择了包含我生成的gradle项目的目录.然后,我单击"构建模型",然后将我的项目添加到要导入的可用项目列表中.选择"完成"后,Eclipse开始导入它们.就在最后,我得到了这个对话框:

查看日志文件,我发现了这个堆栈跟踪:
java.lang.NullPointerException
at org.springsource.ide.eclipse.gradle.core.wizards.GradleImportOperation.refreshProjects(GradleImportOperation.java:256)
at org.springsource.ide.eclipse.gradle.core.wizards.GradleImportOperation.perform(GradleImportOperation.java:195)
at org.springsource.ide.eclipse.gradle.ui.wizards.GradleImportWizard$1.doit(GradleImportWizard.java:66)
at org.springsource.ide.eclipse.gradle.core.util.GradleRunnable$1.run(GradleRunnable.java:49)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Run Code Online (Sandbox Code Playgroud)
我已经尝试重新安装相关的一切.我已多次创建这些项目.我已经下载了一个新版本的eclipse.但是,每次都会出现同样的问题.任何帮助都会很棒.谢谢.
我发现,在Laravel中构建我的数据库模式时,失败的迁移不会回滚,这会使迁移变得毫无意义.
例如,我有这个迁移:
Schema::create('accounts', function(Blueprint $table)
{
$table->increments('act_id');
$table->string('act_name', 50)->unique();
$table->boolean('act_active')->default(1);
$table->unsignedInteger('act_type');
$table->unsignedInteger('act_businesstype')->default(1);
$table->timestamps();
});
Schema::table('accounts', function($table)
{
$table->foreign('act_businesstype')->references('bst_id')->on('businesstypes');
});
Run Code Online (Sandbox Code Playgroud)
无论如何,如果我运行该迁移,表创建就好了,但是外键失败并且我收到错误.没关系.我应该得到一个错误.但是,常识让我假设如下:
可以,然后呢
我在这里做错了吗?我弄清楚如何"撤消"失败的迁移的唯一方法是实际进入数据库并删除表.在处理复杂的架构时,这是非常令人沮丧的,我会来回修复错误.
所以,我想我现在已经有了我的小咆哮,我的问题是:
如何回滚抛出错误的迁移?
我正在同时构建一个 Vue 应用程序和一个 Vue 组件库。因此,我想使用 npm 链接设置库,这样我就不必继续发布我的库包并将其重新安装在我的主应用程序中。
我的包将被称为@company/vue. 我可以将其发布到 npm 并在我的 Vue 应用程序中安装/使用它,如下所示:
import Vue from 'vue';
import VueComponents from '@company/vue';
Vue.use(VueComponents);
Run Code Online (Sandbox Code Playgroud)
效果很好。我可以访问 .vue 文件中的组件等等。
但是,如果我按照标准步骤链接我的库:
启动开发模式后,我收到此警告:
export 'default' (imported as 'VueComponents') was not found in '@company/vue'
Run Code Online (Sandbox Code Playgroud)
当然,页面中没有任何内容加载。
我必须想象我可能把它捆绑错了?
我的构建脚本如下所示:
vue-cli-service build --no-clean --target lib --name company-vue src/index.js
Run Code Online (Sandbox Code Playgroud)
它指的是我的index.js:
vue-cli-service build --no-clean --target lib --name company-vue src/index.js
Run Code Online (Sandbox Code Playgroud)
这只是我见过的大多数图书馆的标准方式。再说一遍,如果我从 npm 中提取包,它就可以正常工作。
这是与我的 package.json 中的捆绑相关的内容:
import './index.scss';
import * as components from …Run Code Online (Sandbox Code Playgroud) 我正在使用 C# 和 PDFium 库将 PDF 打印到特定标签打印机。当我通过 Chrome、Edge 或我的应用程序打印此 PDF 时,质量有问题。当我通过 Adobe Reader 或 Foxit Reader 打印时,质量正是我想要的。
这是差异的imgur图片:https ://i.imgur.com/gSnYcEE.jpg
我的应用程序是标记为“网络打印”的应用程序。正如您在图像中看到的,它的质量与浏览器的性能相匹配。尤其是右边的小文字是我最关心的。
那么,桌面 PDF 阅读器在打印时有何不同?
这是在 C# 中实际打印 PDF 的代码:
public static Boolean Print(PrintQueue printer, byte[] content, Boolean landscape)
{
using (MemoryStream stream = new MemoryStream(content))
{
PdfDocument doc = PdfDocument.Load(stream);
PrintDocument pd = GetPrintDocumentAsPDF(printer.Name, doc, landscape);
pd.Print();
return true;
}
}
private static PrintDocument GetPrintDocumentAsPDF(String printerName, PdfDocument doc, Boolean landscape)
{
PdfPrintMultiplePages multiPages = new PdfPrintMultiplePages(1, 1, landscape ? System.Windows.Forms.Orientation.Horizontal …Run Code Online (Sandbox Code Playgroud) 这几天我一直在尝试设置 Vue 组件库。我浏览了几个教程并通读了一些流行的现有 UI 库的代码。我的问题归结为:
我的库名为@company/vue-components
我使用 npm 将库安装到项目中:
npm install @company/vue-components
Run Code Online (Sandbox Code Playgroud)
然后我尝试将我的库注册为 Vue 的插件:
import Vue from 'vue';
import VueComponents from '@company/vue-components';
Vue.use(VueComponents);
Run Code Online (Sandbox Code Playgroud)
我尝试在 vue-cli 生成的 About.vue 页面(称为 EButton)中使用我的组件:
<template>
<div class="about">
<h1>This is an about page</h1>
<e-button color="primary">Click this button</e-button>
</div>
</template>
<script>
export default {
};
</script>
Run Code Online (Sandbox Code Playgroud)
但我收到一个错误:
[Vue warn]: Unknown custom element: <e-button> - did you register the component correctly? For recursive components, make sure to provide the "name" option
Run Code Online (Sandbox Code Playgroud)
如果我回到注册插件的地方,我可以进行这一更改并且它会起作用:
import VueComponents from '@company/vue-components/src/index';
Run Code Online (Sandbox Code Playgroud)
所以,我想我没有正确构建我的 …
我有一个与地址模型有多态关系的帐户模型.这被设置为一对一的关联设置如下:
帐户:
public function address()
{
return $this->morphOne('Address', 'hasAddress', 'add_hasaddress_type', 'add_hasaddress_id', 'act_id');
}
Run Code Online (Sandbox Code Playgroud)
地址:
public function hasAddress()
{
return $this->morphTo('hasAddress', 'add_hasaddress_type', 'add_hasaddress_id');
}
Run Code Online (Sandbox Code Playgroud)
在我的表单上编辑帐户,我也有地址字段.我可以通过以下方式简单地绑定我的帐户对象:
{{ Form::model($account, array('route' => array('accounts/edit', $account->act_id), 'method' => 'put')) }}
{{ Form::label('act_name', 'Account Name:') }}
{{ Form::text('act_name', Input::old('act_name')) }}
Run Code Online (Sandbox Code Playgroud)
并且填写正确的字段.但是,如何填充地址字段?根据我的研究,我需要做:
{{ Form::text('address.add_city', Input::old('address.add_city')) }}
Run Code Online (Sandbox Code Playgroud)
要访问关系的值,但这不起作用.
我也试过了
{{ Form::text('address[add_city]', Input::old('address[add_city]')) }}
Run Code Online (Sandbox Code Playgroud)
正如具有类似标题的SO所暗示的那样.这两个我尝试过和没有旧的输入.这不适用于简单的关系,还是我做错了什么?
另外,如何在控制器中处理这些表单?
关于关系的任何内容都不在形式模型绑定文档中,并且进行搜索主要是让人们要求一对多绑定.
我有一个表帐户:
act_id,
act_name,
act_address
Run Code Online (Sandbox Code Playgroud)
我有一个表地址:
add_id,
add_street1,
<other fields you'd expect in an address table>
Run Code Online (Sandbox Code Playgroud)
accounts.act_address 是addresses.add_id 的外键。在 Laravel 中,我有我的帐户模型:
use LaravelBook\Ardent\Ardent;
use Illuminate\Database\Eloquent\SoftDeletingTrait;
class Account extends Ardent
{
use SoftDeletingTrait;
protected $table = 'accounts';
protected $primaryKey = 'act_id';
public static $rules = array
(
'act_name' => 'required|unique:accounts'
);
protected $fillable = array
(
'act_name'
);
public function address()
{
return $this->hasOne('Address', 'add_id', 'act_address');
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我在这里设置了一对一关系。(当然,Address 模型也有一个“belongsTo”)。这一切都有效。
问题是,地址外键可以为空,因为帐户不需要地址。因此,如果我在没有帐户->地址的情况下尝试访问它,我会收到“尝试访问非对象的属性”错误。
如果帐户记录没有一组,我想做的是将帐户->地址设置为新的地址对象(所有字段为空)。
我所能做的是在模型中创建第二种方法:
public function getAddress()
{
return empty($this->address) ? new Address() …Run Code Online (Sandbox Code Playgroud) 我正在使用 Jasper Reports 和 Java 创建一些报告。在界面中,用户选择1个或多个项目,并为每个项目生成报告。现在,我有查询:
SELECT * FROM StockInventory
Run Code Online (Sandbox Code Playgroud)
这是在 jrxml 文件中。但是,通过我的应用程序运行它,它会为表中的每个项目创建一个报告。我想要的是:
SELECT * FROM StockInventory WHERE pk IN (?...)
Run Code Online (Sandbox Code Playgroud)
其中“?...”是用户选择的项目的键。因此,不仅参数是动态的,而且参数的数量也是动态的。
我的问题是,我不知道如何在 jrxml 中设置参数,也不知道如何从 Java 的 jasperreports 库中设置参数。目前,要设置值,我正在这样做:
Map<String, Object> params = new HashMap<String, Object>();
JasperReport report = JasperCompileManager.compileReport("path\\to\\jrxml");
JasperPrint print = JasperFillManager.fillReport(report, params, new ItemData(keys));
Run Code Online (Sandbox Code Playgroud)
ItemData() 在哪里:
private class ItemData implements JRDataSource
{
private final List<InventoryItem> items;
private int counter;
public ItemData(List<PrimaryKey> keys)
{
items = new ArrayList<InventoryItem>();
InventoryItemDao dao = new InventoryItemDao();
for(PrimaryKey key : keys)
{ …Run Code Online (Sandbox Code Playgroud)