相关文章推荐
有腹肌的卡布奇诺  ·  js ...·  1 月前    · 
酒量大的青蛙  ·  公布!江苏省2020年普通高中星级评估出炉, ...·  3 月前    · 
痛苦的投影仪  ·  2-1绝杀西班牙!巴西男足卫冕金牌,马尔科姆 ...·  4 月前    · 
奔跑的斑马  ·  Hearts of Iron IV ...·  5 月前    · 
爱运动的围巾  ·  浏览器的同源策略 - Web 安全 | MDN·  6 月前    · 
爱喝酒的毛衣  ·  大数据计算MaxCompute我要取出jso ...·  1 年前    · 
Code  ›  解决Spring Spring Data JPA 错误: Page 1 of 1 containing UNKNOWN instances解决Spring Spring Data JPA 错误: 开发者社区
jpa data
https://cloud.tencent.com/developer/article/1188876
星星上的苦咖啡
2 年前
作者头像
一个会写诗的程序员
0 篇文章

解决Spring Spring Data JPA 错误: Page 1 of 1 containing UNKNOWN instances解决Spring Spring Data JPA 错误:

前往专栏
腾讯云
开发者社区
文档 意见反馈 控制台
首页
学习
活动
专区
工具
TVP
文章/答案/技术大牛
发布
首页
学习
活动
专区
工具
TVP
返回腾讯云官网
社区首页 > 专栏 > 一个会写诗的程序员的博客 > 解决Spring Spring Data JPA 错误: Page 1 of 1 containing UNKNOWN instances解决Spring Spring Data JPA 错误:

解决Spring Spring Data JPA 错误: Page 1 of 1 containing UNKNOWN instances解决Spring Spring Data JPA 错误:

作者头像
一个会写诗的程序员
发布 于 2018-08-17 15:02:04
2.8K 0
发布 于 2018-08-17 15:02:04
举报

解决Spring Spring Data JPA 错误: Page 1 of 1 containing UNKNOWN instances

SpringBoot 整合 Spring-Data-JPA 的时候出现此问题:

前端 js 代码

