在我的DAO层中,我有一个像这样的Find函数
public List<?> findCategoryWithSentenceNumber(int offset, int maxRec) {
Criteria crit = getSession().createCriteria(Category.class, "cate");
crit.createAlias("cate.sentences", "sent");
crit.setProjection(Projections.projectionList().
add(Projections.property("title"), "title").
add(Projections.count("sent.id"), "numberOfSentence").
add(Projections.groupProperty("title"))
);
crit.setFirstResult(offset);
crit.setMaxResults(maxRec);
return crit.list();
}
Run Code Online (Sandbox Code Playgroud)
所以,为了读取数据,我必须使用一个循环(带Iterator
)
List<?> result = categoryDAO.findCategoryWithSentenceNumber(0, 10);
// List<DQCategoryDTO> dtoList = new ArrayList<>();
for (Iterator<?> it = result.iterator(); it.hasNext(); ) {
Object[] myResult = (Object[]) it.next();
String title = (String) myResult[0];
Long count = (Long) myResult[1];
assertEquals("test", title);
assertEquals(1, count.intValue());
// dQCategoryDTO = new DQCategoryDTO();
// dQCategoryDTO.setTitle(title);
// dQCategoryDTO.setNumberOfSentence(count);
// dtoList.add(dQCategoryDTO);
} …
Run Code Online (Sandbox Code Playgroud) 我想知道Logcat Output Format
在Android DDMS中改变哪种方式.我在MAC上使用Android Studio 0.4.2.我知道我可以从终端自定义格式,但我还需要在Android DDMS Monitor工具中执行此操作.
在我的页面上,我需要显示帖子详细信息和评论表单以供查看者发表评论.我创建了2个通用视图:
# views.py
class PostDetailView (DetailView):
model = Post
context_object_name = 'post'
template_name = 'post.html'
def get_context_data(self, **kwargs):
context = super(PostDetailView, self).get_context_data(**kwargs)
context['comment_form'] = CommentForm()
return context
class AddCommentView(FormView):
template_name = 'post.html'
form_class = CommentForm
success_url = '/'
def form_valid(self, form):
form.save()
return super(AddCommentView, self).form_valid(form)
def form_invalid(self, form):
return self.render_to_response(self.get_context_data(form=form))
detail = PostDetailView.as_view()
add_comment = AddCommentView.as_view()
# urls.py
....
url(r'^(?P<pk>\d+)/$', view='detail'),
url(r'^(?P<post_id>\d+)/add_comment/$', view='add_comment'),
....
Run Code Online (Sandbox Code Playgroud)
AddCommentView会出现错误,因为我没有为评论指定帖子的ID.如何在AddCommentView中访问post_id?
我附加了一个对话框组件作为指令,以便在我点击主页面上的按钮(链接到主要组件)时在主组件页面上显示它.这就是我做到的
在模板中
<button id="goToTasksCases" class="btn btn-success btn-lg" (click)="doShowStartNewCase($event)">START A NEW CASE</button>
<modal-new-case></modal-new-case>
Run Code Online (Sandbox Code Playgroud)
在组件中
@Component({
selector: 'case-index'
})
@View({
templateUrl: 'client/app/case/case.index.html',
directives : [ModalNewCaseComponent]
})
export class CaseIndexComponent {
doShowStartNewCase(event: any) {
// how can I access the ModalNewCaseComponent
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我需要在ModalNewCaseComponent
Rest服务的一些回调之后为子组件()设置一些值.如何通过当前设置实现这一目标?
CRUD模块无法在play框架中转换有意义的类名.例如,如果我有一个Category模型,然后在控制器文件夹中创建一个Categories类来扩展CRUD,则类别链接将不会出现在admin部分中.但是,如果我将文件重命名为"Categorys",它将起作用.这个小问题有什么解决方案吗?因为我曾经和CakePhp一起玩,所以它适用于所有名称约定
我正在为我的项目编写代码覆盖率并遇到奇怪的行为。我有这样的功能
public void testException(int i) throws Exception {
if (i == 0) {
throw new Exception("exception");
}
}
Run Code Online (Sandbox Code Playgroud)
和测试用例
@Test
public void testException() {
try {
mapper.testException(0);
fail("Wrong");
} catch (Exception ex) {
assertEquals("exception", ex.getMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
通过maven()运行测试用例后mvn sonar:sonar
,该分支将被Sonar覆盖。但是,如果测试的函数是这样的
public void testException(int i) throws Exception {
if (i == 0) {
throwException();
}
}
public void throwException() throws Exception {
throw new Exception("exception");
}
Run Code Online (Sandbox Code Playgroud)
那么if
虽然函数的内部throwException
实际上被执行了,但分支没有被覆盖。有办法克服这个问题吗?我需要 100% 完成全班课程
我google了很多,但找不到任何解决这个简单问题的方法.我唯一能想到的就是for loop
用一个图像反复覆盖整个屏幕,但这种方式完全是疯了.谁能给我一个好的方向呢?
我正在通过此链接的示例源代码学习网络编程http://cs.baylor.edu/~donahoo/practical/CSockets/textcode.html.在编译期间,只是想知道为什么在Solaris环境中,我必须手动链接make文件中的socket和nsl库,但是当在linux机器中时,我不需要这样做吗?
我试图在Active Directory上搜索组织单元(Window Server 2003).这是我的代码
package com.test;
import java.io.IOException;
import java.util.Properties;
import javax.naming.CompositeName;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.Control;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import javax.naming.ldap.PagedResultsControl;
public class Main {
Properties ENV = new Properties();
private DirContext CTX;
private static final String BIN_ENV = "java.naming.ldap.attributes.binary";
private static final String CTX_CLASS = "com.sun.jndi.ldap.LdapCtxFactory";
String host = "127.0.0.1";
String port = "389";
String OU = "OU=b#,DC=domain,DC=local";
public int getConnection() {
int result = 0;
ENV.clear();
String …
Run Code Online (Sandbox Code Playgroud) 我无法找到正确的方法,以便从列表视图行下的基于类的定义中触发事件.这是我到目前为止所做的
class SampleApp extends React.Component {
constructor(props){
super(props)
this.state = {
dataSource: ds.cloneWithRows(this._partners()),
}
// this._click = this._click.bind(this);
}
_click() {
console.log('clicked');
}
_renderRow(rowData) {
return (<TouchableHighlight onPress={() => {this._click();}}>
<Text style={{ fontSize:18 }}>{rowData}</Text>
</TouchableHighlight>);
}
render() {
console.log('Partners: ', this._partners() )
return (
<View style={styles.container}>
<ListView
dataSource={this.state.dataSource}
renderRow={ this._renderRow } />
</View>
);
}
}
Run Code Online (Sandbox Code Playgroud)
this
里面onPress
没有提到反应成分.我该如何解决?这是反应游乐场链接https://rnplay.org/apps/Xd-l3w
我有一个小问题,但无法弄清楚为什么.在我的django shell上:
In [2]: Post.objects.dates('created', 'month')
Out[2]: [datetime.datetime(2012, 5, 1, 0, 0, tzinfo=<UTC>)]
Run Code Online (Sandbox Code Playgroud)
但是在我的模板上
{% for d in dates %}
<li><a href="#">{{ d|date:"m Y"}}</a></li>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
它给出了"04 2012"而不是"05 2012".我错过了什么 ?