如何从Thymeleaf访问一些简单的POJO静态属性?例如:
public final static int PROJECT_NAME_MAX_LENGTH = 255;
Run Code Online (Sandbox Code Playgroud)
如何输入:
<input type="text" th:maxlength="??" />
Run Code Online (Sandbox Code Playgroud) 由于如何从JSP页面中的数据库检索和显示图像,我找到了从db/blob检索图像的非常好的解决方案?
但这是在每个图像请求上使用JDBC连接的解决方案.
我正在使用Spring 3注释和Hibernate 3.
我尝试通过我的'imageService'做类似的事情,它由ImageServlet类中的注释自动装配,但是我得到了nullPointerException,这意味着可能没有依赖注入设置imageService.
有什么方法可以解决这个问题吗?我不喜欢在图像请求上建立单个jdbc连接.
我有界面:
interface Identifable<T extends Serializable> {
T getID();
}
Run Code Online (Sandbox Code Playgroud)
和实现这个的类:
public class Cat implements Identifable<Long> {
public Long getID(){...};
}
Run Code Online (Sandbox Code Playgroud)
一切正常.至今.现在我想创建GenericDAO,为什么我不能创建它?:
public abstract GenericDAO<T extends Identifable<S>> {
T getByID(S id);
}
Run Code Online (Sandbox Code Playgroud)
我只能声明我的GenericDAO:
public abstract GenericDAO<T extends Identifable, S> {
T getById(S id);
}
Run Code Online (Sandbox Code Playgroud)
完整的课程:
public CatDAO extends GenericDAO<Cat, Long> {
Cat getById(Long id);
}
Run Code Online (Sandbox Code Playgroud)
但我觉得它没用,因为我重复信息.我已经声明,Cat实现了Identifable <Long>,为什么我必须声明GenericDAO <Cat,Long>,而不仅仅是GenericDAO <Cat>?
我有一个像这样的HQL查询:
Query query = session.createQuery("from User as user where user.joined!=null order by user.joined desc");
Run Code Online (Sandbox Code Playgroud)
如何设置变量User属性作为查询的排序顺序?我的解决方案:
String order = "user.joined";
Query query = session.createQuery("from User as user where user.joined!=null order by :order desc").setString("order", order);
Run Code Online (Sandbox Code Playgroud)
没有给出有序的查询结果。
我的实体类映射如下:
@Entity
@Audited
@Table(name="messages_locale")
public class Locale {
@Id
@GeneratedValue
@Getter @Setter //Project Lombok's annotations, equal to generated getter and setter method
private int id;
(...)
Run Code Online (Sandbox Code Playgroud)
我创建干净的新数据库和属性:
<prop key ="hibernate.hbm2ddl.auto">创建</ prop>
在创建数据库后,为什么地狱(对不起,差不多浪费了两天这个bug),我在postgres数据库中得到了一个序列?:
CREATE SEQUENCE hibernate_sequence
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 2
CACHE 1;
ALTER TABLE hibernate_sequence
OWNER TO postgres;
Run Code Online (Sandbox Code Playgroud)
我不想要一个序列,我想只是自动增加自动生成的值..
我有我的实体:
@Entity
@Table(name="performances")
@AssociationOverrides({
@AssociationOverride(name="id.player", joinColumns=@JoinColumn(name="player_id")),
@AssociationOverride(name="id.season", joinColumns=@JoinColumn(name="season_id"))
})
public class Performance extends AbstractEntity<PerformanceID> {
private static final long serialVersionUID = 1L;
@EmbeddedId
@Getter @Setter
private PerformanceID id;
@Getter @Setter
private int goals;
public Player getPlayer(){
return id.getPlayer();
}
public Season getSeason(){
return id.getSeason();
}
Run Code Online (Sandbox Code Playgroud)
和:
@Embeddable
public class PerformanceID implements Serializable {
private static final long serialVersionUID = 1L;
@ManyToOne(fetch=FetchType.LAZY, targetEntity=Player.class)
@JoinColumn(name="player_id")
@Getter @Setter
private Player player;
@ManyToOne(fetch=FetchType.LAZY, targetEntity=Season.class)
@JoinColumn(name="season_id")
@Getter @Setter
private Season season;
Run Code Online (Sandbox Code Playgroud)
如何选择玩家名称为"Claudio"的演出记录?在HQL中,它只是工作:
Query query = …Run Code Online (Sandbox Code Playgroud) 我上课了:
@Entity
@Table(name="users")
public class User{
private Integer id;
private String name;
private Address address;
}
Run Code Online (Sandbox Code Playgroud)
和:
@Entity
@Table(name="adress")
public class Adress{
private Integer id;
private String street;
(...)
}
Run Code Online (Sandbox Code Playgroud)
任何方式如何映射关系@ManyToOne(许多用户可以拥有相同的adres),但我不想在我的Address类中拥有属性List <User>用户?
我得到了如下的包结构:
(...)
com.domain.group.dao
com.domain.group.service
(...)
com.domain.users.dao
com.domain.users.service
Run Code Online (Sandbox Code Playgroud)
有什么方法可以告诉 spring 应该只扫描包以“dao”或“service”结尾的所有类?
这是类似问题的示例,但它不能解决我的问题。
是否可以在加载页面后使用JSF触发ajax事件,例如每隔10秒?
我的意思是:
<f:ajax listener="#{bean.mymethod()}" />
Run Code Online (Sandbox Code Playgroud)
我想在加载页面后每隔10秒调用一次这个方法.我不想通过JavaScript刷新重新加载整个页面.
我在gradle项目中创建了另一个称为“集成测试”的源集。一切正常,但是eclipse无法看到为此源集精确定义的依赖项类。
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
repositories {
mavenCentral()
}
sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integration-test/java')
}
resources.srcDir file('src/integration-test/resources')
}
}
configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
}
dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-all:1.10.19'
integrationTestCompile 'org.springframework:spring-test:4.1.7.RELEASE'
compile 'org.springframework:spring-context:4.1.7.RELEASE'
compile 'org.springframework:spring-core:4.1.7.RELEASE'
}
task integrationTest(type: Test) {
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
outputs.upToDateWhen { false }
}
check.dependsOn integrationTest
integrationTest.mustRunAfter test
version = '1.0'
}
Run Code Online (Sandbox Code Playgroud)
当我通过命令“ …
我上课了:
@Entity
@Table(name="restaurants")
public class Restaurant {
@Id
@GeneratedValue
private int id;
private String name;
private String street;
(...)
@ManyToMany
@JoinTable(name="user_restaurant_owner",
joinColumns={@JoinColumn(name="restaurant_id")},
inverseJoinColumns={@JoinColumn(name="username")})
private List<User> owner;
Run Code Online (Sandbox Code Playgroud)
如果我知道用户("所有者")用户名,如何获得餐厅?
查询q = session.createQuery("从餐厅作为r,其中r.owner =:username").setString("username",username);
它不起作用
在我的数据库中,我有一个"year"列,它是一个整数.
如何使用Criteria API(而不是HQL)搜索哪些记录包含,例如年份列中的"196 ..."?
我认为它应该是Restrictions.like,但我得到了例外:
__PRE__
我是jQuery的新手,但我试着学习它.假设我输入了id ="userForm:id"; 在javascript中我可以简单地获取id:
var id = document.getElementById("userForm:id");
Run Code Online (Sandbox Code Playgroud)
在jQuery中我尝试:
var id = $('#userForm:id');
Run Code Online (Sandbox Code Playgroud)
但后来我得到错误:
Uncaught Error: Syntax error, unrecognized expression: unsupported
pseudo: id
Run Code Online (Sandbox Code Playgroud)