Rumah Java javaTutorial Bagaimana untuk mengintegrasikan pagehelper dalam Springboot2

Bagaimana untuk mengintegrasikan pagehelper dalam Springboot2

May 21, 2023 pm 09:43 PM
springboot pagehelper

1. pom.xml

<?xml  version="1.0" encoding="UTF-8"?>
<project>
  <modelversion>4.0.0</modelversion>
  <parent>
    <groupid>org.springframework.boot</groupid>
    <artifactid>spring-boot-starter-parent</artifactid>
    <version>2.2.1.RELEASE</version>
    <relativepath></relativepath> <!-- lookup parent from repository -->
  </parent>
  <groupid>qinfeng.zheng</groupid>
  <artifactid>learn-pagequery</artifactid>
  <version>0.0.1-SNAPSHOT</version>
  <name>learn-pagequery</name>
  <description>Demo project for Spring Boot</description>

  <properties>
    <java.version>1.8</java.version>
  </properties>

  <dependencies>
    <dependency>
      <groupid>org.springframework.boot</groupid>
      <artifactid>spring-boot-starter-web</artifactid>
    </dependency>
    <dependency>
      <groupid>org.mybatis.spring.boot</groupid>
      <artifactid>mybatis-spring-boot-starter</artifactid>
      <version>1.3.2</version>
    </dependency>
    <dependency>
      <groupid>mysql</groupid>
      <artifactid>mysql-connector-java</artifactid>
      <version>5.1.47</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupid>org.springframework.boot</groupid>
      <artifactid>spring-boot-starter-test</artifactid>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupid>org.junit.vintage</groupid>
          <artifactid>junit-vintage-engine</artifactid>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupid>com.github.pagehelper</groupid>
      <artifactid>pagehelper-spring-boot-starter</artifactid>
      <version>1.2.12</version>
    </dependency>

  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupid>org.springframework.boot</groupid>
        <artifactid>spring-boot-maven-plugin</artifactid>
      </plugin>
    </plugins>
  </build>

</project>
Salin selepas log masuk

2. application.peroperties

#pagehelper
pagehelper.helper-dialect=mysql
pagehelper.params=count= countSql
pagehelper.reasonable=true
pagehelper.support-methods-arguments=true

#mysql
spring.datasource.driver-class-name = com.mysql.jdbc.Driver
spring.datasource.url= jdbc:mysql://120.79.xx.xx:3306/test?useUnicode=yes&characterEncoding=UTF-8&useSSL=false
spring.datasource.username = root
spring.datasource. kata laluan = 1212212

3 Kelas entiti

public class Country implements Serializable {
  private static final long serialVersionUID = 6569081236403751407L;

  private int  id;
  private String countryname;
  private String countrycode;

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getCountryname() {
    return countryname;
  }

  public void setCountryname(String countryname) {
    this.countryname = countryname;
  }

  public String getCountrycode() {
    return countrycode;
  }

  public void setCountrycode(String countrycode) {
    this.countrycode = countrycode;
  }
}
Salin selepas log masuk

4, kelas antara muka pemeta

@Mapper
public interface CountryMapper {
  @Select("select * from country")
  List<country> findAll();

}</country>
Salin selepas log masuk

5

Terus salin data rasmi

@RestController
public class CountryController {
  @Autowired
  private CountryMapper countryMapper;

  @GetMapping("/findAll")
  public List<country> findAll(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "20") Integer pageSize) {
    PageHelper.startPage(pageNum, pageSize);
    List<country> countries = countryMapper.findAll();

    Page page = (Page) countries;
    System.out.println("每页展示条数:" + page.getPageSize());
    System.out.println("总条数:" + page.getTotal());
    System.out.println("当前页:" + page.getPageNum());
    System.out.println("总页数:" + page.getPages());

    return countries;
  }
}</country></country>
Salin selepas log masuk

Baiklah, semuanya sudah siap, mulakan projek springboot, akses pelayar, perhatikan pencetakan dalam pengawal

Permintaan pertama:

Bagaimana untuk mengintegrasikan pagehelper dalam Springboot2cetakan pengawal:

Bagaimana untuk mengintegrasikan pagehelper dalam Springboot2Permintaan kedua:

Bagaimana untuk mengintegrasikan pagehelper dalam Springboot2Cetak pengawal:

