可以说我有两个域类:
class User {
String name
Role role
}
class Role {
String name
static belongsTo = [user: User]
}
Run Code Online (Sandbox Code Playgroud)
然后创建一些记录:
def r1 = new Role(name: "role1").save()
def r2 = new Role(name: "role2").save()
new User(name: "user1", role: r1).save()
new User(name: "user2", role: r2).save()
new User(name: "user3", role: r1).save()
Run Code Online (Sandbox Code Playgroud)
现在如何按角色选择我的用户?我希望能够执行以下操作之一:
def role = Role.findByName("role1"); //returns a Role with [ id:1 name:"role1" ]
User.findAllByRole(role) //returns null
User.findAllByRole(new Role(name: "role1")) //returns null
User.findAllByRole(role.id) //returns null
User.findAllByRole(id: role.id) //returns null
Run Code Online (Sandbox Code Playgroud)
域类是否可以使用动态find *方法查找其他关联的域类?我可以使用namedQueries来做到这一点,但可以使用id而不是因为我不想为域类之间的每种关系都将它们写出来
我正在尝试运行一个简单的Lift示例,我遇到了一个奇怪的问题.我现在用的是Sonatype的样品清单项目在这里.我略微修改了HTML,但它最初也没有工作.我遇到的问题是,当我运行本地jetty服务器并尝试访问http:// localhost:8080时,它在Firefox 3.6.10而不是HTML中显示为XML.注意,它在IE8中显示正常,但IE8中的Content-Type是"text/html".我认为Firefox出于某种原因不喜欢Content-Type"application/xhtml + xml".Firefox中的消息说:
此XML文件似乎没有与之关联的任何样式信息.文档树如下所示.
以下是Firebug的响应标头:
Expires Thu, 16 Sep 2010 03:55:04 UTC
Content-Length 558
Cache-Control no-cache; private; no-store
Content-Type application/xhtml+xml; charset=utf-8
Pragma no-cache
Date Thu, 16 Sep 2010 03:55:04 UTC
X-Lift-Version 2.0-scala280-SNAPSHOT
Server Jetty(6.1.22)
Run Code Online (Sandbox Code Playgroud)
..和实际的回应:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Lift Test</title>
</head>
<body>
<h2>Welcome to your project!</h2>
<p>
<span>Welcome to toto01 at Wed Sep 15 20:55:04 PDT 2010</span>
</p>
<script type="text/javascript" src="/ajax_request/liftAjax.js"></script>
<script type="text/javascript">
// …Run Code Online (Sandbox Code Playgroud) 这是由动机此文章(第5页)
template<class T>
T const &f(T const &a, T const &b){
return (a > b ? a : b);
}
template int const &f<int>(int const &, int const &);
int main(){
int x = 0, y = 0;
short s = 0;
f(x, y); // OK
f(x, s); // Is this call well-formed?
}
Run Code Online (Sandbox Code Playgroud)
通话是否'f(x, s)'良好?我假设由于函数模板'f'是显式实例化的,因此'short s'将应用标准转换,因此将转换'int'为匹配对显式特化的调用'f<int>'.但似乎这是不正确的?
标准的哪一部分谈到了这方面的适用规则?
我的数组看起来像这样:
Array ( [Bob] => Red [Joe] => Blue )
Run Code Online (Sandbox Code Playgroud)
但它可能是任何数量的人,像这样:
Array ( [Bob] => Red [Joe] => Blue [Sam] => Orange [Carla] => Yellow)
Run Code Online (Sandbox Code Playgroud)
基本上我希望PHP采用这个数组并回显它,使它看起来像:
Bob - Red
Joe - Blue
Sam - Orange
Carla - Yellow
Run Code Online (Sandbox Code Playgroud)
我知道我需要遍历数组,这是我尝试过的:
for ($row = 0; $row < count($array); $row++) {
echo $array[0] . " - " . $array[1];
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:未定义的偏移量:0,未定义的偏移量:1
我意识到这不起作用,因为当数组的值是字符串时我正在尝试使用索引.有没有什么方法可以使用像这样的位置索引与只包含字符串的多维数组?
谢谢
我有一个与OOPS概念有关的问题.
public class BaseClass
{
public int i = 10;
public int x = 30;
public string str = "Hello";
public virtual string Hello()
{
return "Hello of base class called";
}
}
Run Code Online (Sandbox Code Playgroud)
public class ChildClass : BaseClass
{
public int i = 20;
public int z = 90;
public override string Hello()
{
return "Hello of child class called";
}
}
Run Code Online (Sandbox Code Playgroud)
现在我已经看到下面的代码工作正常
BaseClass baseObject = new ChildClass();
Run Code Online (Sandbox Code Playgroud)
当我输入时,我baseObject.只看到成员BaseClass.
第一个问题:有人可以告诉我开发人员需要这样做的情况BaseClass baseObject = new …
我正在尝试并行编程.我有一个正常的循环:
for (int i = 0; i < 100000; i++)
{
Console.WriteLine("Thread ID: {0} and i is " + i + " Time Elapsed: " + sw.Elapsed,
Thread.CurrentThread.ManagedThreadId);
}
Run Code Online (Sandbox Code Playgroud)
这个循环只是将数字增加到100000
我可以使用此for循环并将其转换为Parallel.For循环以将数字计数到100000但是并行使用所有CPU吗?
此外,使用a时Parallel.For,需要哪些参数?你会如何以一种非常基本的方式使用它?
像这样的东西,我想看到完整的语法.
伪代码:
var = user_input
if var > 5:
output = 'var > 5'
else:
output = 'var < 5'
Run Code Online (Sandbox Code Playgroud) 在MSDN中,我已经阅读了有关EnumConverter的内容:
您永远不应该创建EnumConverter的实例.而是调用TypeDescriptor类的GetConverter方法.有关更多信息,请参阅TypeConverter基类中的示例.
有人知道为什么,对我自己实施的转换器是否属实?
例如,我有类GradientColor和转换器GradientColorConverter.我应该写
new GradientColorConverter().ConvertFrom(colorString)
Run Code Online (Sandbox Code Playgroud)
要么
TypeDescriptor.GetConverter(typeof(GradientColor)).ConvertFrom(colorString);
Run Code Online (Sandbox Code Playgroud)
实际上它在两个方面都有效,但哪个更好?