我在bash脚本中有以下三个结构:
NUMOFLINES=$(wc -l $JAVA_TAGS_FILE)
echo $NUMOFLINES" lines"
echo $(wc -l $JAVA_TAGS_FILE)" lines"
echo "$(wc -l $JAVA_TAGS_FILE) lines"
Run Code Online (Sandbox Code Playgroud)
并且在脚本运行时它们都产生相同的输出:
121711 /home/slash/.java_base.tag lines
121711 /home/slash/.java_base.tag lines
121711 /home/slash/.java_base.tag lines
Run Code Online (Sandbox Code Playgroud)
即文件名也被回显(我不想这样).为什么这些scriplet会失败,我应该如何输出干净:
121711 lines
Run Code Online (Sandbox Code Playgroud)
?
我使用RESTEasy JAX-RS实现将Web服务组件部署到JBoss Application Server 7.
是否有注释可用于在JAX-RS中声明必需的@QueryParam参数?而且,如果没有,那么处理缺少这些参数的情况的"标准"方法是什么?
当使用所有必需参数正确调用时,我的Web服务(资源)方法返回JSON字符串化结果,但我不确定向调用者指示缺少必需参数的最佳方法是什么.
据我所知,React教程和文档毫不含糊地警告说,状态不应该直接变异,并且一切都应该通过setState.
我想明白为什么,确切地说,我不能直接改变状态,然后(在同一个函数中)调用this.setState({})只是为了触发render.
例如:以下代码似乎工作得很好:
const React = require('react');
const App = React.createClass({
getInitialState: function() {
return {
some: {
rather: {
deeply: {
embedded: {
stuff: 1
}}}}};
},
updateCounter: function () {
this.state.some.rather.deeply.embedded.stuff++;
this.setState({}); // just to trigger the render ...
},
render: function() {
return (
<div>
Counter value: {this.state.some.rather.deeply.embedded.stuff}
<br></br>
<button onClick={this.updateCounter}>inc</button>
</div>
);
}
});
export default App;
Run Code Online (Sandbox Code Playgroud)
我完全遵循以下约定,但我想进一步了解ReactJS如何实际运行,哪些可能出错或者是否与上述代码不是最佳的.
this.setState文档下的注释基本上确定了两个陷阱:
this.setState它可能会替换(覆盖?)你所做的突变.我不知道在上面的代码中会发生这种情况.setState …有没有办法查询JPA EntityManager是否分离给定的实体?这篇SO帖子正在讨论一个类似的问题,但没有说明在实体的分离状态下查询JPA EntityManager的方法.我更喜欢JPA方式,否则特定于Hibernate.
是否存在以下行为的逻辑语言设计类型解释(Java 7和我怀疑早期版本):
Object a = null;
String as = String.valueOf(a); // as is assigned "null"
System.out.println(as+":"+as.length()); // prints: "null:4"
System.out.println ( String.valueOf(null)); // NPE
Run Code Online (Sandbox Code Playgroud) 我正在将JAX-RS Web服务部署到Tomcat servlet容器.
我见过代码示例,它们使用以下两种方法之一来指示web.xml文件中的资源:
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.example</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Run Code Online (Sandbox Code Playgroud)
...期望资源驻留在com.example包中,我想通过Java RTTI发现.
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>full.qualified.name.to.MyApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Run Code Online (Sandbox Code Playgroud)
... MyApplication类明确标识资源类:
public class MyApplication extends javax.ws.rs.core.Application {
public Set<Class<?>> getClasses() {
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(ResourceA.class);
return s;
}
Run Code Online (Sandbox Code Playgroud)
使用单一方法与其他方法纯粹是品味和配置工作的问题,需要考虑哪些权衡取舍?就个人而言,我更喜欢方法2提供的更细粒度的控制,但是maven Jersey 2.7原型:
mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-webapp \
-DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \
-DgroupId=com.example -DartifactId=simple-service-webapp -Dpackage=com.example \
-DarchetypeVersion=2.7
Run Code Online (Sandbox Code Playgroud)
......正在使用方法1,这让我思考.
我看到一些XSD架构文档在其顶部元素中声明了a targetNamespace和xmlns:tns属性schema.例如下面的一个从这里开始.它们似乎也具有相同的字符串值.我理解的角色,targetNamespace但最重要的是xmlns:tns做什么?
<?xml version="1.0" encoding="UTF-8"?>
<schema
xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/Product"
xmlns:tns="http://www.example.org/Product"
elementFormDefault="qualified">
...
Run Code Online (Sandbox Code Playgroud) 我遇到过这种奇怪的事情:
ReferenceError: regeneratorRuntime is not defined
...我设法在一个非常小的环境中重现(与同一问题上类似的SO问题相比),并且还注意到一些奇怪的行为取决于是否使用了范围.
以下代码有效:
'use strict';
require('babel-polyfill');
{ // scope A (if you remove it you observe different behavior when .babelrc is present)
function *simplestIterator() {
yield 42;
}
for (let v of simplestIterator()) {
console.log(v);
}
}
Run Code Online (Sandbox Code Playgroud)
包裹是:
$ npm ls --depth 0
simple-babel-serverside-node-only-archetype@1.0.0 /home/mperdikeas/regeneratorRuntimeNotDefined
??? babel-cli@6.7.5
??? babel-core@6.7.6
??? babel-polyfill@6.7.4
??? babel-preset-es2016@6.0.11
??? babel-runtime@6.6.1
Run Code Online (Sandbox Code Playgroud)
内容.babelrc是:
$ cat .babelrc
{
"presets": ["es2016"]
}
Run Code Online (Sandbox Code Playgroud)
但是,当移除范围并将其simplestIterator置于全局范围时,它将失败并显示:
ReferenceError: regeneratorRuntime is not defined
Run Code Online (Sandbox Code Playgroud)
更奇怪的是,如果.babelrc …
我正在尝试JAXBContext类中的各种形式的newInstance方法(我使用的是Oracle JDK 1.7附带的默认Sun JAXB实现).
我不清楚只需将具体类与ObjectFactory类传递给newInstance方法即可.我应该注意到,我纯粹使用JAXB来解析XML文件,即仅在XML-> Java方向.
这是绝对最小的代码,它证明了我的观点:
<?xml version="1.0" encoding="UTF-8"?>
<schema elementFormDefault="qualified"
xmlns ="http://www.w3.org/2001/XMLSchema"
xmlns:a ="http://www.example.org/A"
targetNamespace="http://www.example.org/A">
<element name="root" type="a:RootType"></element>
<complexType name="RootType">
<sequence>
<element name="value" type="string"></element>
</sequence>
</complexType>
</schema>
Run Code Online (Sandbox Code Playgroud)
鉴于上述XSD,以下JAXBInstance.newInstance调用成功创建了一个可解析样本a.xml文件的上下文:
但是,在运行时单独传递example.a.RootType.class失败并出现javax.xml.bind.UnmarshalException:
jc = JAXBContext.newInstance(example.a.RootType.class); // this fails at runtime.
Run Code Online (Sandbox Code Playgroud)
任何人都能解释一下吗?我正在试验这些JAXBContext :: newInstance变体的原因是我偶然发现了这个问题,其中接受的答案包括"基于个别类而不是对象工厂构建JAXB上下文"的选项.我正在使用的示例a.xml和JAXB Java代码在帖子的末尾跟随.
<?xml version="1.0" encoding="UTF-8"?> …Run Code Online (Sandbox Code Playgroud) 我正在使用xmllint进行一些验证,我有一个XML实例文档需要针对两个模式进行验证:一个用于外部"信封"(包括任何元素),另一个用于特定有效负载.假设A.xsd是信封模式,B.xsd是有效负载模式(有不同的可能有效负载),ab.xml是有效的XML实例文档(我在帖子的末尾提供了一个示例).
我在同一目录中有本地可用的所有三个文件,并使用xmllint执行验证,提供外部(信封)模式的位置作为模式参数:
xmllint -schema A.xsd ab.xml
Run Code Online (Sandbox Code Playgroud)
...但是,虽然我在实例文档中提供了A.xsd和B.xsd的位置(使用xsi:schemaLocation元素)但xmllint无法找到并抱怨:
ab.xml:8: element person: Schemas validity error : Element '{http://www.example.org/B}person': No matching global element declaration available, but demanded by the strict wildcard.
ab.xml fails to validate
Run Code Online (Sandbox Code Playgroud)
显然xmllint没有读取xsi:schemaLocation元素.我知道xmllint可以配置目录,但我没有让xmllint找到两个模式.在验证实例文档时,如何让xmllint考虑两个模式,或者我可以使用另一个命令行实用程序或图形工具?
<?xml version="1.0" encoding="UTF-8"?>
<schema elementFormDefault="qualified"
xmlns ="http://www.w3.org/2001/XMLSchema"
xmlns:a ="http://www.example.org/A"
targetNamespace ="http://www.example.org/A">
<element name="someType" type="a:SomeType"></element>
<complexType …Run Code Online (Sandbox Code Playgroud)