我正在尝试在电子邮件中添加Twitter共享链接.因为这是在电子邮件中我不能依赖JavaScript,并且必须使用"Build Your Own"Tweet按钮.
例如,分享指向Google的链接:
<a href="http://www.twitter.com/share?url=http://www.google.com/>Tweet</a>
Run Code Online (Sandbox Code Playgroud)
这很好用.我遇到的问题是URL有查询字符串.
<a href="http://www.twitter.com/share?url=http://mysite.org/foo.htm?bar=123&baz=456">Tweet</a>
Run Code Online (Sandbox Code Playgroud)
带有查询字符串的网址混淆了Twitter的网址缩短服务,t.co. 我已经尝试过以各种方式对此进行URL编码,并且无法正常工作.我得到的最接近的是这样做.
<a href="http://www.twitter.com/share?url=http://mysite.org/foo.htm%3Fbar%3D123%26baz%3D456">Tweet</a>
Run Code Online (Sandbox Code Playgroud)
这里我只编码了查询字符串.当我这样做时,t.co成功地缩短了URL,但是在遵循缩短的链接时,它会将您带到编码的URL.我http://mysite.org/foo.htm%3Fbar%3D123%26baz%3D456在地址栏中看到,并在浏览器中收到以下错误
未找到
在此服务器上找不到请求的URL /foo.htm?bar=123&baz=456.
我不知道如何解决这个问题.
编辑: Re:onteria_
我试过编码整个网址.当我这样做时,Tweet中没有显示任何URL.
情况:
现在我们有三种不同的状态.HEAD的状态,索引的状态和工作树的状态.撤消工作树中的更改以使其与索引的状态匹配的命令是什么?
我想将微数据添加到页面,但项目的数据被分解为页面的几个不连续部分.如果我有两个span带有itemscope属性的元素,是否可以让搜索引擎合并两个项目范围并将它们解释为单个项目?
例如*:
<span itemscope itemtype="http://schema.org/Person">
Hello, my name is <span itemprop="name">Glinda</span>.
</span>
I like to fly around in a giant bubble.
<span itemscope itemtype="http://schema.org/Person">
I live in the <span itemprop="location">Land of Oz</span>.
</span>
Run Code Online (Sandbox Code Playgroud)
有没有办法添加类似itemid属性的东西来告诉网络蜘蛛这两个人itemscopes应该作为一个项目而不是两个消费?
也许这样的事情.
<span itemscope itemtype="http://schema.org/Person" itemid="7f6ba1">
Hello, my name is <span itemprop="name">Glinda</span>.
</span>
I like to fly around in a giant bubble.
<span itemscope itemtype="http://schema.org/Person" itemid="7f6ba1">
I live in the <span itemprop="location">Land of Oz</span>.
</span>
Run Code Online (Sandbox Code Playgroud)
*我理解在这个例子中我可以使用一个大跨度,但我不能用我必须使用的实际页面来做到这一点.
编辑:也许我需要一个更好的例子.它有点做作,但证明了我的问题.请记住,重新组织页面不是一种选择.
<h1>Locations</h1> …Run Code Online (Sandbox Code Playgroud) 有一个Grails域对象,它有一个自定义静态函数来从数据库中获取数据
class Foo {
/* member variables, mapping, constraints, etc. */
static findByCustomCriteria(someParameter, List listParameter) {
/* code to get stuff from the database... */
/*
Return value is a map
["one": "uno", "two": "due", "three": "tre"]
*/
}
}
Run Code Online (Sandbox Code Playgroud)
静态函数findByCustomCriteria用于createCriteria()构建从Foo表中提取数据的查询,这意味着mockDomain(Foo)在单元测试时无法正常工作.我正在尝试解决这个问题的方法是使用模拟的通用方法之一进行模拟findByCustomCriteria,但我无法正确理解语法.
我有一个控制器BarController,我正在尝试测试,并埋在呼叫中BarController.someFunction()有一个呼叫Foo.findByCustomCriteria().
class BarControllerTest extends ControllerUnitTestCase {
protected void setUp() {
super.setUp()
}
protected void tearDown() {
super.tearDown()
}
void testSomeFunction() {
/* Mocking for Foo …Run Code Online (Sandbox Code Playgroud) 我有以下功能
var redirect = function() {
window.location.href = "http://www.google.com";
}
Run Code Online (Sandbox Code Playgroud)
我想用qUnit测试这个函数.
问题是,当我调用运行测试的HTML文档时,一旦进入调用测试,redirect()浏览器就会加载google.com.我想做的是以某种方式模拟window.location.href,以便它不重定向,因此我可以检查它是否设置为正确的值.
以一种更可测试的方式重写它将是一个可接受的答案,并受到欢迎.由于我使用的是qUnit,因此一些jQuery魔法是合适的,就像一些老式的重构一样.建议为window.location.href添加自定义setter,但我无法弄清楚如何使其工作.
请不要改变我的代码行为的建议.
我有一个看起来像这样的数据库行.
ID (int): 123
Name (string): SomeName
Data (string): <data><foo>one</foo></bar>two</bar></data>
Run Code Online (Sandbox Code Playgroud)
我需要以下列方式将此数据格式化为XML.
<row>
<id>123</id>
<name>SomeName</name>
<data>
<foo>one</foo>
<bar>two</bar>
</data>
<row>
Run Code Online (Sandbox Code Playgroud)
我目前正在使用SimpleXML来尝试构建它,但我不确定如何将现有的XML插入到我正在尝试构建的新XML文档中.
如果PHP附带其他标准XML构建器,我也愿意使用它们. 字符串连接不是可接受的答案.
编辑:看起来好像SimpleXML不会做我需要的.我想在这一点上,我需要其他XML解析器的建议.
我有三个域类:Beer,Review和Reviewer.
我希望Review表在Beer和Reviewer之间创建多对多关系,因此我希望Review的主键是Beer和Reviewer的id字段的组合.我正在关注这个Grails文档.
这是我的域类.
class Beer {
String name
String type
Brewery breweryId
static hasMany = [ reviews : Review ]
static constraints = {
}
}
class Reviewer {
String screenName
static hasMany = [ reviews : Review ]
static constraints = {
}
}
class Review implements Serializable {
int score
Beer beer
Reviewer reviewer
static constraints = {
}
static mapping = {
id composite:['beer', 'reviewer']
}
}
Run Code Online (Sandbox Code Playgroud)
我得到了编译错误,但是stackoverflow上的另一个答案说我需要添加implements Serializable.这样可以解决错误,但是当我查看数据库时,我仍然没有得到复合主键.
以下是我在查看表定义时所看到的内容.我正在使用Postgres.
Table "public.review"
Column | …Run Code Online (Sandbox Code Playgroud) 根据文档,您应该能够将 javabean 传递给 FreeMarker 模板,并且它将能够访问 bean 的 getter。我一直在尝试这样做,但没有任何运气。这是我将 bean 传递给模板的代码。
public class Hello extends HttpServlet {
public static final Logger LOGGER = Logger.getLogger(Hello.class.getName());
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
Configuration cfg = new Configuration();
cfg.setDirectoryForTemplateLoading(new File(this.getServletContext().getRealPath("/templates")));
cfg.setObjectWrapper(new DefaultObjectWrapper());
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
cfg.setIncompatibleImprovements(new Version(2, 3, 20)); // FreeMarker 2.3.20
final String name = req.getParameter("name");
// This works when model is a Map, but not when it is a bean
Model model = new Model();
model.setUsername(name); …Run Code Online (Sandbox Code Playgroud) 用于创建自己的令牌和字符过滤器的Solr文档说明如下.
http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters#Specifying_an_Analyzer_in_the_schema
如果你想使用自定义CharFilters,Tokenizers或TokenFilters,你需要编写一个非常简单的工厂,它的子类是BaseTokenizerFactory或BaseTokenFilterFactory,就像这样......
public class MyCustomFilterFactory extends BaseTokenFilterFactory {
public TokenStream create(TokenStream input) {
return new MyCustomFilter(input);
}
}
Run Code Online (Sandbox Code Playgroud)
我在Solr 4的源代码中找不到BaseTokenFilterFactory.
这是Solr 3.6.1中的org.apache.solr.analysis包
这是Solr 4.0.0的相同包
文档似乎适用于Solr 3.6,但我需要知道如何使用4.0创建自定义过滤器.
grails ×2
mocking ×2
unit-testing ×2
freemarker ×1
git ×1
grails-orm ×1
groovy ×1
html5 ×1
indexing ×1
javabeans ×1
jquery ×1
microdata ×1
php ×1
query-string ×1
qunit ×1
seo ×1
share ×1
simplexml ×1
solr ×1
templates ×1
testing ×1
twitter ×1
url-encoding ×1
xml ×1