Bagaimana untuk mengintegrasikan pagehelper dalam Springboot2OK, pengesahan selesai! Sempurna! ! !

Tambahan:

Apabila melakukan fungsi paging, pemalam halaman muka depan secara amnya memerlukan beberapa data seperti bilangan halaman semasa, jumlah item dan jumlah bilangan daripada halaman. Dalam kes ini, anda boleh merujuk kepada PageInfo, yang boleh memenuhi sepenuhnya keperluan paging bagi pemalam.

drop table country if exists;

create table country (
 id int primary key auto_increment,
 countryname varchar(32),
 countrycode varchar(2)
);

insert into country (id, countryname, countrycode) values(1,'Angola','AO');
insert into country (id, countryname, countrycode) values(2,'Afghanistan','AF');
insert into country (id, countryname, countrycode) values(3,'Albania','AL');
insert into country (id, countryname, countrycode) values(4,'Algeria','DZ');
insert into country (id, countryname, countrycode) values(5,'Andorra','AD');
insert into country (id, countryname, countrycode) values(6,'Anguilla','AI');
insert into country (id, countryname, countrycode) values(7,'Antigua and Barbuda','AG');
insert into country (id, countryname, countrycode) values(8,'Argentina','AR');
insert into country (id, countryname, countrycode) values(9,'Armenia','AM');
insert into country (id, countryname, countrycode) values(10,'Australia','AU');
insert into country (id, countryname, countrycode) values(11,'Austria','AT');
insert into country (id, countryname, countrycode) values(12,'Azerbaijan','AZ');
insert into country (id, countryname, countrycode) values(13,'Bahamas','BS');
insert into country (id, countryname, countrycode) values(14,'Bahrain','BH');
insert into country (id, countryname, countrycode) values(15,'Bangladesh','BD');
insert into country (id, countryname, countrycode) values(16,'Barbados','BB');
insert into country (id, countryname, countrycode) values(17,'Belarus','BY');
insert into country (id, countryname, countrycode) values(18,'Belgium','BE');
insert into country (id, countryname, countrycode) values(19,'Belize','BZ');
insert into country (id, countryname, countrycode) values(20,'Benin','BJ');
insert into country (id, countryname, countrycode) values(21,'Bermuda Is.','BM');
insert into country (id, countryname, countrycode) values(22,'Bolivia','BO');
insert into country (id, countryname, countrycode) values(23,'Botswana','BW');
insert into country (id, countryname, countrycode) values(24,'Brazil','BR');
insert into country (id, countryname, countrycode) values(25,'Brunei','BN');
insert into country (id, countryname, countrycode) values(26,'Bulgaria','BG');
insert into country (id, countryname, countrycode) values(27,'Burkina-faso','BF');
insert into country (id, countryname, countrycode) values(28,'Burma','MM');
insert into country (id, countryname, countrycode) values(29,'Burundi','BI');
insert into country (id, countryname, countrycode) values(30,'Cameroon','CM');
insert into country (id, countryname, countrycode) values(31,'Canada','CA');
insert into country (id, countryname, countrycode) values(32,'Central African Republic','CF');
insert into country (id, countryname, countrycode) values(33,'Chad','TD');
insert into country (id, countryname, countrycode) values(34,'Chile','CL');
insert into country (id, countryname, countrycode) values(35,'China','CN');
insert into country (id, countryname, countrycode) values(36,'Colombia','CO');
insert into country (id, countryname, countrycode) values(37,'Congo','CG');
insert into country (id, countryname, countrycode) values(38,'Cook Is.','CK');
insert into country (id, countryname, countrycode) values(39,'Costa Rica','CR');
insert into country (id, countryname, countrycode) values(40,'Cuba','CU');
insert into country (id, countryname, countrycode) values(41,'Cyprus','CY');
insert into country (id, countryname, countrycode) values(42,'Czech Republic','CZ');
insert into country (id, countryname, countrycode) values(43,'Denmark','DK');
insert into country (id, countryname, countrycode) values(44,'Djibouti','DJ');
insert into country (id, countryname, countrycode) values(45,'Dominica Rep.','DO');
insert into country (id, countryname, countrycode) values(46,'Ecuador','EC');
insert into country (id, countryname, countrycode) values(47,'Egypt','EG');
insert into country (id, countryname, countrycode) values(48,'EI Salvador','SV');
insert into country (id, countryname, countrycode) values(49,'Estonia','EE');
insert into country (id, countryname, countrycode) values(50,'Ethiopia','ET');
insert into country (id, countryname, countrycode) values(51,'Fiji','FJ');
insert into country (id, countryname, countrycode) values(52,'Finland','FI');
insert into country (id, countryname, countrycode) values(53,'France','FR');
insert into country (id, countryname, countrycode) values(54,'French Guiana','GF');
insert into country (id, countryname, countrycode) values(55,'Gabon','GA');
insert into country (id, countryname, countrycode) values(56,'Gambia','GM');
insert into country (id, countryname, countrycode) values(57,'Georgia','GE');
insert into country (id, countryname, countrycode) values(58,'Germany','DE');
insert into country (id, countryname, countrycode) values(59,'Ghana','GH');
insert into country (id, countryname, countrycode) values(60,'Gibraltar','GI');
insert into country (id, countryname, countrycode) values(61,'Greece','GR');
insert into country (id, countryname, countrycode) values(62,'Grenada','GD');
insert into country (id, countryname, countrycode) values(63,'Guam','GU');
insert into country (id, countryname, countrycode) values(64,'Guatemala','GT');
insert into country (id, countryname, countrycode) values(65,'Guinea','GN');
insert into country (id, countryname, countrycode) values(66,'Guyana','GY');
insert into country (id, countryname, countrycode) values(67,'Haiti','HT');
insert into country (id, countryname, countrycode) values(68,'Honduras','HN');
insert into country (id, countryname, countrycode) values(69,'Hongkong','HK');
insert into country (id, countryname, countrycode) values(70,'Hungary','HU');
insert into country (id, countryname, countrycode) values(71,'Iceland','IS');
insert into country (id, countryname, countrycode) values(72,'India','IN');
insert into country (id, countryname, countrycode) values(73,'Indonesia','ID');
insert into country (id, countryname, countrycode) values(74,'Iran','IR');
insert into country (id, countryname, countrycode) values(75,'Iraq','IQ');
insert into country (id, countryname, countrycode) values(76,'Ireland','IE');
insert into country (id, countryname, countrycode) values(77,'Israel','IL');
insert into country (id, countryname, countrycode) values(78,'Italy','IT');
insert into country (id, countryname, countrycode) values(79,'Jamaica','JM');
insert into country (id, countryname, countrycode) values(80,'Japan','JP');
insert into country (id, countryname, countrycode) values(81,'Jordan','JO');
insert into country (id, countryname, countrycode) values(82,'Kampuchea (Cambodia )','KH');
insert into country (id, countryname, countrycode) values(83,'Kazakstan','KZ');
insert into country (id, countryname, countrycode) values(84,'Kenya','KE');
insert into country (id, countryname, countrycode) values(85,'Korea','KR');
insert into country (id, countryname, countrycode) values(86,'Kuwait','KW');
insert into country (id, countryname, countrycode) values(87,'Kyrgyzstan','KG');
insert into country (id, countryname, countrycode) values(88,'Laos','LA');
insert into country (id, countryname, countrycode) values(89,'Latvia','LV');
insert into country (id, countryname, countrycode) values(90,'Lebanon','LB');
insert into country (id, countryname, countrycode) values(91,'Lesotho','LS');
insert into country (id, countryname, countrycode) values(92,'Liberia','LR');
insert into country (id, countryname, countrycode) values(93,'Libya','LY');
insert into country (id, countryname, countrycode) values(94,'Liechtenstein','LI');
insert into country (id, countryname, countrycode) values(95,'Lithuania','LT');
insert into country (id, countryname, countrycode) values(96,'Luxembourg','LU');
insert into country (id, countryname, countrycode) values(97,'Macao','MO');
insert into country (id, countryname, countrycode) values(98,'Madagascar','MG');
insert into country (id, countryname, countrycode) values(99,'Malawi','MW');
insert into country (id, countryname, countrycode) values(100,'Malaysia','MY');
insert into country (id, countryname, countrycode) values(101,'Maldives','MV');
insert into country (id, countryname, countrycode) values(102,'Mali','ML');
insert into country (id, countryname, countrycode) values(103,'Malta','MT');
insert into country (id, countryname, countrycode) values(104,'Mauritius','MU');
insert into country (id, countryname, countrycode) values(105,'Mexico','MX');
insert into country (id, countryname, countrycode) values(106,'Moldova, Republic of','MD');
insert into country (id, countryname, countrycode) values(107,'Monaco','MC');
insert into country (id, countryname, countrycode) values(108,'Mongolia','MN');
insert into country (id, countryname, countrycode) values(109,'Montserrat Is','MS');
insert into country (id, countryname, countrycode) values(110,'Morocco','MA');
insert into country (id, countryname, countrycode) values(111,'Mozambique','MZ');
insert into country (id, countryname, countrycode) values(112,'Namibia','NA');
insert into country (id, countryname, countrycode) values(113,'Nauru','NR');
insert into country (id, countryname, countrycode) values(114,'Nepal','NP');
insert into country (id, countryname, countrycode) values(115,'Netherlands','NL');
insert into country (id, countryname, countrycode) values(116,'New Zealand','NZ');
insert into country (id, countryname, countrycode) values(117,'Nicaragua','NI');
insert into country (id, countryname, countrycode) values(118,'Niger','NE');
insert into country (id, countryname, countrycode) values(119,'Nigeria','NG');
insert into country (id, countryname, countrycode) values(120,'North Korea','KP');
insert into country (id, countryname, countrycode) values(121,'Norway','NO');
insert into country (id, countryname, countrycode) values(122,'Oman','OM');
insert into country (id, countryname, countrycode) values(123,'Pakistan','PK');
insert into country (id, countryname, countrycode) values(124,'Panama','PA');
insert into country (id, countryname, countrycode) values(125,'Papua New Cuinea','PG');
insert into country (id, countryname, countrycode) values(126,'Paraguay','PY');
insert into country (id, countryname, countrycode) values(127,'Peru','PE');
insert into country (id, countryname, countrycode) values(128,'Philippines','PH');
insert into country (id, countryname, countrycode) values(129,'Poland','PL');
insert into country (id, countryname, countrycode) values(130,'French Polynesia','PF');
insert into country (id, countryname, countrycode) values(131,'Portugal','PT');
insert into country (id, countryname, countrycode) values(132,'Puerto Rico','PR');
insert into country (id, countryname, countrycode) values(133,'Qatar','QA');
insert into country (id, countryname, countrycode) values(134,'Romania','RO');
insert into country (id, countryname, countrycode) values(135,'Russia','RU');
insert into country (id, countryname, countrycode) values(136,'Saint Lueia','LC');
insert into country (id, countryname, countrycode) values(137,'Saint Vincent','VC');
insert into country (id, countryname, countrycode) values(138,'San Marino','SM');
insert into country (id, countryname, countrycode) values(139,'Sao Tome and Principe','ST');
insert into country (id, countryname, countrycode) values(140,'Saudi Arabia','SA');
insert into country (id, countryname, countrycode) values(141,'Senegal','SN');
insert into country (id, countryname, countrycode) values(142,'Seychelles','SC');
insert into country (id, countryname, countrycode) values(143,'Sierra Leone','SL');
insert into country (id, countryname, countrycode) values(144,'Singapore','SG');
insert into country (id, countryname, countrycode) values(145,'Slovakia','SK');
insert into country (id, countryname, countrycode) values(146,'Slovenia','SI');
insert into country (id, countryname, countrycode) values(147,'Solomon Is','SB');
insert into country (id, countryname, countrycode) values(148,'Somali','SO');
insert into country (id, countryname, countrycode) values(149,'South Africa','ZA');
insert into country (id, countryname, countrycode) values(150,'Spain','ES');
insert into country (id, countryname, countrycode) values(151,'Sri Lanka','LK');
insert into country (id, countryname, countrycode) values(152,'St.Lucia','LC');
insert into country (id, countryname, countrycode) values(153,'St.Vincent','VC');
insert into country (id, countryname, countrycode) values(154,'Sudan','SD');
insert into country (id, countryname, countrycode) values(155,'Suriname','SR');
insert into country (id, countryname, countrycode) values(156,'Swaziland','SZ');
insert into country (id, countryname, countrycode) values(157,'Sweden','SE');
insert into country (id, countryname, countrycode) values(158,'Switzerland','CH');
insert into country (id, countryname, countrycode) values(159,'Syria','SY');
insert into country (id, countryname, countrycode) values(160,'Taiwan','TW');
insert into country (id, countryname, countrycode) values(161,'Tajikstan','TJ');
insert into country (id, countryname, countrycode) values(162,'Tanzania','TZ');
insert into country (id, countryname, countrycode) values(163,'Thailand','TH');
insert into country (id, countryname, countrycode) values(164,'Togo','TG');
insert into country (id, countryname, countrycode) values(165,'Tonga','TO');
insert into country (id, countryname, countrycode) values(166,'Trinidad and Tobago','TT');
insert into country (id, countryname, countrycode) values(167,'Tunisia','TN');
insert into country (id, countryname, countrycode) values(168,'Turkey','TR');
insert into country (id, countryname, countrycode) values(169,'Turkmenistan','TM');
insert into country (id, countryname, countrycode) values(170,'Uganda','UG');
insert into country (id, countryname, countrycode) values(171,'Ukraine','UA');
insert into country (id, countryname, countrycode) values(172,'United Arab Emirates','AE');
insert into country (id, countryname, countrycode) values(173,'United Kiongdom','GB');
insert into country (id, countryname, countrycode) values(174,'United States of America','US');
insert into country (id, countryname, countrycode) values(175,'Uruguay','UY');
insert into country (id, countryname, countrycode) values(176,'Uzbekistan','UZ');
insert into country (id, countryname, countrycode) values(177,'Venezuela','VE');
insert into country (id, countryname, countrycode) values(178,'Vietnam','VN');
insert into country (id, countryname, countrycode) values(179,'Yemen','YE');
insert into country (id, countryname, countrycode) values(180,'Yugoslavia','YU');
insert into country (id, countryname, countrycode) values(181,'Zimbabwe','ZW');
insert into country (id, countryname, countrycode) values(182,'Zaire','ZR');
insert into country (id, countryname, countrycode) values(183,'Zambia','ZM');
Salin selepas log masuk

