springboot+jpa+mysql的小例子

model/user层

镜像数据库

package com.alphaz.core.pojo.viewmodel.prepay;import javax.persistence.*;
import java.math.BigDecimal;@Entity(name = "tb_prepaybill")
public class PrepayBillModel  {@Id@GeneratedValue(strategy = GenerationType.IDENTITY)private Long enterpriseid;private String ssq;private Integer jzzt;private String billno;private Integer incomeState;private Long xmid;private Integer zsfs;private BigDecimal xssr;private String xssl;private String yjsl;private BigDecimal fbk;private BigDecimal yjzzs;private BigDecimal sjyjzzs;private String bz;public Long getEnterpriseid() {return enterpriseid;}public void setEnterpriseid(Long enterpriseid) {this.enterpriseid = enterpriseid;}public String getSsq() {return ssq;}public void setSsq(String ssq) {this.ssq = ssq;}public Integer getJzzt() {return jzzt;}public void setJzzt(Integer jzzt) {this.jzzt = jzzt;}public String getBillno() {return billno;}public void setBillno(String billno) {this.billno = billno;}public Integer getIncomeState() {return incomeState;}public void setIncomeState(Integer incomeState) {this.incomeState = incomeState;}public Long getXmid() {return xmid;}public void setXmid(Long xmid) {this.xmid = xmid;}public Integer getZsfs() { return zsfs; }public void setZsfs(Integer zsfs) { this.zsfs = zsfs; }public BigDecimal getXssr() { return xssr; }public void setXssr(BigDecimal xssr) { this.xssr = xssr; }public String getXssl() { return xssl; }public void setXssl(String xssl) { this.xssl = xssl; }public String getYjsl() { return yjsl; }public void setYjsl(String yjsl) { this.yjsl = yjsl; }public BigDecimal getFbk() { return fbk; }public void setFbk(BigDecimal fbk) { this.fbk = fbk; }public BigDecimal getYjzzs() { return yjzzs; }public void setYjzzs(BigDecimal yjzzs) { this.yjzzs = yjzzs; }public BigDecimal getSjyjzzs() { return sjyjzzs; }public void setSjyjzzs(BigDecimal sjyjzzs) { this.yjzzs = sjyjzzs; }public String getBz() { return bz; }public void setBz(String bz) { this.bz = bz; }@Overridepublic String toString() {return "PrepayBillModel{" +"enterpriseid=" + enterpriseid +", ssq='" + ssq + '\'' +", jzzt=" + jzzt +", billno='" + billno + '\'' +", incomeState=" + incomeState +", xmid=" + xmid +", zsfs=" + zsfs +", xssr=" + xssr +", xssl='" + xssl + '\'' +", yjsl='" + yjsl + '\'' +", fbk=" + fbk +", yjzzs=" + yjzzs +", sjyjzzs=" + sjyjzzs +", bz='" + bz + '\'' +'}';}
}

Dao层

别忘了继承jpa类(提供一系列数据库操作方法)

package com.alphaz.core.dao;import com.alphaz.core.pojo.viewmodel.prepay.PrepayBillModel;
import org.mapstruct.Mapper;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;import java.util.List;@Mapperpublic interface PrepayBillDAO extends JpaRepository<PrepayBillModel,Integer> {List<PrepayBillModel> getPrepayBillModelsByXmid(String xmid);List<PrepayBillModel> getPrepayBillModelsBySsq(String ssq);List<PrepayBillModel> getPrepayBillModelsByBillno(String billno);@Query("select b from tb_prepaybill b where b.xmid=:xmid and b.ssq=:ssq")List<PrepayBillModel> getPrepayBillModelsByXmidAndSsq(String xmid,String ssq);@Query("select b from tb_prepaybill b where b.xmid=:xmid and b.ssq=:ssq")List<PrepayBillModel> getPrepayBillModelsByBillnoAndSsq(String billno,String ssq);@Query("select b from tb_prepaybill b where b.xmid=:xmid and b.ssq=:ssq")List<PrepayBillModel> getPrepayBillModelsByBillnoAndXmid(String billno,String xmid);@Query("select b from tb_prepaybill b where b.xmid=:xmid and b.ssq=:ssq")List<PrepayBillModel> getPrepayBillModelsByBillnoAndXmidaAndSsq(String billno,String xmid,String ssq);}

service层

package com.alphaz.core.service;import com.alphaz.core.dao.PrepayBillDAO;import com.alphaz.core.pojo.viewmodel.prepay.PrepayBillModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;import java.util.List;@Servicepublic class PrepayBillService {@AutowiredPrepayBillDAO prepayBillDAO ;public void addprepaybill(PrepayBillModel prepayBillModel) {prepayBillDAO.save(prepayBillModel);}public Page<PrepayBillModel> getPrepayBillModelByPage(Pageable pageable) {return prepayBillDAO.findAll(pageable);}public List<PrepayBillModel> getPrepayBillModelsByXmid(String xmid){return prepayBillDAO.getPrepayBillModelsByXmid(xmid);}public List<PrepayBillModel> getPrepayBillModelsBySsq(String ssq){return prepayBillDAO.getPrepayBillModelsBySsq(ssq);}public List<PrepayBillModel> getPrepayBillModelsByXmidAndSsq(String xmid,String ssq){return prepayBillDAO.getPrepayBillModelsByXmidAndSsq(xmid,ssq);}public List<PrepayBillModel> getPrepayBillModelsByBillnoAndSsq(String billno,String ssq){return prepayBillDAO.getPrepayBillModelsByBillnoAndSsq(billno,ssq);}public List<PrepayBillModel> getPrepayBillModelsByBillnoAndXmid(String billno,String xmid){return prepayBillDAO.getPrepayBillModelsByBillnoAndXmid(billno,xmid);}public List<PrepayBillModel> getPrepayBillModelsByBillnoAndXmidaAndSsq(String billno,String xmid,String ssq){return prepayBillDAO.getPrepayBillModelsByBillnoAndXmidaAndSsq(billno,xmid,ssq);}}

controller层

package com.alphaz.app.controller;import com.alphaz.core.pojo.viewmodel.prepay.PrepayBillModel;
import com.alphaz.core.service.PrepayBillService;
import com.alphaz.core.utils.redis.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import javax.annotation.Resource;
import java.util.List;@RestController
@RequestMapping("/prepay")
public class prepayBillController {@ResourcePrepayBillService prepayBillService;@Autowiredprivate RedisUtil redisUtil;@GetMapping("/findAll")public void findAll(){PageRequest pageable = PageRequest.of(2,3);Page<PrepayBillModel> page =prepayBillService.getPrepayBillModelByPage(pageable);System.out.println("总页数:"+page.getTotalPages());System.out.println("总记录数:"+page.getTotalElements());System.out.println("查询结果:"+page.getContent());System.out.println("当前页数:"+page.getNumber()+1);System.out.println("当前页记录数:"+page.getNumberOfElements());System.out.println("每页记录数:"+page.getSize());}@GetMapping("/search")public void search(){List<PrepayBillModel> bs1 = prepayBillService.getPrepayBillModelsByBillnoAndSsq("1","712");}@GetMapping("/save")public void save(){PrepayBillModel prepayBillModel=new PrepayBillModel();prepayBillModel.setBillno("22");prepayBillService.addprepaybill(prepayBillModel);}
}

springboot+jpa+mysql的小例子相关推荐

  1. springboot+jpa+mysql Springboot+jpa+jdbc+sqlserver 使用时遇到的一系列的问题

    更改背景 正在做一个微信小程序的前后端项目,一开始使用的是springboot+jpa+mysql,但负责接受数据存入数据库的负责人执意要用sqlserver.本来微信小程序前端,以及spring b ...

  2. c语言连接数据库例子,c语言操作mysql数据库小例子_互帮互助(C language MySQL database operation example _ mutual help).doc...

    这是精心收集的精品经典资料,值得下载保存阅读! c语言操作mysql数据库小例子_互帮互助(C language MySQL database operation example _ mutual h ...

  3. springboot+jpa+mysql+redis+swagger整合步骤

    springboot+jpa+MySQL+swagger框架搭建好之上再整合redis: 在电脑上先安装redis: 一.在pom.xml中引入redis 二.在application.yml里配置r ...

  4. springboot jpa mysql大学生兼职网源码+安装视频+讲解视频+效果视频

    项目介绍: springboot jpa mysql大学生兼职网源码+安装视频+讲解视频+效果视频 高清视频演示: https://www.bilibili.com/video/BV1yY4y137U ...

  5. spring jpa mysql集群_微框架:Springboot+Jpa+mysql零基础上手班

    [课前科普百科] 企业的很多技术都是保密的,尤其是实战项目和新兴技术.Springboot是目前互联网薪的技术.Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spr ...

  6. 解决 springboot + JPA + MySQL 表名全大写 出现 “表不存在” 问题(Table ‘XXX.xxx‘ doesn‘t exist)

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. 项目中使用 JPA 和 mysql .表名是全大写的. 出现 如下报错: java.sql.SQLS ...

  7. java小例子mysql_Java 访问MySQL的小例子

    Java访问Mysql,需要有mysql.jar包,这个需要提前准备好.在java中引入mysql.jar有两种方法,下面将详细介绍. (一)新建项目时,通过导入外部jar的方法: (1)打开myec ...

  8. Java 访问MySQL的小例子

    Java访问Mysql,需要有mysql.jar包,这个需要提前准备好.在java中引入mysql.jar有两种方法,下面将详细介绍. (一)新建项目时,通过导入外部jar的方法: (1)打开myec ...

  9. 基于vue2+element+springboot+mybatis+jpa+mysql的学籍管理系统

    目录 整套系统源码下载 一.开发背景 二.用到的技术 三.开发使用的IDE 四.搭建开发环境 五.启动项目 六.学籍管理系统使用说明 七.结语 八.源码下载 基于vue2+element+spring ...

最新文章

  1. swift判断iPhone 各种型号
  2. vs2010连接mongodb服务器,X64位
  3. [转]基于Starling移动项目开发准备工作
  4. [Linux主机] 优化你的php-fpm(php5.3+)让你的网站跑得更快
  5. 推荐:26种NLP练手项目(代码+数据)
  6. 机器学习 | 梯度下降原理及Python实现
  7. 从 ASP.NET Core 2.1 迁移到 2.2 踩坑总结
  8. .NET中操作SQLite
  9. mysql事务操作代码_Mysql中事务的使用【mysql】
  10. Atitit 提升效率 降低技术难度与提升技术矛盾的解决方案 1. 问题 2 1.1. 高手喜欢技术挑战怎么办,但会提升技术难度 导致新手不会用怎么办 2 2. 解决方案 2 2.1. 通过开会统
  11. 蚂蚁课堂视频笔记思维导图-3期 七、互联网高并发解决方案
  12. Linux开机自动启动python脚本程序,或 Jetson nano或Jetson Xavier NX开机自动启动python脚本程序
  13. 解决springboot警告WARNING: All illegal access operations will be denied in a future release
  14. TSV文件与CSV文件的区别
  15. 3060ti配什么cpu和主板
  16. 针对瑞萨单片机编译时空间无法全部使用问题的解决方案
  17. 数据分析画图:50道练习玩转matplotlib
  18. 插件怎么用_室内设计,3dmax插件教程,一键生成木地板
  19. [转载] 发烧了,退烧药该怎么吃?
  20. QT实现窗口置顶、置顶状态切换、多窗口置顶优先关系

热门文章

  1. 目录英文linux,Linux系统各个目录的作用(中英文对照)
  2. 机顶盒桌面服务器,机顶盒桌面源码电视盒子launcher源码
  3. java毕业设计大学生家教平台(附源码、数据库)
  4. 实现简单的带头双向循环链表
  5. 电脑通过手机做Model拨号
  6. 终于等到了 xp黑屏了
  7. Linux内核Thermal框架详解十四、Thermal Governor(4)
  8. 【三星官方教程】如何为Gear VR开发应用(四):场景连接
  9. 【WLAN从入门到精通-基础篇】第7期——AP上线过程
  10. GNSS数据下载网址 汇总大全 [2020.9.22更新]