spring-mvc - Spring Data JPA如何使用排序?

标签 spring-mvc spring-data thymeleaf spring-boot

@Controller
@RequestMapping("/admin/hotel")
class HotelController {

    @Autowired
    private HotelRepository repository;

    @RequestMapping(method = RequestMethod.GET)
    public String list(Model model, @PageableDefault(page = 0, value = 10) Pageable pageable) {
        Page<Hotel> page = repository.findAll(pageable);
        model.addAttribute("page", page);
        return "hotel/list";
    }
}

我的问题:如何使用 Thymeleaf 模板引擎在 View 层上使用 Page 对象生成排序链接?

最佳答案

<a th:href="@{~/admin/hotel(sort=(${page?.sort?.getOrderFor('title')?.ascending} ? 'title,desc' : 'title,asc'))}">title</a>

关于spring-mvc - Spring Data JPA如何使用排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22931852/

相关文章:

java - 数据库连接mysql和Spring框架

java - Spring MVC StreamingResponseBody 返回分块文件

Spring JPA : Locking parent row when inserting one to many child record

java - 错误:Neither BindingResult nor plain target object for bean name 'id' available as request attribute

css - 如何在 spring 3 中的 css 文件中使用 font-faces

java - 在 Spring 3/Spring Security 2.0.5 中检测 session 超时

Spring Data Rest自定义 Controller

java - QuerydslPredicate 和泛型类

java - 使用 Thymeleaf 时,Spring security sessionscope 似乎为空

templates - 根据 thymeleaf 中的其他变量选择上下文变量属性(动态)