我正在开发Java桌面应用程序,并且对使用JavaFX非常感兴趣。我计划使用MVC架构,因为我对Java EE和MVC模型有一定的经验。
我想将数据存储在嵌入式derby数据库中,并使用Hibernate作为持久层,但是找不到关于使用hibernate和JavaFX实现MVC的出色教程。
我已经创建了持久性文件,但不确定如何使其与JavaFX一起使用。在Java EE中,我注入了EJB服务或DAO,但是由于我的应用程序未与服务器连接,因此我认为我无法做到这一点。
有人可以解释我如何实现这一目标吗?可以一起使用吗?
我已被指示在log4net旁边使用AutoFac(而不是Castle Windsor),并且在如何正确使用这些技术方面迷失了方向.
使用autofac网站上的示例我有以下LoggerModule
public class LoggingModule : Module
{
private static void InjectLoggerProperties(object instance)
{
var instanceType = instance.GetType();
// Get all the injectable properties to set.
// If you wanted to ensure the properties were only UNSET properties,
// here's where you'd do it.
var properties = instanceType
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => p.PropertyType == typeof(ILog) && p.CanWrite && p.GetIndexParameters().Length == 0);
// Set the properties located.
foreach (var propToSet in properties)
{
propToSet.SetValue(instance, LogManager.GetLogger(instanceType), null);
}
}
private …Run Code Online (Sandbox Code Playgroud) 从许多不同来源阅读后,我对View和Model应如何在MVC中与Swift进行通信感到非常困惑
如何用Swift做同样的事情(这里是Objective-c)
在模型中:
(void)receivedMessageFromServer {
// Fire the notification
[[NSNotificationCenter defaultCenter] postNotificationName:@"ReceivedData" object:nil];
}
Run Code Online (Sandbox Code Playgroud)
在View Controller中处理"ReceivedData"通知:
(void)viewDidLoad {
[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedDataNotification:) name:@"ReceivedData" object:nil];
}
-(void)receivedDataNotification:(id)object {
NSLog(@"Received Data!");
}
Run Code Online (Sandbox Code Playgroud) 我有一个foreach循环从数据库循环我的文档,它只拉入IMAGES然后我在页面上每行有4个图像,我想点击一个它打开一个模态与图像,再次点击另一个相同.所以我有这个设置:
@foreach (var item in Model.DocumentList)
{
// Below I am currently using just a ID for modal (which i know is wrong)
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" data-toggle="modal)" data-target="#myModal" title="@item.FileDescription">
@Html.DocumentUrl(item.FileUrl, false)
</a>
<span class="col-xs-12" style="text-align:center;">@item.CreatedDate.ToShortDateString()</span>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Uploaded - @item.CreatedDate.ToShortDateString()</h4>
</div>
<div class="modal-body">
@Html.DocumentUrl(item.FileUrl, true)
<div class="row">
<div class="col-md-12">
<p>
@item.FileDescription
</p>
</div>
</div>
</div> …Run Code Online (Sandbox Code Playgroud) 这个问题围绕着在Java中实现MVC架构的标准实践 - 特别是Swing.我知道之前已经提出过这个问题,但我希望对控制器的使用有所了解.
我一直在分离我的模型,视图和控制器,其中:
回到控制器的具体情况 - 我一直在使用类(静态)变量来表示控制器,以便我的应用程序的任何部分都能轻松访问.所以我的控制器类可能如下所示:
public class Controller {
public static ControllerA controllerA;
public static ControllerB controllerB;
}
public class ControllerA {
private JPanel panel1;
private JPanel panel2;
private DefaultListModel list;
}
...
Run Code Online (Sandbox Code Playgroud)
每当我需要做某事时,我会像这样调用控制器:
Controller.controllerA.doSomething
Run Code Online (Sandbox Code Playgroud)
这意味着我的大部分代码都位于控制器中.通常,如果我需要做某事,控制器会有一个方法,它通常需要视图或模型中的等效方法来完成任务.我发现这会导致代码重复.例如:
Controller.controllerA.removeElement();
Run Code Online (Sandbox Code Playgroud)
将在控制器中调用以下方法:
protected void removeElement() {
list.removeElement()
}
Run Code Online (Sandbox Code Playgroud)
随着我的应用程序的增长,我看到很多实例,控制器只是镜像模型或视图所需的操作,因为它是视图/模型的主要访问点.
所以我的问题是:
我被赋予了创建自定义swing组件的任务.我的组件在测试应用程序中正常运行,其中包括用于放大和缩小Image的JSlider.但是我需要以Model,UIDelegate和Component类格式呈现我的自定义组件,我完全迷失了如何转换我的代码以使其遵循这种格式.这是我的测试应用程序的代码.
package test;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.*;
import java.io.File;
import java.net.URL;
import javax.imageio.ImageIO;
public class ZoomDemo extends JComponent implements ChangeListener {
JPanel gui;
/**
* Displays the image.
*/
JLabel imageCanvas;
Dimension size;
double scale = 1.0;
private BufferedImage image;
public ZoomDemo() {
size = new Dimension(10, 10);
setBackground(Color.black);
try {
image = ImageIO.read(new File("car.jpg"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void setImage(Image image) {
imageCanvas.setIcon(new ImageIcon(image));
}
public …Run Code Online (Sandbox Code Playgroud) 在学习@tereško 关于如何构建模型的答案时,我无法找到服务之间进行通信的最佳方式.我也发现这个答案与我正在处理的情况类似,但这个例子很适合展示.因此,从这个意义上说,当服务只能访问域和映射器工厂对象时,如何在Blog服务中检索识别服务.我是否从控制器发送它?或者我是否也需要发送服务工厂?
更新:我没有提供一个例子,因为我提到tereško的第二个答案与我想要实现的非常类似.我正在尝试构建一个BlogService,例如存储帖子.为了存储帖子的作者,我试图检索(他的被叫)识别服务以获得登录用户(显然是帖子的作者).
class BlogService
{
public function storePost($title, $content)
{
$post = $this->domainFactory->build('Post');
$mapper = $this->mapperFactory->build('Post');
$post->setTitle($title);
$post->setContent($content);
$post->setAuthor( /* get logged in user */ );
$mapper->save($post);
}
}
Run Code Online (Sandbox Code Playgroud) 无法找到任何相关内容,但我确信它很简单.
当我使用url更改查询时,我有一个需要复制4次的路由.
目前:
Route::get('/', function()
{
$builds = Blog::findBuilds();
return View::make('pages/home', compact('builds'));
});
Run Code Online (Sandbox Code Playgroud)
我想做的是例如:
Route::get(array('/', '/trending', 'staff-picks'), function()
{
$builds = Blog::findBuilds();
return View::make('pages/home', compact('builds'));
});
Run Code Online (Sandbox Code Playgroud)
但那当然不行.什么诀窍?
我目前正在整理一些用于练习的mvc框架,我有一些laravel经验,因此大致基于此。我做了一个路由器,它只是为您设置的网址返回一个指定的视图。
现在,我还制作了控制器,用于拆分URL,并将基本URL后的第一部分用作控制器,第二部分用作操作。这将加载与控制器相对应的文件,并在该文件中加载与操作相对应的方法。
因此,如果url类似于:url.com/users/index,它将加载UsersController.php文件并在该文件中查找index()方法。
现在我想知道控制器和路由器之间的确切区别是什么?它像指定的吗?其中路由器稍微简单一点,并且只对给定的确切网址做出反应,而路由器将其切碎并增加深度?
我目前所拥有的似乎有很多重叠。
我尝试将两个变量放在来自viewbags的JQuery中:
$("#btnAdd").click(function () {
var url = dev + "/Legacy/PutContentInThematic";
var GroupingId = $("#GroupingId_Dialog").val();
var Title = $("#Title_Dialog").val();
var Synopsis = $("#Description_Dialog").val();
var image = $("#Image_Dialog").val();
var ThematicId = @ViewBag.thematicid //Here i can't put ';'
var ThematicName = @ViewBag.Name
$.ajax({
url: url,
cache: false,
type: 'POST',
data: {
GroupingId: GroupingId,
ThematicId: ThematicId,
Title: Title,
Synopsis: Synopsis,
Image: image,
ThematicName: ThematicName
}
});
});
Run Code Online (Sandbox Code Playgroud)
问题涉及最后两个变量"ThematicId"和"ThematicName",不可能把';' 最后,所以第二个变量ThematicName不起作用.
我尝试将此变量放在函数之外,但我不再工作了.您是否有想法为此Ajax调用修复它或其他解决方案?