精品专区-精品自拍9-精品自拍三级乱伦-精品自拍视频-精品自拍视频曝光-精品自拍小视频

網(wǎng)站建設(shè)資訊

NEWS

網(wǎng)站建設(shè)資訊

springboot中怎么利用Jpa實(shí)現(xiàn)分頁(yè)功能

本篇文章給大家分享的是有關(guān)springboot中怎么利用Jpa 實(shí)現(xiàn)分頁(yè)功能,小編覺(jué)得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話(huà)不多說(shuō),跟著小編一起來(lái)看看吧。

網(wǎng)站的建設(shè)成都創(chuàng)新互聯(lián)公司專(zhuān)注網(wǎng)站定制,經(jīng)驗(yàn)豐富,不做模板,主營(yíng)網(wǎng)站定制開(kāi)發(fā).小程序定制開(kāi)發(fā),H5頁(yè)面制作!給你煥然一新的設(shè)計(jì)體驗(yàn)!已為發(fā)電機(jī)回收等企業(yè)提供專(zhuān)業(yè)服務(wù)。

Springboot 集成 Jpa 實(shí)現(xiàn)分頁(yè)

由于用的技術(shù)并不復(fù)雜,所以我們開(kāi)門(mén)見(jiàn)山,直接上代碼

先來(lái)看下代碼結(jié)構(gòu)
springboot中怎么利用Jpa 實(shí)現(xiàn)分頁(yè)功能

pom.xml 引入相關(guān)jar包



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.3.4.RELEASE
         
    
    com.example
    springboot-blog
    0.0.1-SNAPSHOT
    springboot-blog
    Blog project for Spring Boot

    
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter-data-jpa
        
        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            junit
            junit
        

        
            MySQL
            mysql-connector-java
            runtime
        
        
            org.projectlombok
            lombok
            true
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
            
                
                    org.junit.vintage
                    junit-vintage-engine
                
            
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    

application.properties配置

# 配置數(shù)據(jù)源
spring.datasource.url=jdbc:mysql://localhost:3306/blog_system
spring.datasource.username=root
spring.datasource.password=root

#基本配置
spring.application.name=springboot-blog
server.port=8080

# 顯示sql
spring.jpa.show-sql=true

實(shí)體類(lèi)Article

@Data
@ToString
@Entity
@Table(name = "t_article")
public class Article {

    @Id
    private Integer id;

    @Column(name = "title")
    private String title;

    @Column(name = "content")
    private String content;

    @Column(name = "created")
    private Date created;

    @Column(name = "modified")
    private Date modified;

    @Column(name = "categories")
    private String categories;

    @Column(name = "tags")
    private String tags;

    @Column(name = "allow_comment")
    private Integer allowComment;

    @Column(name = "thumbnail")
    private String thumbnail;

}

ArticleDao層實(shí)現(xiàn)

public interface ArticleDao extends JpaRepository {

}

Article Service 層

ArticleService接口

public interface ArticleService {

    Page
 getArticleWithPage(Integer page, Integer size); }

ArticleServiceImpl實(shí)現(xiàn)類(lèi)

@Service
@Slf4j
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleDao articleDao;

    @Override
    public Page
 getArticleWithPage(Integer page, Integer size) {         log.info("page is {}, size is {}", page, size);         if (page <= 0) {             page = 1;         }         Pageable pageRequest = PageRequest.of(page - 1, size);         return articleDao.findAll(pageRequest);     } }

ArticleController 控制層實(shí)現(xiàn)

@Controller
@Slf4j
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @RequestMapping("/index")
    public String toIndex(Model model,
                          @RequestParam(value = "page", defaultValue = "1") Integer page,
                          @RequestParam(value = "size", defaultValue = "3") Integer size) {
        Page
 articles = articleService.getArticleWithPage(page, size);         model.addAttribute("articles", articles);         return "/client/index";     } }

頁(yè)面核心代碼







    

        
        
            

                
                    
                    默認(rèn)分類(lèi)
                       
                    
                    
                    

                                                 
                        
                    

                                                          
                     
                     首頁(yè)             上一頁(yè)             下一頁(yè)             尾頁(yè)

        
    
                               子慕                          

                Java后臺(tái)開(kāi)發(fā)             

            

個(gè)人博客小站,主要發(fā)表關(guān)于Java、Spring、Docker等相關(guān)文章

                              聯(lián)系我             

                                              

             

效果展示

springboot中怎么利用Jpa 實(shí)現(xiàn)分頁(yè)功能

以上就是springboot中怎么利用Jpa 實(shí)現(xiàn)分頁(yè)功能,小編相信有部分知識(shí)點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見(jiàn)到或用到的。希望你能通過(guò)這篇文章學(xué)到更多知識(shí)。更多詳情敬請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。


當(dāng)前名稱(chēng):springboot中怎么利用Jpa實(shí)現(xiàn)分頁(yè)功能
新聞來(lái)源:http://m.jcarcd.cn/article/gededj.html 主站蜘蛛池模板: 精品福利私拍 | 九九在线免费视频 | 国产精品免费网站 | 国产秘精品入口欧 | www.操| 国产区综合 | 91成人福利 | 欧在线一二三四区 | 另类综合视频在线 | 欧美自拍日韩高清 | 日本欧美中文幕 | 国产经典| 殴美在线观看乱操 | 91传媒 | 国产欧美日本在线 | 国产精选视频网 | 午夜影院在线看 | 日本一线二线 | 福利区体验5分钟 | 91老熟女对白露脸 | 国产91剧情 | 欧美日韩看片 | 成人福利精品在线 | 国产精品夜夜春夜夜 | 国产福利电影网 | 蜜桃A∨ | 日韩精品免 | 91九色字幕资源网 | 黑人在线视频 | 日韩精品真人荷官 | 噼里啪啦国语 | 日韩中文字幕在线 | 人禽乱交| 国产二三| 欧美日韩黄 | 国产欧美日韩在 | 国产亚洲色 | 欧美一级日韩精品 | 午夜免费体验 | 91精品国产福利 | 精品福利一 |