2025年springboot+jpa+mysql的小例子

springboot+jpa+mysql的小例子springboot jpa mysql 的小例子 model user 层 镜像数据库 package com alphaz core pojo viewmodel prepay import javax persistence import java math BigDecimal

大家好,我是讯享网,很高兴认识大家。

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; } @Override public 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; @Mapper public 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; @Service public class PrepayBillService { 
    @Autowired PrepayBillDAO 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 { 
    @Resource PrepayBillService prepayBillService; @Autowired private 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); } } 
小讯
上一篇 2025-03-04 17:20
下一篇 2025-02-26 18:37

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/44865.html