Ujian permintaan:

Bagaimana untuk mengintegrasikan pagehelper dalam Springboot2Melihat kod sumber kelas PageInfo, tidak sukar untuk mendapati ia mempunyai sokongan atribut komprehensif untuk bahagian hadapan- tamatkan pemalam paging

@GetMapping("/findAll")
  public PageInfo<country> findAll(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "20") Integer pageSize) {
    PageHelper.startPage(pageNum, pageSize);
    List<country> countries = countryMapper.findAll();

//    Page page = (Page) countries;
//    System.out.println("每页展示条数:" + page.getPageSize());
//    System.out.println("总条数:" + page.getTotal());
//    System.out.println("当前页:" + page.getPageNum());
//    System.out.println("总页数:" + page.getPages());
    PageInfo<country> result = new PageInfo(countries);
    return result;
  }</country></country></country>
Salin selepas log masuk

Atas ialah kandungan terperinci Bagaimana untuk mengintegrasikan pagehelper dalam Springboot2. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn

Alat AI Hot

Undresser.AI Undress

Undresser.AI Undress

Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover

AI Clothes Remover

Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Undress AI Tool

Undress AI Tool

Gambar buka pakaian secara percuma

Clothoff.io

Clothoff.io

Penyingkiran pakaian AI

AI Hentai Generator

