所以我有一个接受泛型类型参数的类,如果type参数是给定类型的子类,则会进行一些特殊处理.
IEnumerable<T> models = ...
// Special handling of MySpecialModel
if (filterString != null && typeof(MySpecialModel).IsAssignableFrom(typeof(T)))
{
var filters = filterString.Split(...);
models =
from m in models.Cast<MySpecialModel>()
where (from t in m.Tags
from f in filters
where t.IndexOf(f, StringComparison.CurrentCultureIgnoreCase) >= 0
select t)
.Any()
select (T)m;
}
Run Code Online (Sandbox Code Playgroud)
但是我在最后一行得到例外
Cannot convert type 'MySpecialModel' to 'T'
Run Code Online (Sandbox Code Playgroud)
如果我更改代码as而不是强制转换,我会收到此错误.
The type parameter 'T' cannot be used with the 'as' operator because it does not have a class type constraint nor a 'class' …Run Code Online (Sandbox Code Playgroud) 1l为long,1f为float,1d为double,字节怎么样?
long l = 1l;
float f = 1f;
double d = 1d;
// byte b = 1?;
Run Code Online (Sandbox Code Playgroud)
什么相当于byte?它存在吗?
Canopy的集成Ipython终端允许使用Emacs键绑定,但集成的代码编辑器不允许.从一个窗口切换到另一个窗口时这是一个问题...有没有办法在"Enthought"Canopy代码编辑器中激活Emacs键绑定?(我在OS X上)
当我尝试在我的文本中放置一些动态部分以供<s:text>Struts 2中的标记使用时,这些部分将被params我定义的替换.
这是我在我的句子中写的方式file.properties:
my_error=The event {0} doesn't exist
Run Code Online (Sandbox Code Playgroud)
这是我尝试显示它的方式:
<s:text name="my_error">
<s:param>Event01</s:param>
</s:text>
Run Code Online (Sandbox Code Playgroud)
但是在结果中,表达式{0}没有被替换,我在日志中没有错误.怎么了?
请告诉我ServletActionContext和之间有什么区别ServletContext?
ServletContext在所有servlet和操作之间共享,而ServletActionContext特定于某个操作还是在所有操作之间共享?
我对我的应用程序进行了轻微更改,并将其检入到subversion存储库中.一旦签入,我运行了Jenkins构建.Jenkins目前正在Windows服务器上运行.
我收到的错误如下:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal
org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (deploy) on project sd-rest-servlet:
Cannot invoke Tomcat manager: FAIL - Deployed application at context path /sd but
context failed to start
Run Code Online (Sandbox Code Playgroud)
我进一步调查了这个错误消息,所以我检查了Jenkins服务器上的Tomcat日志,我发现了一个潜在的问题:
SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Document base C:\Program Files\Apache Software Foundation\Tomcat 6.0\temp\28-sd does not exist or is not a readable directory
at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:142)
at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4320)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4489)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:675)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:601)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1385)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:306)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1389)
at …Run Code Online (Sandbox Code Playgroud) 我在我的django项目中有一个autocomplete_light的工作实现,从一个下拉列表中的cities_light中提取值,这正确地将外键保存到表单提交中的db中的字段.当我重新访问表单时,我希望自动完成文本字段默认为保存的值,理想情况下使用纯文本中的值并使用"X"按钮(就像已经内置的那样).目前,我看到占位符文本和空白文本字段.当我重新访问表单时,表单中的其他已保存值(此处省略)正确默认.我需要在此处添加什么来触发窗口小部件以显示保存的值?这是我的代码:
forms.py
class UserProfileForm(autocomplete_light.GenericModelForm):
location = autocomplete_light.GenericModelChoiceField(
widget=autocomplete_light.ChoiceWidget(
autocomplete='AutocompleteItems',
autocomplete_js_attributes={'placeholder':'City, State, Country',
'minimum_characters': 3})
)
class Meta:
model = UserProfile
fields = ['location']
Run Code Online (Sandbox Code Playgroud)
models.py
class UserProfile(models.Model):
user = models.ForeignKey(
User,
unique=True
)
location = models.ForeignKey(
City,
blank=True,
null=True
)
Run Code Online (Sandbox Code Playgroud)
autocomplete_light_registry.py
class AutocompleteItems(autocomplete_light.AutocompleteGenericBase):
choices = (
City.objects.all(),
)
search_fields = (
('search_names',),
)
autocomplete_light.register(AutocompleteItems)
Run Code Online (Sandbox Code Playgroud) 我遇到了用于Java的Sphinx语音识别库的问题.我用它来获取输入并处理它.我第一次得到输入,它的工作原理.第二次,它在我有机会谈话之前立即回答.在那之后,它继续回答自己.我尝试在每次输入之前分配并在每次输入后解除分配,但这似乎不起作用.我能做什么?
代码:
这是处理输入的方法:
public void getInput() {
if (using) return;
using = true;
if (!allocated) {
JTalk.speak("Please hold.");
recognizer.allocate();
allocated = true;
}
JTalk.speak("Speak now.");
Result result = recognizer.recognize();
if (result != null) {
String resultText = result.getBestFinalResultNoFiller();
JDispatcher.getInstance().matchInput(resultText);
}
else {
JTalk.speak("Try again.");
}
using = false;
}
Run Code Online (Sandbox Code Playgroud)
你需要知道的:
MouseListenerfor a TrayIcon.speak(String)运行say <text>从Runtime.matchInput(String) 迭代数组中所有已注册的侦听器并测试匹配.更新2:
根据Nikolay Shmyrev的回答,我尝试在构造函数中分配麦克风,并在适当的时间启动,然后停止麦克风getInput().
这是SphinxBridge类:
public class SphinxBridge {
private ConfigurationManager cm; …Run Code Online (Sandbox Code Playgroud) 我要在几小时内区分当前日期和存储在数据库中的日期.在PostgreSQL中,我可以使用以下查询来完成它:
SELECT storage_time, extract(epoch from (localtimestamp - storage_time))/3600 as diff_hour FROM some_table;
Run Code Online (Sandbox Code Playgroud)
这给了我以小时为单位的日期差异:
storage_time | diff_hour
-------------------------+-------------------
2014-02-03 19:37:39.481 | 44.4788805811111
2014-02-03 19:40:28.201 | 44.4320139144444
2014-01-29 18:25:12.828 | 165.686284192222
2014-02-03 19:25:56.861 | 44.6740528033333
2014-02-05 15:53:38.178 | 0.212575858888889
2014-01-30 15:53:38.61 | 144.212455858889
Run Code Online (Sandbox Code Playgroud)
现在,我面临着将其移植到Hibernate查询语言的困难.我尝试了很多变化,但我无法从日期差异中获得时代.这肯定不起作用:
"FROM SomeEntity " +
"WHERE someAttribute = :attr " +
"AND epoch(localtimestamp - deviceInfo.storageTime) / 3600 > :threshold_hour";
Run Code Online (Sandbox Code Playgroud)
当我运行此命令时,我得到以下异常:
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:273) …Run Code Online (Sandbox Code Playgroud) 我有一个使用Struts2,Spring和JPA的Web应用程序.在应用程序中,我们正在使用注释.当我们在eclipse中部署应用程序时,如果我们将其部署为虚拟应用程序(右键单击服务器,选择属性,选择WebLogic,选择发布模式),应用程序运行正常.此选项生成_auto_generated_ear文件并运行应用程序. 当我将其部署为展开的归档文件或通过管理控制台手动将应用程序部署为.war文件时,我收到以下错误消息:
[[ACTIVE] ExecuteThread:'8'表示队列:'weblogic.kernel.Default(self-tuning)'] WARN org.apache.struts2.dispatcher.Dispatcher - 找不到操作或结果:/eServices/login.action There没有映射名称空间[/]的动作和与上下文路径[/ eServices]关联的动作名称[登录]. - com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)中的[未知位置]位于org.apache.struts2.impl上的org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63).位于org.apache的org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:552)的com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)中的StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)位于weblogic.servlet.internal.FilterChainImpl.doFilter的org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)中的.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) (FilterChainImpl.java:56)位于oracle.security.jps.util的java.security.AccessController.doPrivileged(Native Method)的oracle.security.jps.ee.http.JpsAbsFilter $ 1.run(JpsAbsFilter.java:111). oracle.security.jps中的JpsSubject.doAsPrivileged(JpsSubject.java:313)位于oracle.security.jps.ee.http.JpsAbsFilter.doFilter的oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:94)中的.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:413) (JpsAbsFilter.java:161)位于oracle.dms的weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)的oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71). servlog.DMSServletFilter.doFilter(DMSServletFilter.java:136)位于weblogic.servome.servial.Web上的weblogic.servlet.inperi.WebAppServletContext $ ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)的weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56) .loglet.internal.WebAppServletContext $ ServletInvocationAction.run(WebAppServletContext.java:3681)at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)at weblogic.security.service.SecurityManager.runAs(SecurityManager.java) :120)at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.jav)a:2277)weblogic.servlet.internal.WebAppServletContext.exe(WebAppServletContext.java:2183)at weblogic.servlet.invine.ServletRequestImpl.run(ServletRequestImpl.java:1454)at weblogic.work.ExecuteThread.execute(ExecuteThread.java) :209)at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)
任何WebLogic专家都能指出我正确的方向吗?在WebLogic中运行的Struts2的Convention-plugin是否存在问题?任何帮助将不胜感激.提前致谢.
更新:
web.xml中
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>eServices</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Needed to manage the Java based @Configuration classes for Spring -->
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.ceiwc.es.config</param-value>
</context-param>
<!-- …Run Code Online (Sandbox Code Playgroud) java ×5
struts2 ×3
casting ×2
.net ×1
byte ×1
c# ×1
canopy ×1
date ×1
django ×1
emacs ×1
enthought ×1
forms ×1
generics ×1
hibernate ×1
hql ×1
jenkins ×1
jquery ×1
jsp ×1
jsp-tags ×1
key-bindings ×1
linq ×1
maven ×1
oracle ×1
postgresql ×1
properties ×1
python ×1
servlets ×1
sphinx4 ×1
tomcat ×1
weblogic ×1