我有以下Groovy代码:
def number = "246" as List
def number1= number.subsequences()
//outputs: [[6], [2, 6], [4, 6], [2], [2, 4, 6], [4], [2, 4]]
Run Code Online (Sandbox Code Playgroud)
现在我想要的是,每个列表都number1应该返回int,比如说第二个列表number1应该返回为26.我所做的是:
number1.each{ it }.collect() as int
Run Code Online (Sandbox Code Playgroud)
哪个不起作用并抛出错误.这可以通过其他方式完成吗?如果错了,请提前致谢并纠正我
我有一个名为qotd的grails应用程序,它有一个名为的控制器quote.我为这个控制器编写了一个名为random.gspfile的视图文件:
<html>
<head>
<title>Random Quote</title>
</head>
<body>
<div id ="quote">
<q>${content}</q>
<p>${author}</p>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
现在我必须写下这个控制器的Grails布局.例如,我必须找到我的.css和图像文件等,如何做到这一点(如果显示一个例子,会更好)?我应该把文件放在哪里?
提前致谢.
我想知道我是否可以为Spring编写代码并使用Spring框架,如果我在Grails中工作?
我有一个像这样的控制器:
@Secured(['ROLE_USER','IS_AUTHENTICATED_FULLY'])
def userprofile(){
def user = User.get(springSecurityService.principal.id)
params.id = user.id
redirect (action : "show", params:params)
}
Run Code Online (Sandbox Code Playgroud)
我想在spock中测试控制器上面的控制器,所以我写了一个像这样的测试代码:
def 'userProfile test'() {
setup:
mockDomain(User,[new User(username:"amtoasd",password:"blahblah")])
when:
controller.userprofile()
then:
response.redirectUrl == "/user/show/1"
}
Run Code Online (Sandbox Code Playgroud)
当我运行我的测试时,此测试失败并显示以下错误消息:
java.lang.NullPointerException: Cannot get property 'principal' on null object
at mnm.schedule.UserController.userprofile(UserController.groovy:33)
Run Code Online (Sandbox Code Playgroud)
在集成测试的情况下:
class UserSpec extends IntegrationSpec {
def springSecurityService
def 'userProfile test'() {
setup:
def userInstance = new User(username:"antoaravinth",password:"secrets").save()
def userInstance2 = new User(username:"antoaravinthas",password:"secrets").save()
def usercontroller = new UserController()
usercontroller.springSecurityService = springSecurityService
when:
usercontroller.userprofile()
then:
response.redirectUrl == "/user/sho" …Run Code Online (Sandbox Code Playgroud) 我是C的初学者,让我说我有这样的代码:
#include <stdio.h>
void test(char *t)
{
t++;
*t = 'e';
}
void main()
{
char a[] = "anto";
printf("%c\n",a[1]);
test(a);
printf("%c\n",a[1]);
}
Run Code Online (Sandbox Code Playgroud)
这是示例代码,我正在弄清楚指针是如何工作的.根据我的说法:
t++;
Run Code Online (Sandbox Code Playgroud)
在上面的代码将递增数组的地址a由1 char在调用函数test.很好,现在我知道*它用于检索指针指向的对象值.
但奇怪的是,当我改变t++为
*t++;
Run Code Online (Sandbox Code Playgroud)
我得到的输出和以前一样.我字面意思是这个,上面的语句
*t++;应该改变内容只知道,根据*运算符的定义.
但这又改变了地址t.怎么会?我在哪里弄错了这个概念?
提前致谢
在最近的采访中我得到了这样一个问题:
Given a string value, find out its 127th bit and reset it, do this in C language
Reset means if that particular bit is 0 change to 1 and vice versa
我没有找到任何算法,但我想知道如何用C语言解决这个问题.
在得到少数人的答案之后,我尝试了这个:
#include<stdio.h>
void main()
{
char *str="anto";
str[15] ^= 0x80;
printf("%s",str);
}
Run Code Online (Sandbox Code Playgroud)
我得到的输出为:anto.现在我的脑子里有点罢了,改变一点不会改变输出?