小编use*_*391的帖子

Thymeleaf,片段和默认参数

我创建了fragment.html文件.它包含以下片段:

<div th:fragment="my_fragment(content)">
    <p th:text="${content}"></p>
</div>
Run Code Online (Sandbox Code Playgroud)

我将上面的片段放入我的视图文件中:

<div th:replace="fragments :: my_fragment('test')"></div>
Run Code Online (Sandbox Code Playgroud)

现在,我想将两个参数传递给my_fragment,但我必须确保向后兼容性.

我试着按如下方式解决问题:

<div th:fragment="my_fragment(content, defaultParameter='default value')">
    <p th:text="${content}"></p>
</div>
Run Code Online (Sandbox Code Playgroud)

不幸的是,上面的解决方案产生了错误:

org.springframework.web.util.NestedServletException:请求处理失败; 嵌套异常是org.thymeleaf.exceptions.TemplateProcessingException:无法解析片段.签名"my_fragment(content,defaultParameter ='default value')"声明2个参数,但片段选择指定1个参数.片段选择不正确匹配.

任何的想法?

java spring spring-mvc thymeleaf

33
推荐指数
3
解决办法
3万
查看次数

PostgreSQL错误的排序

我使用PostgreSQL 9.3.3并且我有一个表,其中一列名为title(字符变化(50)).

当我执行以下查询时:

select * from test
order by title asc
Run Code Online (Sandbox Code Playgroud)

我得到了以下结果:

#
A
#Example
Run Code Online (Sandbox Code Playgroud)

为什么"#Example"处于最后位置?在我看来,"#Example"应该处于第二位.

sql postgresql

12
推荐指数
2
解决办法
4401
查看次数

Spring数据JPA存储库在EJB计时器中使用会导致TransactionRequiredException

我想在我的Java EE项目中使用spring数据库.我用:

  • WildFly 10.0.0
  • Hibernate 5.0.7
  • Spring Data JPA 1.10.6
  • CDI而不是Spring DI

我创建了以下类和接口:

@Entity
public class TestEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotNull
    @Size(min = 1, max = 32)
    @Column(name = "name")
    private String name;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的存储库

@Repository
public interface TestRepository extends CrudRepository<TestEntity, Long> { …
Run Code Online (Sandbox Code Playgroud)

hibernate jpa cdi spring-data spring-data-jpa

5
推荐指数
1
解决办法
1350
查看次数

Java注释 - 代码简化

我正在寻找一种简化以下代码的方法.

@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {
        // My configuration classes
})
public class MyServiceTest {
    @Autowired
    private MyService service;

    @Test
    public void myTest() {
        Assert.assertTrue(service != null);
    }
}
Run Code Online (Sandbox Code Playgroud)

我有很多配置类,我不想把它们放到每个测试类中.所以我有了创建自己的注释的想法:

@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {
        // My configuration classes
})
public @interface IntegrationTests {
}
Run Code Online (Sandbox Code Playgroud)

我尝试以下列方式使用它:

@IntegrationTests
public class MyServiceTest {
    @Autowired
    private MyService service;

    @Test
    public void myTest() {
        Assert.assertTrue(service != null);
    }
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用.任何的想法?

java testing spring annotations spring-test

2
推荐指数
2
解决办法
684
查看次数