我有 Hibernate 的问题。我尝试将日历对象映射到我在表结构中使用的日期。
在 Hibernate 的引用指南中,您可以找到有关类型映射的信息,在那里您可以找到类似“calendar_date”的信息。
<property generated="never" lazy="false" name="dateB" type="calendar_date" />
但是一个简单的等号不起作用(没有结果,但是 phpMyAdmin 给了我相同的查询结果):
List<Maturity> result = session.createCriteria(Maturity.class).add(Restrictions.eq("dateB", date0)).list();
这是成熟度类:
package datahandler.objects;
import java.util.Calendar;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
public class Maturity {
final int DAY = 0;
final int MONTH = 1;
final int YEAR = 2;
final int HOUR = 3;
final int MIN = 4;
@Id
@GeneratedValue
private int id;
@Temporal(TemporalType.DATE)
private Calendar dateB = Calendar.getInstance();
private Calendar dateE = Calendar.getInstance();
private Calendar timeB = Calendar.getInstance();
private Calendar timeE = Calendar.getInstance();
private String name;
private String description;
public Maturity() {
// this.id = 0; // Sicherheitseintrag für leeren Termin-Datensatz!!!
}
public Maturity(int id, Calendar dateB, Calendar dateE, String name,
String description) {
this.id = id;
this.timeB = dateB;
this.dateB = dateB;
this.timeE = dateE;
this.dateE = dateE;
this.name = name;
this.description = description;
}
public Maturity(Calendar dateB, Calendar dateE, String name,
String description) {
this.timeB = dateB;
this.dateB = dateB;
this.timeE = dateE;
this.dateE = dateE;
this.name = name;
this.description = description;
}
public Maturity(int id, int dayB, int monB, int yearB, int hourB, int minB,
int dayE, int monE, int yearE, int hourE, int minE, String name,
String description) {
this.id = id;
this.timeB.set(0, 0, 0, hourB, minB, 0);
this.dateB.set(yearB, monB - 1, dayB);
this.timeE.set(0, 0, 0, hourE, minE, 0);
this.dateE.set(yearE, monE - 1, dayE);
this.name = name;
this.description = description;
}
public Maturity(int dayB, int monB, int yearB, int hourB, int minB,
int dayE, int monE, int yearE, int hourE, int minE, String name,
String description) {
this.timeB.set(0, 0, 0, hourB, minB, 0);
this.dateB.set(yearB, monB - 1, dayB);
this.timeE.set(0, 0, 0, hourE, minE, 0);
this.dateE.set(yearE, monE - 1, dayE);
this.name = name;
this.description = description;
}
// Standard Get- Methoden
public int getId() {
return id;
}
public Calendar getDateB() {
return dateB;
}
public Calendar getTimeB() {
return timeB;
}
public Calendar getDateE() {
return dateE;
}
public Calendar getTimeE() {
return timeE;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
// Standard Set- Methoden
public void setId(int id) {
this.id = id;
}
public void setDateB(Calendar dateB) {
this.dateB = dateB;
}
public void setTimeB(Calendar timeB) {
this.timeB = timeB;
}
public void setDateE(Calendar dateE) {
this.dateE = dateE;
}
public void setTimeE(Calendar timeE) {
this.timeE = timeE;
}
public void setName(String name) {
this.name = name;
}
public void setDescription(String description) {
this.description = description;
}
// Spezielle Get- Methoden für Calendar (Array:
// [DAY][MONTH][YEAR][HOUR][MIN])
public int[] getDateB_M() {
return new int[] { dateB.get(Calendar.DAY_OF_MONTH),
dateB.get(Calendar.MONTH) + 1, dateB.get(Calendar.YEAR),
timeB.get(Calendar.HOUR_OF_DAY), timeB.get(Calendar.MINUTE) };
}
public int[] getDateE_M() {
return new int[] { dateE.get(Calendar.DAY_OF_MONTH),
dateE.get(Calendar.MONTH) + 1, dateE.get(Calendar.YEAR),
timeE.get(Calendar.HOUR_OF_DAY), timeE.get(Calendar.MINUTE) };
}
// Spezielle Set- Methoden für Calendar
public void setDateB(int day, int month, int year, int hour, int min) {
this.timeB.set(0, 0, 0, hour, min);
this.dateB.set(year, (month - 1), day);
}
public void setDateE(int day, int month, int year, int hour, int min) {
this.timeE.set(0, 0, 0, hour, min);
this.dateE.set(year, (month - 1), day, hour, min);
}
public void setDateB(int day, int month, int year) {
this.dateB.set(year, (month - 1), day, 0, 0);
}
public void setDateE(int day, int month, int year) {
this.dateE.set(year, (month - 1), day, 0, 0);
}
}
date0 生成:
Calendar rangeStart = Calendar.getInstance();
int dayB, monB, yearB;
dayB = this.readGetParameterAsInteger("startDay");
monB = this.readGetParameterAsInteger("startMonth");
yearB = this.readGetParameterAsInteger("startYear");
rangeStart.set(yearB, monB, dayB, 0, 0, 0);
我能做什么?
最佳答案
Hibernate 类型日历、calendar_date MAP java.util.Calendar 到 SQL 类型 TIMESTAMP 和 DATE。你就在那里。 但是您需要显示 date0 的类型是什么以及它是如何构建或检索的。
也可以尝试使用替代日历而不是 calendar_date
关于java - 日历到日期映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4605721/
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
我需要检查DateTime是否采用有效的ISO8601格式。喜欢:#iso8601?我检查了ruby是否有特定方法,但没有找到。目前我正在使用date.iso8601==date来检查这个。有什么好的方法吗?编辑解释我的环境,并改变问题的范围。因此,我的项目将使用jsapiFullCalendar,这就是我需要iso8601字符串格式的原因。我想知道更好或正确的方法是什么,以正确的格式将日期保存在数据库中,或者让ActiveRecord完成它们的工作并在我需要时间信息时对其进行操作。 最佳答案 我不太明白你的问题。我假设您想检查
我的日期格式如下:"%d-%m-%Y"(例如,今天的日期为07-09-2015),我想看看是不是在过去的七天内。谁能推荐一种方法? 最佳答案 你可以这样做:require"date"Date.today-7 关于ruby-检查日期是否在过去7天内,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/32438063/
这个问题在这里已经有了答案:Railsformattingdate(4个答案)关闭4年前。我想格式化Time.Now函数以显示YYYY-MM-DDHH:MM:SS而不是:“2018-03-0909:47:19+0000”该函数需要放在时间中.现在功能。require‘roo’require‘roo-xls’require‘byebug’file_name=ARGV.first||“Template.xlsx”excel_file=Roo::Spreadsheet.open(“./#{file_name}“,extension::xlsx)xml=Nokogiri::XML::Build
我正在尝试解析一个CSV文件并使用SQL命令自动为其创建一个表。CSV中的第一行给出了列标题。但我需要推断每个列的类型。Ruby中是否有任何函数可以找到每个字段中内容的类型。例如,CSV行:"12012","Test","1233.22","12:21:22","10/10/2009"应该产生像这样的类型['integer','string','float','time','date']谢谢! 最佳答案 require'time'defto_something(str)if(num=Integer(str)rescueFloat(s
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
为什么以下不同?Time.now.end_of_day==Time.now.end_of_day-0.days#falseTime.now.end_of_day.to_s==Time.now.end_of_day-0.days.to_s#true 最佳答案 因为纳秒数不同:ruby-1.9.2-p180:014>(Time.now.end_of_day-0.days).nsec=>999999000ruby-1.9.2-p180:015>Time.now.end_of_day.nsec=>999999998
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht