我对使用静态hasOne映射和在域类中组合对象之间的区别感到困惑.两者有什么不同?即.
class DegreeProgram {
String degreeName
Date programOfStudyApproval
static hasOne = [committee:GraduateCommittee]
}
Run Code Online (Sandbox Code Playgroud)
与
class DegreeProgram {
String degreeName
Date programOfStudyApproval
GraduateCommittee committee
}
Run Code Online (Sandbox Code Playgroud)
GraduateCommittee是另一个GORM领域模型类.
我在代码中看到了这个.它让我大吃一惊.
<% if (false) { %>
<script type="text/javascript" src="~/Scripts/jquery-1.3.2.js"></script>
<% } %>
Run Code Online (Sandbox Code Playgroud)
这似乎是非常不合逻辑的,它必须是故意的.我只能假设某种方式"出现",有人将其作为解决方案插入.当然,没有评论.
为什么有人会这样做?
我已经编码多年了,发现自己处于挫折之中.我正在开发一个新的基于Web的服务,它也有一个用户界面,它将从头开始开发.它将使用一些开源组件,但主要是一个新的东西.
但这是我的问题.构建这样的系统意味着构建所有这些组件:
我希望他们所有人都遵循相同的"模式",系统中的模块由一个文件夹或一组文件组成,这些文件包含该模块中的所有这些组件.
但是我很难获得这个架构以便我喜欢它.这是我到目前为止:
但我确实感到非常愚蠢 - 因为以程序的方式构建了主系统.我最初开始在OOP中开始编写它,但由于必须使所有内容都适合同一系统,因此很快发现自己处于头痛状态.它是OOP,但它是紧密耦合的,我不喜欢它,虽然它是以OOP方式编写的,组件实际上不是那么独立或者只是管理的麻烦.
我可以遵循任何模式或指南来获得更好的结果吗?我喜欢当前的系统是我可以调用任何东西,预览呈现PHP,或HTML视图,CSS样式,额外的Javascript函数和每个需求的AJAX通信,保持脚步非常小,但它感觉很脏.我甚至使用全局主数据库连接(尽管它是一个全局对象).
有任何想法吗?如果它只是一种语言就不会成为一个问题,但试图让一切工作在一起是一件令人头痛的问题.
谢谢!
我正在尝试修补Drupal Panels模块以修复这个令人讨厌的问题,这使得AJAX错误处理程序完全不可读.错误处理程序有这个:
// Replace all < and > by < and >
error_text = error_text.replace("/&(lt|gt);/g", function (m, p) {
return (p == "lt")? "<" : ">";
});
Run Code Online (Sandbox Code Playgroud)
我尝试了两种方法:
添加
// Now replace all " with ' for readability, for goodness sakes, per
// http://drupal.org/node/1124042
error_text = error_text.replace(/"/g, "'");
Run Code Online (Sandbox Code Playgroud)
修改
// Replace all < and > by < and >
error_text = error_text.replace("/&(lt|gt|quot);/g", function (m, p) {
return (p == "lt")? "<" : (p == "gt") ? ">" : …Run Code Online (Sandbox Code Playgroud) Grails GORM不会将抽象域类持久保存到数据库中,从而导致多态关系中断.例如:
abstract class User {
String email
String password
static constraints = {
email(blank:false, nullable:false,email:true)
password(blank:false, password:true)
}
static hasMany = [membership:GroupMembership]
}
class RegularEmployee extends User {}
class Manager extends User {
Workgroup managedGroup
}
class Document {
String name
String description
int fileSize
String fileExtension
User owner
Date creationTime
Date lastModifiedTime
DocumentData myData
boolean isCheckedOut
enum Sensitivity {LOW,MEDIUM,HIGH}
def documentImportance = Sensitivity.LOW
static constraints = {
name(nullable:false, blank:false)
description(nullable:false, blank:false)
fileSize(nullable:false)
fileExtension(nullable:false)
owner(nullable:false)
myData(nullable:false)
}
}
Run Code Online (Sandbox Code Playgroud)
原因 …
当阅读关于遗传算法的交叉部分时,书籍和论文通常指的是简单地交换要再现的两个所选候选者的数据中的比特的方法.
我还没有看到用于实际行业应用的实现遗传算法的实际代码,但我发现很难想象它足以在简单的数据类型上运行.
我总是想象遗传算法的各个阶段将在涉及复杂数学运算的复杂对象上执行,而不是仅仅在单个整数中交换一些位.
甚至维基百科也只是为交叉列出了这些类型的操作.
我错过了一些重要的东西,或者这些交叉方法真的是唯一使用的东西吗?
algorithm optimization search genetic-algorithm evolutionary-algorithm
我不幸地处理了一个用以下内容定义的接口
public Map<?, ?> getMap(String key);
Run Code Online (Sandbox Code Playgroud)
我正在尝试编写使用此接口的单元测试.
Map<String,String> pageMaps = new HashMap<String,String();
pageMaps.put(EmptyResultsHandler.PAGEIDENT,"boogie");
pageMaps.put(EmptyResultsHandler.BROWSEPARENTNODEID, "Chompie");
Map<?,?> stupid = (Map<?, ?>)pageMaps;
EasyMock.expect(config.getMap("sillyMap")).andReturn(stupid);
Run Code Online (Sandbox Code Playgroud)
并且编译器是borking.
The method andReturn(Map<capture#5-of ?,capture#6-of ?>) in the type IExpectationSetters<Map<capture#5-of ?,capture#6-of ?>> is not applicable for the arguments (Map<capture#7-of ?,capture#8-of ?>)
Run Code Online (Sandbox Code Playgroud)
如果我尝试pageMaps直接使用,它会告诉我:
The method andReturn(Map<capture#5-of ?,capture#6-of ?>) in the type IExpectationSetters<Map<capture#5-of ?,capture#6-of ?>> is not applicable for the arguments (Map<String,String>)
Run Code Online (Sandbox Code Playgroud)
如果我做pageMaps了Map<?,?>,我不能把字符串放在里面.
The method put(capture#3-of ?, capture#4-of ?) in the type Map<capture#3-of ?,capture#4-of ?> …Run Code Online (Sandbox Code Playgroud) 我对嵌套域类有内部要求,我希望将父关系的更新传播给子项.代码示例可以说清楚:
class Milestone {
static belongsTo = [project:Project]
static hasMany = [goals:OrgGoals, children:Milestone]
String name
Date start
Date estimatedEnd
Date achievedEnd
...
}
Run Code Online (Sandbox Code Playgroud)
当父里程碑的estimatedEnd更新时,我希望孩子的估计会自动更新相同的金额.GORM的beforeUpdate()钩子似乎是一个合乎逻辑的地方:
为了让生活更轻松,我想使用一些简单的Date算法,所以我在Milestone类中添加了以下方法:
def beforeUpdate()
{
// check if an actual change has been made and the estimated end has been changed
if(this.isDirty() && this.getDirtyPropertyNames().contains("estimatedEnd"))
{
updateChildEstimates(this.estimatedEnd,this.getPersistentValue("estimatedEnd"))
}
}
private void updateChildEstimates(Date newEstimate, Date original)
{
def difference = newEstimate - original
if(difference > 0)
{
children.each{ it.estimatedEnd+= difference }
}
}
Run Code Online (Sandbox Code Playgroud)
没有编译错误.但是当我运行以下集成测试时:
void …Run Code Online (Sandbox Code Playgroud) 可能重复:
对象为空?
update: (id, data) ->
toUpdate = @find(id)
if toUpdate isnt {}
console.log "hi mom"
console.log toUpdate
toUpdate.setProperty(key, value) for own key, value of data
return toUpdate
find:(id) ->
result = record for record in @storage when record.id is id
return result or {}
Run Code Online (Sandbox Code Playgroud)
鉴于以下Mocha测试
describe '#update', ->
it 'should return an updated record from a given id and data when the record exists', ->
boogie = createData()
archive = new Archive("Dog")
dog = archive.create(boogie)
result = archive.update(1, {name:"Chompie", …Run Code Online (Sandbox Code Playgroud) grails ×3
grails-orm ×3
javascript ×2
algorithm ×1
asp.net ×1
coding-style ×1
coffeescript ×1
easymock ×1
frameworks ×1
generics ×1
hibernate ×1
html ×1
if-statement ×1
inheritance ×1
java ×1
oop ×1
optimization ×1
orm ×1
php ×1
regex ×1
search ×1
type-erasure ×1