我有一个包含日期的字符串,例如"01-01-2012",然后是空格,然后是时间"01:01:01".完整的字符串是:"01-01-2012 01:01:01"
我想从这个字符串中只提取日期,所以最后我会有"01-01-2012",但不知道如何做到这一点.
我正试图将我的StringReader背部转换为常规String,如图所示:
String string = reader.toString();
Run Code Online (Sandbox Code Playgroud)
但是当我尝试读出这个字符串时,就像这样:
System.out.println("string: "+string);
Run Code Online (Sandbox Code Playgroud)
我得到的只是一个指针值,如下所示:
java.io.StringReader@2c552c55
Run Code Online (Sandbox Code Playgroud)
我在读回字符串时做错了吗?
通常,默认范围是请求范围.我试图删除范围注释并期望bean有一个请求bean scopped行为(通过在前一页上返回一个提交的值,我记得我已经尝试过这个过去并且它工作正常)但我没有得到任何关于表达语言连接到它.那么什么是默认范围以及它为什么不是相同的行为?!
我继承了一个hibernate应用程序,但我遇到了问题.似乎代码不会将孩子保存为一对多关系.它是双向的,但是在保存父对象时,它似乎不会保存孩子.
在这种情况下,Question类是父类.
// Question.java
@Entity
@SequenceGenerator(name = "question_sequence", sequenceName = "seq_question", allocationSize = 1000)
@Table(name = "question")
public class Question {
protected Long questionId;
protected Set<AnswerValue> answerValues;
public TurkQuestion(){}
public TurkQuestion(Long questionId){
this.questionId = questionId;
}
@Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "question_sequence")
@Column(name = "question_id")
public Long getQuestionId(){
return questionId;
}
@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "question_id",referencedColumnName="question_id")
public Set<AnswerValue> getAnswerValues(){
return answerValues;
}
public void setQuestionId(Long questionId){
this.questionId = questionId;
}
public void setAnswerValues(Set<AnswerValue> answerValues){
this.answerValues = answerValues;
} …Run Code Online (Sandbox Code Playgroud) 我需要了解编译servlet所需的serlvet-api.jar.
我正在构建一个简单的servlet,如下所示:
import javax.servlet.*;
import javax.servlet.http.*;
public class FirstServlet extends HttpServlet {
// Remaining code here
}
Run Code Online (Sandbox Code Playgroud)
我知道我们需要servlet-api.jar文件来编译这个简单的servlet,如下所示:
javac -classpath /path/where/jar/is/servlet-api.jar
Run Code Online (Sandbox Code Playgroud)
现在我的怀疑从这里开始:
考虑这种情况:
假设我们使用Tomcat编译/构建简单的servlet(即构建servlet所需的tomcat版本的jar)并创建.war文件.我们可以在其他供应商的容器中部署战争吗?
我有一个客户端应用程序提供给我的C#应用程序的XML文档.这是客户端发送XML文件的方式:
<?xml version="1.0" encoding="utf-8"?>
<SomeAccount>
<parentId>2380983</parentId>
<!-- more elements -->
</SomeAccount>
Run Code Online (Sandbox Code Playgroud)
还有一个支持XML反序列化的C#类:
[XmlRoot]
public class SomeAccount
{
[XmlElement("parentId")]
public long ParentId { get; set; }
//rest of fields...
}
Run Code Online (Sandbox Code Playgroud)
但是有一些客户端的系统以这种方式发送XML(请注意大写LeParentId):
<?xml version="1.0" encoding="utf-8"?>
<SomeAccount>
<LeParentId>2380983</LeParentId>
<!-- similar for the other elements -->
</SomeAccount>
Run Code Online (Sandbox Code Playgroud)
如何使这个字段(和其他字段)支持XML名称parentId和LeParentId?
这是我目前用于XML反序列化的方法:
public sealed class XmlSerializationUtil
{
public static T Deserialize<T>(string xml)
{
if (xml == null)
return default(T);
XmlSerializer serializer = new XmlSerializer(typeof(T));
StringReader stringReader = new StringReader(xml);
return (T)serializer.Deserialize(stringReader); …Run Code Online (Sandbox Code Playgroud) 为了搞乱目的,我在日食火星上写了这行代码:
null.toString();
Run Code Online (Sandbox Code Playgroud)
我收到以下编译器错误消息:
无法在基本类型null上调用toString()
这是非常奇怪的,因为null它不是原始类型,也不是对象引用,如下所述:null是一个对象吗?
所以,为了确保,我尝试使用javac编译这样奇怪的代码行,我得到了这个结果:
NullTest.java:3:无法解除引用
Run Code Online (Sandbox Code Playgroud)null.toString(); ^1错误
有人知道为什么Eclipse会给出这样的(IMO)误导性编译器错误消息吗?
在编写自己的类时,是否总是需要覆盖equals(Object o)?
如果我不这样做,它会自动检查所有字段是否相同?或者只是检查两个变量是否指向同一个对象?
有没有人使用,实现,知道或只是听说过任何图形(特别是RDF)到java的对象映射框架.
我们目前正在评估框架.到目前为止,我们有:
看一下web中的一些java示例代码,我遇到了以下语法:
public class WordCount {
public static class Map extends Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
//...
}
}
//...
}
Run Code Online (Sandbox Code Playgroud)
来自C#背景,其中静态类不能从另一个类继承,我extends在Map课后对关键字有点困惑.扩展静态类是什么意思,它提供了什么优势?
java ×8
inheritance ×2
string ×2
annotations ×1
c# ×1
comparison ×1
eclipse ×1
equals ×1
graph ×1
hibernate ×1
java-ee ×1
jsf ×1
many-to-one ×1
mapping ×1
null ×1
one-to-many ×1
orm ×1
rdf ×1
servlets ×1
static ×1
stringreader ×1
tomcat7 ×1
tostring ×1
xml ×1