第9讲 9.2 SpringBoot自定义查询原生SQL

1,bookDao接口,添加注解,nativeQuery=true,表示启动本地查询,查询三个并随机排列

@Query(value="select * from t_book order by RAND() limit ?1",nativeQuery=true)
public List randomList(Integer num);

2,BookController ,

@ResponseBody
@RequestMapping("/randomList")
public List randomList(){
        List bookList = bookDao.randomList(3);
        return bookList;
    }

3,测试

猜你喜欢

转载自blog.csdn.net/u010393325/article/details/83957896
9.2