int main()
{
enum Days{Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday};
Days TheDay;
int j = 0;
printf("Please enter the day of the week (0 to 6)\n");
scanf("%d",&j);
TheDay = Days(j);
//how to PRINT THE VALUES stored in TheDay
printf("%s",TheDay); // isnt working
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我偶然发现了NOAA的SOAP服务,它让我思考.政府还向企业和公众提供了哪些其他电子政务服务?我知道美国有很多API,但其他政府如欧盟呢.我不仅对SOAP感兴趣,而且对通过互联网向公众提供的任何远程过程调用(RPC)服务感兴趣.我不仅对数据源感兴趣,还对其他类型的API感兴趣.
我们有一个Java应用程序,它有一些知道读取文本文件的模块.他们非常简单地使用这样的代码:
BufferedReader br = new BufferedReader(new FileReader(file));
String line = null;
while ((line = br.readLine()) != null)
{
... // do stuff to file here
}
Run Code Online (Sandbox Code Playgroud)
我在我的项目上运行PMD并在线路上获得了" AssignmentInOperand "违规while (...)
.
除了显而易见的事情之外,是否有更简单的方法来执行此循环:
String line = br.readLine();
while (line != null)
{
... // do stuff to file here
line = br.readLine();
}
Run Code Online (Sandbox Code Playgroud)
这被认为是更好的做法吗?(虽然我们"复制" line = br.readLine()
代码?)
我是JAX-RS的新手,我正在尝试使用Jersey构建一个简单的RESTful Web服务.
我有两个问题.请澄清这些:
我想尝试像这个URL一样简单的web服务 http://localhost:8080/SampleJersey/rest/inchi/InChIName
InChIName是这样的字符串InChI=1S/C9H8O4/c1-6(10)13-8-5-3-2-4-7(8)9(11)12/h2- 5H,1H3,(H,11,12)
.我如何传递这个@PathParam
,我的意思是一个普通的字符串工作正常,但这里有斜杠,连字符和逗号.如何让它忽略这些.我试着把它放在引号中,但那不起作用.我该怎么做?
我需要将它传递InChI
给另一个webservice并返回一个XML作为输出,我想将该XML输出显示为我的Webservice的输出.如果我有@Produces("application/xml")
它会工作吗?
这是我的代码:
@Path("/inchi")
public class InChIto3D {
@GET
@Path("{inchiname}")
@Produces("application/xml")
public String get3DCoordinates(@PathParam("inchiname")String inchiName) {
String ne="";
try{
URL eutilsurl = new URL(
"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?"
+ "db=pccompound&term=%22"+inchiName+"%22[inchi]");
BufferedReader in = new BufferedReader(
new InputStreamReader(eutilsurl.openStream()));
String inputline;
while ((inputline=in.readLine())!=null)
ne=ne+inputline;
}catch (MalformedURLException e1) {
}catch (IOException e2){
}
return ne;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个新的注释,我将在其中进行一些运行时布线,但是,由于多种原因,我想在编译时验证我的布线是否会成功进行一些基本检查.
假设我创建了一个新注释:
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface CustomAnnotation{
}
Run Code Online (Sandbox Code Playgroud)
现在我想在编译时进行某种验证,比如检查CustomAnnotation
注释是否属于特定类型的字段:ParticularType
.我在Java 6工作,所以我创建了一个AbstractProcessor
:
@SupportedAnnotationTypes("com.example.CustomAnnotation")
public class CompileTimeAnnotationProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(CustomAnnotation.class);
for(Element e : elements){
if(!e.getClass().equals(ParticularType.class)){
processingEnv.getMessager().printMessage(Kind.ERROR,
"@CustomAnnotation annotated fields must be of type ParticularType");
}
}
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
然后,根据我发现的一些说明,我创建了一个文件夹META-INF/services
并创建了一个javax.annotation.processing.Processor
包含内容的文件:
com.example.CompileTimeAnnotationProcessor
Run Code Online (Sandbox Code Playgroud)
然后,我将项目导出为jar.
在另一个项目中,我构建了一个简单的测试类:
public class TestClass {
@CustomAnnotation
private String bar; // not `ParticularType`
}
Run Code Online (Sandbox Code Playgroud)
我按如下方式配置了Eclipse项目属性: …
我有一个HTML表单,用户可以将文本输入到title
字段中,然后我创建一个名为的HTML文件title.html
我的问题是用户可以在标题字段中输入空格和撇号,这些字段不能在html文件名中使用.我使用以下内容替换带下划线的空格:
$FileName = str_replace(" ", "_", $UserInput);
Run Code Online (Sandbox Code Playgroud)
但是,我似乎无法删除单引号?我尝试过使用:
$FileName = preg_replace("/'/", '', $UserInput);
Run Code Online (Sandbox Code Playgroud)
但这又把test's
它变成了test\s.html
.
如何在spring配置文件中包含条件语句
我有String bean(b),其值取决于属性(a)的值.a根据其运行的环境动态设置.
if (a)
b="yes"
else
b="no"
Run Code Online (Sandbox Code Playgroud)
我如何在spring配置中编码?
假设我有一些架构:
<xsd:schema ...>
<xsd:element name="foo">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="fooElement" type="xs:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Run Code Online (Sandbox Code Playgroud)
这定义了一些元素foo
,其中包含一些fooElement
带有字符串类型的元素.我现在想扩展元素foo
也有一个元素barElement
并调用这个扩展名bar
.
为了使事情复杂化,我们还假设其他人已定义foo
并且架构无法更改.虽然这里的例子很简单,但我们也假设内容foo
可能更复杂,定义新模式并不像复制元素那么简单fooElement
.
实际上,我想定义一个新架构:
<xsd:schema xmlns:fns="otherschema" ...>
<xsd:import namespace="otherschema" />
<xsd:element name="bar">
<xsd:complexContent>
<xsd:extension base="fns:foo">
<xsd:sequence>
<xsd:element name="barElement" type="xs:string" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:element>
</xsd:schema>
Run Code Online (Sandbox Code Playgroud)
不幸<xsd:extension>
的是,该base
属性只接受XSD类型参数,而不接受元素.如何扩展元素?(我可以扩展一个元素吗?)