基礎(chǔ)
?
原生SQL方法設(shè)置@Query的屬性為nativeQuery = true
@Query(value = "select u.* from Article u where u.title = ? ", nativeQuery = true)
:title 、?1 匹配第一個參數(shù)title
@Query(value = "select u.* from Article u where u.title = :title ", nativeQuery = true)
List<Article> queryArticleList(String title) ;
@Query(value = "select u.* from Article u where u.title = ?1 ", nativeQuery = true)
List<Article> queryArticleList(String title) ;
Demo?
主要方法
/**
* Description: 文章列表
*/
@Transactional
@RequestMapping("/list2/{title}")
public ModelAndView articlelist2(
@PathVariable(value = "title" ) String title) {
Sort sort = Sort.by(Sort.Direction.DESC, "id");
Pageable pageable = PageRequest.of(0, 2, sort);
Page<Article> result = articleRepository.queryArticleList(title,pageable);
System.out.println(result);
ModelAndView mav = new ModelAndView("article/list");
mav.addObject("page", result);
return mav;
}
@Transactional:事務(wù)?
本文摘自 :https://blog.51cto.com/u