我有以下内容:
value = 42
array = ["this","is","a","test"]
Run Code Online (Sandbox Code Playgroud)
我怎么能转换它来得到这个
{ "this" => { "is" => { "a" => { "test" => 42 } } } }
Run Code Online (Sandbox Code Playgroud)
阵列总是平的.
谢谢!
我想知道在Java上使用HB更新一个脱离对象的某些字段的最佳方法是什么.特别是当对象具有子对象属性时.例如(删除注释并减少字段数以减少噪音):
public class Parent {
int id;
String field2;
...
Child child;
}
public class Child {
int id;
String field3;
}
Run Code Online (Sandbox Code Playgroud)
在MVC webapp中更新Parent时,我可以使用Session.get(Parent.class,123)调用父实例,使用它来填充表单并显示它.没有DTO,只有被释放的父级传递给视图并绑定到表单.现在,我只想让用户更新父级的field2属性.因此,当用户发布表单时,我得到一个父实例,其中id和field2已填充(我认为mvc框架在这里不重要,绑定时所有行为大致相同).
现在,哪种策略最适合执行实体更新?我可以考虑一些替代方案,但我想听听专家:)(请记住,我不想放松父实例和子实例之间的关系)
A)再次从Session中重新获取Parent实例,并手动替换更新的字段
Parent pojoParent; //binded with the data of the Form.
Parent entity = Session.get(Parent.class,pojoParent.getId());
entity.setField2(pojoParent.getField2()).
Run Code Online (Sandbox Code Playgroud)
我经常使用它.但pojoParent似乎被用作卧底DTO.如果要更新的字段数量变大,那也很糟糕.
B)将Child存储在某处(httpSession?)并将其关联到后者.
Parent parent = Session.get(Parent.class,123);
//bind the retrieved parent to the form
// store the Child from parent.getChild() on the httpSession
...
//when the users submits the form...
pojoParent.setChild(someHttpSessionContext.getAttribute('Child'))
Session.save(pojoParent);
Run Code Online (Sandbox Code Playgroud)
我认为这是垃圾,但我在一些项目中看到了......
C)将Parent和Child之间的关系设置为不可变.在关系上使用 …
我怀疑很长一段时间......希望任何人都能看到我.
假设我的模型中有3个类.
abstract class Document {}
class Letter extends Document {}
class Email extends Document {}
Run Code Online (Sandbox Code Playgroud)
和一个服务类,其方法返回一个Document(一个Letter或Email).
class MyService {
public Document getDoc(){...}
}
Run Code Online (Sandbox Code Playgroud)
因此,在我的控制器中,我想显示MyService返回的文档,我希望它使用电子邮件的视图和信函的其他视图显示.控制器如何知道调用哪个文档视图?letterView或emailView?.
我经常在控制器上创建一个if语句来检查服务层接收到的Document的类型......但是我不认为从OOP的角度来看这是最好的方法,如果我实现了一些布尔方法Document. isLetter(),Document.isEmail()解决方案本质上是相同的.
另一件事是以某种方式将视图选择委托给Document.就像是:
class MyController {
public View handleSomething() {
Document document = myService.getDocument();
return document.getView();
}
}
Run Code Online (Sandbox Code Playgroud)
但是,omg,为什么我的模型对象必须知道关于视图的任何信息?
任何强硬都值得赞赏:)
我需要在SVG画布中放置一个按钮标签,有没有办法?(我正在使用raphael JS)
我知道我可以在svg画布内"绘制"一个按钮并对onclick事件进行编码,但我希望保留浏览器按钮的原生外观.谢谢.
我有一个带有@Id和@TableGenerator的'dog'Entitiy
...
@TableGenerator(table = "seq", name = "dog_gen", pkColumnName = "seq_name", valueColumnName="seq_val")
@Id @GeneratedValue(strategy = GenerationType.TABLE, generator = "dog_gen")
private Long id;
...
Run Code Online (Sandbox Code Playgroud)
有没有办法在其他实体中重用相同的表生成器(dog_gen)?我想在两个独立的实体中保持相同的id序列
dog = 1,dog = 2,dog = 3,cat = 4,cat = 5,dog = 6等等......
两个实体不共享一个公共超类来实现与id属性的某种继承.
如果我添加了@GeneratedValue(发电机="dog_gen")对我的猫实体,省略@TableGenerator声明抛出一个异常说开始的背景下,当它找不到发电机.
Caused by: org.hibernate.AnnotationException: Unknown Id.generator: dog_gen
at org.hibernate.cfg.BinderHelper.makeIdGenerator(BinderHelper.java:413)
at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1795)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1229)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:733)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:498)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:277)
Run Code Online (Sandbox Code Playgroud) 我有以下问题.如果我从2年前到今天要求石墨图表,每秒都有数据,如下所示:
http://graphite/render?target=averageSeries(server.web1.load)&from=-2years
Run Code Online (Sandbox Code Playgroud)
它显示正确,非常快.显然,并非所有过去两年的积分都被渲染出来.但是,如果我要求石墨为csv输出自己使用其他绘图库渲染点:
http://graphite/render?target=averageSeries(server.web*.load)&from=-2years&format=csv
Run Code Online (Sandbox Code Playgroud)
我得到了整套积分(2年*365天*24小时*60分钟*60秒积分).有没有办法让石墨减少这个数量?例如,要求最多N个点进行大小为WHOLE/N或类似的组的平均值.谢谢
我有一个带有onbeforeunload函数的'ask_a_question'页面,在离开未保存的东西之前提醒用户(嘿!如SO:P).我正在使用带有水豚和webdriver的黄瓜进行测试,添加了@javascript标签,因为它使用了大量的javascript.黄瓜功能可能如下所示:
@javascript
Scenario: add a question
Given I login as "Mauricio"
And I go to the create question page
Then I should see "Ask a Question" within "header"
Run Code Online (Sandbox Code Playgroud)
但是一旦测试开始,Capybara(或WebDriver,我不知道)尝试重复使用相同的浏览器窗口进行其他测试,然后显示onbeforeunload警告,拧紧以下测试.
由于我的功能本身并未关闭或退出页面.我不认为添加一些东西来接受警报可能是个好主意.但说实话,我很失落.
如何告诉capybara为每个@javascript测试使用新的浏览器窗口或自动关闭onbeforeunload警报?
感谢名单