我正在从数据库中撤回日期和时间.它们存储在单独的字段中,但我想将它们组合成一个适当反映日期/时间的java.util.Date对象.
这是我原来的方法,但它有缺陷.我总是得到一个6小时的日期/时间.我认为这是因为Time有一个时区偏移量和Date,我真的只需要其中一个来获得时区偏移量.
有关如何做到这一点的任何建议,以便它会给我正确的日期/时间?
import java.sql.Time;
import java.util.Calendar;
import java.util.Date;
import org.apache.commons.lang.time.DateUtils;
public static Date combineDateTime(Date date, Time time)
{
if (date == null)
return null;
Date newDate = DateUtils.truncate(date, Calendar.DATE);
if (time != null)
{
Date t = new Date(time.getTime());
newDate = new Date(newDate.getTime() + t.getTime());
}
return newDate;
}
Run Code Online (Sandbox Code Playgroud) @Entity
public class TestClass implements Serializable{
private Integer id;
private Set<String> mySet;
@Id
@GeneratedValue
public Integer getId() {
return id;
}
@OneToMany(cascade={CascadeType.ALL})
public Set<String> getMySet() {
return mySet;
}
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误.
Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: TestClass.mySet[java.lang.String]
Run Code Online (Sandbox Code Playgroud)
或者如果我离开@OneToMany
org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: test_class, for columns: [org.hibernate.mapping.Column(my_sets)]
如何在我的java Web应用程序之外移动spring xml配置?
我想将spring.xml存储在我的Web应用程序之外,因此我不必创建我的应用程序的新版本来更改配置.
做这个的最好方式是什么?
我在Windows Server 2003上安装了Tomcat 6.0.18,它不会作为服务启动.我用jdk 1.6.0_07运行它.
它在我用tomcat6.exe启动时运行.
我在Windows上的系统事件日志中出现了一个模糊的错误.
Apache Tomcat 6服务因服务特定错误0(0x0)而终止.
我需要以简单的方式允许最终用户从同一个盒子上的apache提供的网页重启tomcat.
我们正在尝试让我们的QC部门轻松地将新版本的webapp部署到apache.我们正在使用samba,但我们需要一种简单的方法让他们在部署之前/之后停止/启动tomcat服务器.
这只适用于内部qc盒.是否有现成的解决方案?或者更容易编写一些快速的PHP应用程序来处理这个?
我希望能够在数据流入/流出磁盘时加密/解密数据.我知道我可以编写自己的Stream并在那里实现加密,但我宁愿不冒险做错.是否有一个与以下代码类似的库?
byte[] encryptionKey = ;
byte[] initVector = ;
var fileStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write);
var encryptionStream = new AesEncryptionStream(fileStream, initVector, encryptionKey);
var gzStream = new GZipStream(encryptionStream, CompressionMode.Compress);
var writer = new BinaryWriter(gzStream);
Run Code Online (Sandbox Code Playgroud) System.InvalidOperationException:MsmqIntegrationBinding验证失败.该服务无法启动.MsmqIntegrationBinding绑定不支持服务操作的方法签名.
我正在使用以下示例此处 我更改的唯一设置是我需要使用ActiveX序列化格式.
接口
namespace MQTest
{
//MSMQIntegrationBinding
[ServiceContract]
public interface IMQService
{
[OperationContract(IsOneWay = true, Action = "*")]
void GetData(string value);
}
}
Run Code Online (Sandbox Code Playgroud)
服务
public class MQService : IMQService
{
public static void Main()
{
// Get base address from appsettings in configuration.
Uri baseAddress = new Uri("http://localhost:8000/Test/Service");
// Create a ServiceHost for the CalculatorService type and provide the base address.
using (ServiceHost serviceHost = new ServiceHost(typeof (IMQService), baseAddress))
{
// Open the ServiceHostBase to create listeners and …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的骆驼路线.它以作为Web服务公开的CXF端点开始.然后我想将它转换为xml并在bean上调用一个方法.
目前我正在获取Web服务调用后的CXF特定对象.如何将序列化对象从CXF MessageList中取出并继续使用?
我的路线:
<camel:route>
<camel:from uri="cxf:bean:helloEndpoint" />
<camel:marshal ref="xstream-utf8" />
<camel:to uri="bean:hello?method=hello"/>
</camel:route>
Run Code Online (Sandbox Code Playgroud)
XML序列化消息:
<?xml version='1.0' encoding='UTF-8'?>
<org.apache.cxf.message.MessageContentsList serialization="custom">
<unserializable-parents />
<list>
<default>
<size>1</size>
</default>
<int>6</int>
<com.whatever.Person>
<firstName>Joe</firstName>
<middleName></middleName>
<lastName>Buddah</lastName>
<dateOfBirth>2010-04-13 12:09:00.137 CDT</dateOfBirth>
</com.whatever.Person>
</list>
</org.apache.cxf.message.MessageContentsList>
Run Code Online (Sandbox Code Playgroud)
我希望XML更像这样:
<com.whatever.Person>
<firstName>Joe</firstName>
<middleName></middleName>
<lastName>Buddah</lastName>
<dateOfBirth>2010-04-13 12:09:00.137 CDT</dateOfBirth>
</com.whatever.Person>
Run Code Online (Sandbox Code Playgroud) 在使用带有hibernate for ORM的mysql数据库检索文本之前,如何使用mysql的compress()和uncompress()函数压缩文本,然后再存储和解压缩文本?
有没有办法使用"IDictionary"样式查找动态访问expando的属性?
var messageLocation = "Message";
dynamic expando = new ExpandoObject();
expando.Message = "I am awesome!";
Console.WriteLine(expando[messageLocation]);
Run Code Online (Sandbox Code Playgroud)