我有下一张桌子.groups表包含按层次排序的组和group_member,用于存储用户所属的组.
groups
---------
id
parent_id
name
group_member
---------
id
group_id
user_id
ID PARENT_ID NAME
---------------------------
1 NULL Cerebra
2 1 CATS
3 2 CATS 2.0
4 1 Cerepedia
5 4 Cerepedia 2.0
6 1 CMS
ID GROUP_ID USER_ID
---------------------------
1 1 3
2 1 4
3 1 5
4 2 7
5 2 6
6 4 6
7 5 12
8 4 9
9 1 10
Run Code Online (Sandbox Code Playgroud)
我想检索给定用户的可见组.这就是说用户属于的组和这些组的子组.例如,使用以上数据:
USER VISIBLE_GROUPS
9 4, 5
3 1,2,4,5,6
12 5 …Run Code Online (Sandbox Code Playgroud) 我想验证一个字符串,它可以是一封电子邮件或多个用逗号分隔的电子邮件.
例如:
bill.gates@hotmail.com - > TRUE
bill - > FALSE
bill.gates @ microsoft.com,steve.jobs @ apple.com" - > TRUE
bill.gates @ microsoft.com,steve.jobs @ apple.com,bob " - > false
bob,bill.gates @ microsoft.com,steve.jobs @ apple.com" - > false
我推出了下一个与测试用例一起使用的代码.
function validateEmail(field) {
var regex=/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i;
return (regex.test(field)) ? true : false;
}
function validateMultipleEmailsCommaSeparated(value) {
var result = value.split(",");
for(var i = 0;i < result.length;i++)
if(!validateEmail(result[i]))
return false;
return true;
}
Run Code Online (Sandbox Code Playgroud)
这是最快捷的方式吗?如果我想允许怎么办 并且,作为分隔符?
我想用Ant生成我的数据库模式.我正在使用hbm2ddl任务.
我正在使用Hibernate和JNDI.我的hibernate.cfg.xml看起来像:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.datasource">java:comp/env/jdbc/my_app</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<!-- Mapping -->
</session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)
我的$ CATALINA_HOME/webapps/myapp/META-INF/context.xml如下所示:
<Context>
<Resource name="jdbc/my_app"
global="jdbc/my_app"
auth="Container"
type="javax.sql.DataSource"
username="userA"
password="userA123"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/myapp?autoReconnect=true"
maxActive="8"
maxIdle="4"/>
</Context>
Run Code Online (Sandbox Code Playgroud)
在$ CATALINA_HOME/webapps/myapp/WEB-INF/web.xml里面我有:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/my_app</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Run Code Online (Sandbox Code Playgroud)
在build.xml中我有下一个目标.
<target name="schema" description="Generate DB schema from the O/R mapping files">
<hibernatetool destdir="${basedir}">
<classpath path="${java.src.home}">
<fileset dir="${java.src.home}">
<include name="**/*.hbm.xml"/>
</fileset>
</classpath>
<configuration configurationfile="${java.src.home}/hibernate.cfg.xml"/>
<hbm2ddl
drop="true"
create="true" …Run Code Online (Sandbox Code Playgroud) 可以用java执行linux命令吗?我正在尝试创建一个Web servlet,以允许ftp用户在没有ssh登录访问权限的情况下更改其密码.我想执行下一个命令:
# adduser -s /sbin/nologin clientA -d /home/mainclient/clientA
# passwd clientA
# cd /home/mainclient; chgrp -R mainclient clientA
# cd /home/mainclient/clientA; chmod 770 .
Run Code Online (Sandbox Code Playgroud) 就像是?
<fmt:formatDate value="${event.starttime}" type="both"/>
Run Code Online (Sandbox Code Playgroud) 我有三个表tag,page,pagetag
有了下面的数据
页
ID NAME
1 page 1
2 page 2
3 page 3
4 page 4
Run Code Online (Sandbox Code Playgroud)
标签
ID NAME
1 tag 1
2 tag 2
3 tag 3
4 tag 4
Run Code Online (Sandbox Code Playgroud)
pagetag
ID PAGEID TAGID
1 2 1
2 2 3
3 3 4
4 1 1
5 1 2
6 1 3
Run Code Online (Sandbox Code Playgroud)
我想在单个查询中获取一个字符串,其中包含每个页面的对应标记名称.这是我想要的输出.
ID NAME TAGS
1 page 1 tag 1, tag 2, tag 3
2 page 2 tag 1, tag 3
3 …Run Code Online (Sandbox Code Playgroud) 我有下一个功能:
function setImagesWidth(id,width) {
var images = document.getElementById(id).getElementsByTagName("img");
for(var i = 0; i < images.length;i++) {
// If the real width is bigger than width parameter
images[i].style.width=width;
//}
}
}
Run Code Online (Sandbox Code Playgroud)
我想只在图像实际宽度大于属性值时才将所有img标签的css width属性设置为特定值.如果可能的话,我想要一个不使用任何特定框架的解决方案.
images[i].offsetWidth对于109px宽度的图像返回111.这是因为每边边界1px?
我正在使用FORM身份验证和Realm.我想知道如何退出.
到目前为止,唯一的解决方案是关闭浏览器,但从可用性的角度来看,这是不可接受的.
我正在尝试使用spock where block运行Grails 3服务集成测试.但是,我得到一个空指针异常(见下文).如果我将它作为一个连续的/当块运行它.知道我错过了什么吗?
@Integration
@Rollback
class PersistenceAutoCompleteTermServiceIntegrationSpec extends Specification {
def setup() {
}
def cleanup() {
}
@Autowired
PersistenceAutoCompleteTermService persistenceAutoCompleteTermService
@Unroll
void "fetchAllLikeTerm tests"() {
setup:
new PersistenceAutoCompleteTerm(name: 'Milkshake').save()
new PersistenceAutoCompleteTerm(name: 'Oat Milk').save()
new PersistenceAutoCompleteTerm(name: 'Special K').save()
when:
List<String> names = persistenceAutoCompleteTermService.fetchAllLikeTerm(term)
then:
names.size() == expected_result
where:
term | expected_result
"Milk" | 2
"milk" | 2
}
}
Run Code Online (Sandbox Code Playgroud)
失败了
java.lang.NullPointerException
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
at grails.transaction.GrailsTransactionTemplate.executeAndRollback(GrailsTransactionTemplate.groovy:64)
at com.shoptimix.api.persistence.PersistenceAutoCompleteTermServiceIntegrationSpec.fetchAllLikeTerm tests(PersistenceAutoCompleteTermServiceIntegrationSpec.groovy)
Run Code Online (Sandbox Code Playgroud)
但是这有效:
@Unroll
void "fetchAllLikeTerm tests"() {
setup:
new PersistenceAutoCompleteTerm(name: 'Milkshake').save()
new …Run Code Online (Sandbox Code Playgroud)