我有两个模型,Item和ShopSection.他们有多对多的关系.
@Entity(name = "item")
public class Item extends Model
{
@ManyToMany(cascade = CascadeType.PERSIST)
public Set<ShopSection> sections;
}
@Entity(name = "shop_section")
public class ShopSection extends Model
{
public List<Item> findActiveItems(int page, int length)
{
return Item.find("select distinct i from Item i join i.sections as s where s.id = ?", id).fetch(page, length);
}
}
Run Code Online (Sandbox Code Playgroud)
findActiveItems
是为了找到一个部分中的项目,但我收到此错误:
org.hibernate.hql.ast.QuerySyntaxException: Item is not mapped [select distinct i from Item i join i.sections as s where s.id = ?]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:111)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
at …
Run Code Online (Sandbox Code Playgroud) 对于简单的getter/setter,如下所示,记录它的最佳方法是什么?
public float getPrice()
{
return price;
}
Run Code Online (Sandbox Code Playgroud)
我对编码标准非常严格,因此我的IDE会警告我任何未记录的公共/受保护方法.
选项1:
/**
* Get the price field.
*
* @return
*/
Run Code Online (Sandbox Code Playgroud)
选项2:
/**
* @return Price
*/
Run Code Online (Sandbox Code Playgroud)
或者根本不记录?
因此,我正在观看Google的Marissa Mayer关于加速谷歌网页的演讲.他们发现购物车图标的加载时间增加了2%,然后用户搜索量减少了2%.他们设法用HTML表替换图标.
这是我尝试绘制购物车:( 实时示例页面)
<html>
<head>
<style>
table {border-collapse: collapse;}
th, td {width: 8px; height: 8px;}
th {background-color: blue;}
td {background-color: white;}
</style>
</head>
<body>
<table>
<!-- this row is just to see alignment -->
<tr>
<td></td><td></td><td></td><td></td><td></td>
<td></td><td></td><td></td><td></td><td></td>
<td></td><td></td><td></td><td></td><td></td>
<td></td><td></td><td></td><td></td><td></td>
</tr>
<!-- handle -->
<tr>
<td colspan="14"></td>
<th colspan="3"></th>
<td colspan="3"></td>
</tr>
<tr>
<td colspan="13"></td>
<th colspan="2"></th>
<td colspan="1"></td>
<th colspan="2"></th>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="13"></td>
<th colspan="2"></th>
<td colspan="1"></td>
<th colspan="2"></th>
<td colspan="2"></td>
</tr>
<tr> …
Run Code Online (Sandbox Code Playgroud) 我有一个尝试创建的方法AudioRecord
.不同的手机支持不同的采样率,通道配置和音频格式.因此,该方法尝试AudioRecord
为每个方法创建一个并返回第一个有效的方法.
private AudioRecord getAudioRecord() {
for (int rate: sampleRates) {
for (int audioFormat: audioFormats) {
for (int channelConfig: channelConfigs) {
String description = rate + "Hz, bits: " + audioFormat
+ ", channel: " + channelConfig;
Log.d(TAG, "Trying: " + description);
int bufferSize = AudioRecord.getMinBufferSize(rate, channelConfig, audioFormat);
if (bufferSize == AudioRecord.ERROR
|| bufferSize == AudioRecord.ERROR_BAD_VALUE) {
Log.d(TAG, "Failed: This rate/channel config/format is not supported");
continue;
}
AudioRecord recorder = new AudioRecord(AudioSource.MIC, rate, channelConfig, audioFormat, bufferSize);
if …
Run Code Online (Sandbox Code Playgroud) 关于命名命名空间类,我正在寻找意见或者是否有商定的方法.
例如:
com.facebook.FacebookClient
vs
com.facebook.Client
Run Code Online (Sandbox Code Playgroud)
要么
javax.script.ScriptEngine;
vs
javax.script.Engine;
Run Code Online (Sandbox Code Playgroud)
我现在更喜欢每个例子中的第一个名字,但额外的词似乎有点浪费.
我有这个Java枚举:
public enum Commands
{
RESIZE_WINDOW("size -size"),
CREATE_CHARACTER("create-char -name"),
NEW_SCENE("scene -image"),
DIALOG("d -who -words"),
PLAY_SOUND("sound -file --blocking=false"),
FADE_TO("fade-to -file"),
WAIT("w -length=auto");
}
Run Code Online (Sandbox Code Playgroud)
我希望能够解析这些字符串并提取:
create-char
)-name
)--blocking=false
)我看了一下org.apache.commons.cli
,但是在第一个标准(不同的命令名称)上似乎失败了并且非常冗长.
任何图书馆建议?
(如果上下文有帮助,这将用于解析脚本"语言".)
编辑:脚本语言中的示例输入是d John "Hello World"
- 多字文本用引号括起来.
在我看来,如果UTF-8是唯一的编码使用,随处可见不断,会有用的代码少了很多问题:
<meta>
在执行任何操作之前无需等待指定编码的标记.StackOverflow甚至没有元标记,使浏览器首先下载整页,减慢页面渲染速度.?
在旧网页上看到和其他随机符号(例如代替Microsoft Word的特殊[读:可怕]引号).那么为什么不能从太空中扼杀劣质编码呢?
我有一个程序,每秒拍摄一次屏幕截图并计算屏幕的平均颜色.但是,经过约45分钟的跑步,我的支票
if ((OffscrBmp = CreateCompatibleBitmap(bitmapDC, nScreenWith, nScreenHeight)) == NULL)
开始回来了true
.一个GetLastError()
回复的电话6
,虽然我似乎无法找到任何关于这意味着什么的文件.
为什么数千次调用此函数的工作正常,然后突然每次调用失败?
这是我的整个功能:
COLORREF ScreenColourCapture::getScreenColour() {
// Most of this is adapted from http://www.cplusplus.com/forum/beginner/25138/
LPBITMAPINFO lpbi = NULL;
HBITMAP OffscrBmp = NULL;
HDC OffscrDC = NULL;
int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
HDC bitmapDC = CreateCompatibleDC(0);
HBITMAP hBmp = CreateCompatibleBitmap(GetDC(0), nScreenWidth, nScreenHeight);
SelectObject(bitmapDC, hBmp);
BitBlt(bitmapDC, 0, 0, nScreenWidth, nScreenHeight, GetDC(0), 0, 0, SRCCOPY);
if ((OffscrBmp = CreateCompatibleBitmap(bitmapDC, nScreenWidth, nScreenHeight)) == NULL) {
int …
Run Code Online (Sandbox Code Playgroud) 我想要equals()
更好地理解这个方法.我见过的所有例子都是这样的:
public class City
{
public boolean equals(Object other)
{
if (other instanceof City && other.getId().equals(this.id))
{
return true;
}
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
该方法必须采用对象而不是城市吗?
例如下面不允许这个?
public class City
{
public boolean equals(City other)
{
if (other == null)
{
return false;
}
return this.id.equals(other.getId());
}
}
Run Code Online (Sandbox Code Playgroud) 我必须在数据库中存储数百万个URL,并能够快速通过URL查找行.
MySQL的字符串索引不够快,因为它们只索引字符串的前4个字符,这通常是www.
,然后MySQL迭代每个行开头www.
并将值与我搜索的URL进行比较.
MongoDB不允许您自定义为字符串索引的字符数,并且文档不是很详细,所以我不认为MongoDB是合适的.
Google App Engine有一种特殊的网址类型,很棒,但我不能使用GAE.
有什么建议?
java ×4
android ×1
c++ ×1
coding-style ×1
command-line ×1
database ×1
drawing ×1
encoding ×1
equals ×1
hibernate ×1
html ×1
html-table ×1
indexing ×1
javadoc ×1
jpa ×1
many-to-many ×1
namespaces ×1
nosql ×1
performance ×1
utf-8 ×1
winapi ×1