AI Hentai Generator

Menjana ai hentai secara percuma.

Artikel Panas

R.E.P.O. Kristal tenaga dijelaskan dan apa yang mereka lakukan (kristal kuning)
3 minggu yang lalu By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Tetapan grafik terbaik
3 minggu yang lalu By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Cara Memperbaiki Audio Jika anda tidak dapat mendengar sesiapa
3 minggu yang lalu By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: Cara Membuka Segala -galanya Di Myrise
3 minggu yang lalu By 尊渡假赌尊渡假赌尊渡假赌

Alat panas

Notepad++7.3.1

Notepad++7.3.1

Editor kod yang mudah digunakan dan percuma

SublimeText3 versi Cina

SublimeText3 versi Cina

Versi Cina, sangat mudah digunakan

Hantar Studio 13.0.1

Hantar Studio 13.0.1

Persekitaran pembangunan bersepadu PHP yang berkuasa

Dreamweaver CS6

Dreamweaver CS6

Alat pembangunan web visual

SublimeText3 versi Mac

SublimeText3 versi Mac

Perisian penyuntingan kod peringkat Tuhan (SublimeText3)

Bagaimana Springboot menyepadukan Jasypt untuk melaksanakan penyulitan fail konfigurasi Bagaimana Springboot menyepadukan Jasypt untuk melaksanakan penyulitan fail konfigurasi Jun 01, 2023 am 08:55 AM

Pengenalan kepada Jasypt Jasypt ialah perpustakaan java yang membenarkan pembangun menambah fungsi penyulitan asas pada projeknya dengan usaha yang minimum dan tidak memerlukan pemahaman yang mendalam tentang cara penyulitan berfungsi dengan tinggi untuk penyulitan sehala dan dua hala. teknologi penyulitan berasaskan piawai. Sulitkan kata laluan, teks, nombor, perduaan... Sesuai untuk penyepaduan ke dalam aplikasi berasaskan Spring, API terbuka, untuk digunakan dengan mana-mana pembekal JCE... Tambahkan kebergantungan berikut: com.github.ulisesbocchiojasypt-spring-boot-starter2 Faedah Jasypt melindungi keselamatan sistem kami Walaupun kod itu bocor, sumber data boleh dijamin.

Bagaimana SpringBoot menyepadukan Redisson untuk melaksanakan baris gilir kelewatan Bagaimana SpringBoot menyepadukan Redisson untuk melaksanakan baris gilir kelewatan May 30, 2023 pm 02:40 PM

Senario penggunaan 1. Tempahan berjaya dibuat tetapi pembayaran tidak dibuat dalam masa 30 minit. Pembayaran tamat masa dan pesanan dibatalkan secara automatik 2. Pesanan telah ditandatangani dan tiada penilaian dilakukan selama 7 hari selepas ditandatangani. Jika pesanan tamat dan tidak dinilai, sistem lalai kepada penilaian positif 3. Pesanan dibuat dengan jayanya jika peniaga tidak menerima pesanan selama 5 minit, pesanan itu dibatalkan peringatan mesej teks dihantar... Untuk senario dengan kelewatan yang lama dan prestasi masa nyata yang rendah, kami boleh Gunakan penjadualan tugas untuk melaksanakan pemprosesan undian biasa. Contohnya: xxl-job Hari ini kita akan memilih

Cara menggunakan Redis untuk melaksanakan kunci teragih dalam SpringBoot Cara menggunakan Redis untuk melaksanakan kunci teragih dalam SpringBoot Jun 03, 2023 am 08:16 AM

1. Redis melaksanakan prinsip kunci teragih dan mengapa kunci teragih diperlukan Sebelum bercakap tentang kunci teragih, adalah perlu untuk menjelaskan mengapa kunci teragih diperlukan. Lawan daripada kunci yang diedarkan ialah kunci yang berdiri sendiri Apabila kami menulis program berbilang benang, kami mengelakkan masalah data yang disebabkan oleh mengendalikan pembolehubah yang dikongsi pada masa yang sama Kami biasanya menggunakan kunci untuk mengecualikan pembolehubah yang dikongsi bersama untuk memastikan ketepatannya pembolehubah yang dikongsi skop penggunaannya adalah dalam proses yang sama. Jika terdapat berbilang proses yang perlu mengendalikan sumber yang dikongsi pada masa yang sama, bagaimanakah ia boleh saling eksklusif? Aplikasi perniagaan hari ini biasanya merupakan seni bina perkhidmatan mikro, yang juga bermakna bahawa satu aplikasi akan menggunakan berbilang proses Jika berbilang proses perlu mengubah suai baris rekod yang sama dalam MySQL, untuk mengelakkan data kotor yang disebabkan oleh operasi yang tidak teratur, keperluan pengedaran. untuk diperkenalkan pada masa ini. Gaya dikunci. Ingin mencapai mata

Bagaimana untuk menyelesaikan masalah bahawa springboot tidak boleh mengakses fail selepas membacanya ke dalam pakej balang Bagaimana untuk menyelesaikan masalah bahawa springboot tidak boleh mengakses fail selepas membacanya ke dalam pakej balang Jun 03, 2023 pm 04:38 PM

