我想知道在什么情况下你使用封装.这个问题的目的是协作.因此,当主题被封装时,请随意分享您自己的经验.
一些场景:
计算财产
public class Order {
private List<ListItem> listItems = new ArrayList<ListItem>();
public double getTotal() {
double total = 0;
for(ListItem listItem: listItems)
total += listItem.getQuantity() * listItem.getPropduct().getPrice();
return total;
}
}
Run Code Online (Sandbox Code Playgroud)
自我验证域对象
public class Person {
private String name;
public void setName(String name) {
if(StringUtils.isBlank(name)) {
throw new NotEmptyException("name", name);
}
this.name = name;
}
}
Run Code Online (Sandbox Code Playgroud)
对某些特殊行为使用其他类
public class Person {
private MutableInt id = new MutableInt();
/**
* Integer itself is immutable
*/
public Integer …
Run Code Online (Sandbox Code Playgroud) 我有一个看起来像的#class类
public class Node {
public int Id { get; set; }
/** Properties omitted for sake of brevity **/
public Node ParentNode { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在浏览器中,我提交了一个JSON对象,如下所示
{"Id":1, "ParentNode":1}
Run Code Online (Sandbox Code Playgroud)
分配给ParentNode属性的值1表示数据库标识符.因此,为了正确绑定到我的模型,我需要编写一个自定义的JSON转换器
public class NodeJsonConverter : JsonConverter
{
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
{
return null;
}
/** Load JSON from stream **/
JObject jObject = JObject.Load(reader);
Node node = new Node();
/** Populate object properties **/
serializer.Populate(jObject.CreateReader(), node); …
Run Code Online (Sandbox Code Playgroud) 我想知道JavaScript开发在你的工作中需要多少时间(以百分比表示).我使用复杂的富Internet应用程序,我将大部分时间花在JavaScript开发上.
而且您:您在JavaScript开发中花了多少时间,以及如何减少它?
问候,
如果我想创建一个JQuery UI对话框,我使用类似的东西:
var settings = {autoOpen:false, draggable:false, and so on...};
var dialog = $("#container").dialog(settings);
Run Code Online (Sandbox Code Playgroud)
但现在我想知道我如何检索如上所示的对话框设置,例如
dialog.getSettings();
Run Code Online (Sandbox Code Playgroud)
我需要它,因为我有一个应用程序使用许多具有默认行为的对话框.就像是
function doAfterSubmit(dialogSettings) {
// some code
}
var dialogSettings = {
user:{
add:{
title:"Add user",
buttons:{
"Add":function() {
var settings = $(this).getSettings(); // The answer goes here
// AJAX to send some content
doAfterSubmit(settings);
}
},
otherProperties
},
remove:{
title:"Remove user",
buttons:{
"Remove":function() {
var settings = $(this).getSettings(); // The answer goes here
// AJAX to send some content
doAfterSubmit(settings);
}
},
otherProperties …
Run Code Online (Sandbox Code Playgroud) 我有一个如下设计的问题域模型
class Question {
List<Choice> choiceCollection;
static hasMany = [choiceCollection:Choice]
static mappping = {
choiceCollection(joinTable:false)
}
}
Run Code Online (Sandbox Code Playgroud)
为了满足我的需求,已经自定义了/grails-app/views/question/create.gsp,如下所示
create.gsp
<g:each var="i" in="${(0..4)}">
<div class="fieldcontain required">
<label for="description">
Option ${i + 1}.
<span class="required-indicator">*</span>
</label>
<g:textArea name="choiceCollection[${i}].description" cols="40" rows="5" maxlength="2000" value="${questionInstance?.choiceCollection[i]?.description}"/>
</div>
</g:each>
Run Code Online (Sandbox Code Playgroud)
当我尝试访问创建视图时,我收到以下错误
Error evaluating expression [questionInstance?.choiceCollection[i]?.description]: Cannot invoke method getAt() on null object
Run Code Online (Sandbox Code Playgroud)
问题:如何运行我的应用程序?
Grails版本:2.1.1
我喜欢Google Web Tookit API方法.它在幕后使用Java语言,只编译目标浏览器所需的JavaScript代码.有些开发人员希望在纯JavaScript语言中使用该功能.
Anwser:为了满足这一要求,我们可以提出什么建议?
我建议使用JavaScript注释(作为标志)作为某种编译器(如Yahoo JavaScript编译器)分析我们的应用程序JavaScript代码并仅生成所需的JavaScript框架代码的方式.
示例:假设的JavaScript框架(JQuery,Mootools,Prototype等)代码
// depends function say
funcion sayHello() {
// some code
}
function say() {
// some code
}
// more and more no needed Javascript framework functions in our app
Run Code Online (Sandbox Code Playgroud)
因此,当我的应用程序使用函数sayHello时,只有sayHello函数及其依赖项将通过JavaScript注释进行过滤,没有别的.因此,通过仅使用所需的JavaScript Framework代码,我们的应用程序将更轻松.
而你:你有什么建议?
请参阅以下ArrayList:
List<Integer> values = new ArrayList<Integer>();
values.add(0);
values.add(1);
values.add(2);
values.add(3);
values.add(4);
values.add(5);
values.add(6);
Run Code Online (Sandbox Code Playgroud)
所以我们有:
integerList.size(); // outputs 7 elements
Run Code Online (Sandbox Code Playgroud)
我需要按如下方式显示Google图表:
为了生成它的值,我只是打电话
StringUtils.join(values, ","); // outputs 0,1,2,3,4,5,6
Run Code Online (Sandbox Code Playgroud)
它发生它支持高达 1000像素的宽度.因此,如果我有很多值,我需要将ArrayList拆分为其他ArrayLists以生成其他图表.就像是:
Integer targetSize = 3; // And suppose each target ArrayList has size equal to 3
// ANSWER GOES HERE
List<List<Integer>> output = SomeHelper.split(values, targetSize);
Run Code Online (Sandbox Code Playgroud)
我应该用什么助手来实现我的目标?
见例子
单击show container链接后,将在UI对话框下方显示datepicker组件 - 第二个输入.我该怎么做才能在UI对话框上面显示它?
我需要Java和/或PHP中的JSON,JS Array解析器.你知道任何解析器吗?
问候,