$(function () {
    var searchText = $('.search').find('input').val()
    var columns = [];
    columns.push({
        title: '分类',
        field: 'category',
        align: 'center',
        valign: 'middle',
        formatter: function (value, row, index) {
            return value
        title: '美图',
        field: 'url',
        align: 'center',
        valign: 'middle',
        formatter: function (value, row, index) {
            return "![](" + value + ")"
    $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales['zh-CN']);
    $('#meituFavoriteTable').bootstrapTable({
        url: 'meituSearchFavoriteJson',
        sidePagination: "server",
        queryParamsType: 'page,size',
        contentType: "application/x-www-form-urlencoded",
        method: 'get',
        striped: false,     //是否显示行间隔色
        cache: false,      //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
        pagination: true,  //是否显示分页(*)
        paginationLoop: true,
        paginationHAlign: 'right', //right, left
        paginationVAlign: 'bottom', //bottom, top, both
        paginationDetailHAlign: 'left', //right, left
        paginationPreText: ' 上一页',
        paginationNextText: '下一页',
        search: true,
        searchText: searchText,
        searchTimeOut: 500,
        searchAlign: 'right',
        searchOnEnterKey: false,
        trimOnSearch: true,
        sortable: true,    //是否启用排序
        sortOrder: "desc",   //排序方式
        sortName: "id",
        pageNumber: 1,     //初始化加载第一页,默认第一页
        pageSize: 10,      //每页的记录行数(*)
        pageList: [5, 10, 20, 50, 100], // 可选的每页数据
        totalField: 'totalPages',
        dataField: 'content', //后端 json 对应的表格数据 key
        columns: columns,
        queryParams: function (params) {
            return {
                size: params.pageSize,
                page: params.pageNumber,
                sortName: params.sortName,
                sortOrder: params.sortOrder,
                searchText: params.searchText
        classes: 'table table-responsive full-width',
    $(document).on('keydown', function (event) {
        // 键盘翻页事件
        var e = event || window.event || arguments.callee.caller.arguments[0];
        if (e && e.keyCode == 38 || e && e.keyCode == 37) {//上,左
            // 上一页
            $('.page-pre').click()
        if (e && e.keyCode == 40 || e && e.keyCode == 39) {//下,右
            // 下一页
            $('.page-next').click()
})

后端接口

MeituController

package com.easy.kotlin.controller
import com.easy.kotlin.chapter11_kotlin_springboot.dao.ImageRepository
import com.easy.kotlin.chapter11_kotlin_springboot.entity.Image
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.domain.Page
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Sort
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.servlet.ModelAndView
 * Created by jack on 2017/7/22.
@Controller
class MeituController {
    @Autowired
    var imageRepository: ImageRepository? = null
    @RequestMapping(value = "meituJson", method = arrayOf(RequestMethod.GET))
    @ResponseBody
    fun wotuJson(@RequestParam(value = "page", defaultValue = "0") page: Int,
                 @RequestParam(value = "size", defaultValue = "10") size: Int): Page<Image>? {
        return getPageResult(page, size)
    @RequestMapping(value = "meituSearchJson", method = arrayOf(RequestMethod.GET))
    @ResponseBody
    fun wotuSearchJson(@RequestParam(value = "page", defaultValue = "0") page: Int,
                       @RequestParam(value = "size", defaultValue = "10") size: Int,
                       @RequestParam(value = "searchText", defaultValue = "") searchText: String): Page<Image>? {
        return getPageResult(page, size, searchText)
    @RequestMapping(value = "meituSearchFavoriteJson", method = arrayOf(RequestMethod.GET))
    @ResponseBody
    fun wotuSearchFavoriteJson(@RequestParam(value = "page", defaultValue = "0") page: Int,
                               @RequestParam(value = "size", defaultValue = "10") size: Int,
                               @RequestParam(value = "searchText", defaultValue = "") searchText: String): Page<Image>? {
        return getFavoritePageResult(page, size, searchText)
    @RequestMapping(value = "meituView", method = arrayOf(RequestMethod.GET))
    fun meituView(): ModelAndView {
        return ModelAndView("meituView")
    @RequestMapping(value = "meituFavoriteView", method = arrayOf(RequestMethod.GET))
    fun meituFavoriteView(): ModelAndView {
        return ModelAndView("meituFavoriteView")
    private fun getPageResult(page: Int, size: Int): Page<Image>? {
        val sort = Sort(Sort.Direction.DESC, "id")
        val pageable = PageRequest(page, size, sort)
        return imageRepository?.findAll(pageable)
    private fun getPageResult(page: Int, size: Int, searchText: String): Page<Image>? {
        val sort = Sort(Sort.Direction.DESC, "id")
        val pageable = PageRequest(page, size, sort)
        if (searchText == "") {
            return imageRepository?.findAll(pageable)
        } else {
            return imageRepository?.search(searchText, pageable)
    private fun getFavoritePageResult(page: Int, size: Int, searchText: String): Page<Image>? {
        val sort = Sort(Sort.Direction.DESC, "id")
        val pageable = PageRequest(page, size, sort)
        if (searchText == "") {
            val allFavorite = imageRepository?.findAllFavorite(pageable)
            return allFavorite
        } else {
            val searchFavorite = imageRepository?.searchFavorite(searchText, pageable)
            return searchFavorite
}

ImageRepository

package com.easy.kotlin.chapter11_kotlin_springboot.dao
import com.easy.kotlin.chapter11_kotlin_springboot.entity.Image
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.PagingAndSortingRepository
import org.springframework.data.repository.query.Param
/** Created by jack on 2017/7/17.
@Query注解里面的value和nativeQuery=true,意思是使用原生的sql查询语句.
sql模糊查询like语法,我们在写sql的时候是这样写的
like '%?%'
但是在@Query的value字符串中, 这样写
like %?1%
interface ImageRepository : PagingAndSortingRepository<Image, Long> {
    @Query("SELECT a from #{#entityName} a where a.isDeleted=0 and a.category like %?1%")
    fun findByCategory(category: String): MutableList<Image>
    @Query("select count(*) from #{#entityName} a where a.isDeleted=0 and a.url = ?1")
    fun countByUrl(url: String): Int
    @Query("SELECT a from #{#entityName} a where a.isDeleted=0 and a.category like %:searchText%")
    fun search(@Param("searchText") searchText: String, pageable: Pageable): Page<Image>
    @Query("SELECT a from #{#entityName} a where a.isDeleted=0 and a.isFavorite=1")
    fun findAllFavorite(pageable: Pageable): Page<Image>
    @Query("SELECT a from #{#entityName} a where a.isDeleted=0 and a.isFavorite=1 and a.category like %:searchText%")
 
推荐文章
有腹肌的卡布奇诺  ·  js jquery-ajax/fetch请求时数据文本丢失加号和连接号的问题 - 深入学习ing
1 月前
酒量大的青蛙  ·  公布!江苏省2020年普通高中星级评估出炉,南京新添1所四星级高中!_澎湃号·媒体_澎湃新闻-The Paper
3 月前
痛苦的投影仪  ·  2-1绝杀西班牙!巴西男足卫冕金牌,马尔科姆加时进球_运动家_澎湃新闻-The Paper
4 月前
奔跑的斑马  ·  Hearts of Iron IV 钢铁雄心 4 [DLC 凝聚力解锁] [Steam] [Windows & SteamOS & macOS]_哔哩哔哩bilibili_钢铁雄心4
5 月前
爱运动的围巾  ·  浏览器的同源策略 - Web 安全 | MDN
6 月前
爱喝酒的毛衣  ·  大数据计算MaxCompute我要取出json字符串里的所有key和value 要怎么写?_问答-阿里云开发者社区
1 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号