Springboot membaca fail, tetapi tidak boleh mengakses perkembangan terkini selepas membungkusnya ke dalam pakej balang Terdapat situasi di mana springboot tidak boleh membaca fail selepas membungkusnya ke dalam pakej balang adalah tidak sah dan hanya boleh diakses melalui strim. Fail berada di bawah resources publicvoidtest(){Listnames=newArrayList();InputStreamReaderread=null;try{ClassPathResourceresource=newClassPathResource("name.txt");Input

Bagaimana untuk melaksanakan Springboot+Mybatis-plus tanpa menggunakan pernyataan SQL untuk menambah berbilang jadual Bagaimana untuk melaksanakan Springboot+Mybatis-plus tanpa menggunakan pernyataan SQL untuk menambah berbilang jadual Jun 02, 2023 am 11:07 AM

Apabila Springboot+Mybatis-plus tidak menggunakan pernyataan SQL untuk melaksanakan operasi penambahan berbilang jadual, masalah yang saya hadapi akan terurai dengan mensimulasikan pemikiran dalam persekitaran ujian: Cipta objek BrandDTO dengan parameter untuk mensimulasikan parameter yang dihantar ke latar belakang bahawa adalah amat sukar untuk melaksanakan operasi berbilang jadual dalam Mybatis-plus Jika anda tidak menggunakan alatan seperti Mybatis-plus-join, anda hanya boleh mengkonfigurasi fail Mapper.xml yang sepadan dan mengkonfigurasi ResultMap yang berbau dan kemudian. tulis pernyataan sql yang sepadan Walaupun kaedah ini kelihatan menyusahkan, ia sangat fleksibel dan membolehkan kita

Analisis perbandingan dan perbezaan antara SpringBoot dan SpringMVC Analisis perbandingan dan perbezaan antara SpringBoot dan SpringMVC Dec 29, 2023 am 11:02 AM

SpringBoot dan SpringMVC adalah kedua-dua rangka kerja yang biasa digunakan dalam pembangunan Java, tetapi terdapat beberapa perbezaan yang jelas antara mereka. Artikel ini akan meneroka ciri dan penggunaan kedua-dua rangka kerja ini dan membandingkan perbezaannya. Mula-mula, mari belajar tentang SpringBoot. SpringBoot telah dibangunkan oleh pasukan Pivotal untuk memudahkan penciptaan dan penggunaan aplikasi berdasarkan rangka kerja Spring. Ia menyediakan cara yang pantas dan ringan untuk membina bersendirian, boleh dilaksanakan

Bagaimana SpringBoot menyesuaikan Redis untuk melaksanakan penyirian cache Bagaimana SpringBoot menyesuaikan Redis untuk melaksanakan penyirian cache Jun 03, 2023 am 11:32 AM

1. Sesuaikan RedisTemplate1.1, mekanisme siri lalai RedisAPI Pelaksanaan cache Redis berasaskan API menggunakan templat RedisTemplate untuk operasi cache data Di sini, buka kelas RedisTemplate dan lihat maklumat kod sumber kelas tersebut. Isytihar kunci, Pelbagai kaedah pesirilan nilai, nilai awal kosong @NullableprivateRedisSe

Bagaimana untuk mendapatkan nilai dalam application.yml dalam springboot Bagaimana untuk mendapatkan nilai dalam application.yml dalam springboot Jun 03, 2023 pm 06:43 PM

Dalam projek, beberapa maklumat konfigurasi sering diperlukan Maklumat ini mungkin mempunyai konfigurasi yang berbeza dalam persekitaran ujian dan persekitaran pengeluaran, dan mungkin perlu diubah suai kemudian berdasarkan keadaan perniagaan sebenar. Kami tidak boleh mengekodkan konfigurasi ini dalam kod. Adalah lebih baik untuk menulisnya dalam fail konfigurasi Sebagai contoh, anda boleh menulis maklumat ini dalam fail application.yml. Jadi, bagaimana untuk mendapatkan atau menggunakan alamat ini dalam kod? Terdapat 2 kaedah. Kaedah 1: Kita boleh mendapatkan nilai yang sepadan dengan kunci dalam fail konfigurasi (application.yml) melalui ${key} beranotasi dengan @Value Kaedah ini sesuai untuk situasi di mana terdapat sedikit perkhidmatan mikro projek, Apabila perniagaan adalah rumit, logik

See all articles