1. Windows 7 Enterprise Edition
2. Gagasan 14
3. JDK 1.8
4. Maven 3.5.2
5. Mariadb
6. Sqlyog
Tambahkan settings.xml di direktori conf di direktori Maven ke konten berikut:
1. Menggunakan repositori Alibaba Cloud jauh lebih cepat daripada situs web resmi.
<cermin> <dr> nexus-aliyun </d> <cerminof> central </cryrorof> <name> nexus aliyun </name> <rerl> http://maven.aliyun.com/nexus/content/groups/public </url> </mirror>
2. Konfigurasi JDK Global
<!-Konfigurasi JDK Global, settings.xml-> <profile> <den> jdk18 </dr> <activation> <activeByDefault> true </activeByDefault> <jdk> 1.8 </source> </aktivasi> <properties> <vaven.sourse.source> 1.8 </aktivasi> <maven. <maven.compiler.target> 1.8 </maven.compiler.target> <maven.compiler.compilerVersion> 1.8 </maven.compiler.compilerVersion> </ Properties> </ Properties> </ Properties> </profile>
1. Pengaturan Maven: Pilih direktori Maven, dan konfigurasikan file dan repositori lokal secara bersamaan.
2. Pengaturan Pengkodean Karakter
Pilih Aktifkan Auto-Impor dan Buat Direktori Proyek Seperti yang ditunjukkan di bawah ini:
1. Pom.xml
<? Xml Version = "1.0" encoding = "UTF-8"?> <Project xmlns = "http://maven.apache.org/pom/4.0.0" xmlns: xsi = "http://www.w3.org/2001/xmlschema XSI: schemalocation = "http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <ModelVersion> 4.0.0 </modelversion> <groupid> CN.Tempration </ARTICED </ARTICED </ModelVersion> <groupid> cn.temption <version>1.0-SNAPSHOT</version> <!-- Default settings for using spring boot --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.0.RELEASE</version> </parent> <dependencies> <!-- web --> <dependency> <groupid> org.springframework.boot </sroupid> <Artifactid> Spring-boot-starter-web </t Artifactid> </dependency> <!-thymeleaf-> <dependency> <sruptId> <Trupt-st-st-st-st-st-st-st-st-st-st-st-st-starter.boot </groupid> <ArtiFacTid> Spring-st-st-st-st-starter.tymel </groupid> <ArttifactD> Spring-st-st-st-st-st-starter mysql ---> <dependency> <GroupId> mysql </groupId> <ArTifactId> mysql-connector-java </artifactid> <version> 5.1.21 </version> </dependency> <!-jpa-> <groupid> org.springframework.oot </groupid </groupid> <groupid> org.springframework.ooty </groupid </groupid> groupid> groupid> groupid> groupid> groupid> groupid> <groupid> <ArTifactId> Spring-boot-starter-data-jpa </artifactid> </gandendency> </dependencies> </project>
2. Buat Aplikasi Baru. Properti di Direktori Sumber Daya (tentu saja, jika Anda ingin menggunakan YAML, Anda dapat menggunakan YAML)
# Database Connection spring.datasource.url = jdbc: mysql: //127.0.0.1: 3306/testspring.datasource.username = rootspring.dataSource.password = saspring.datasource.driver-class-name = com.mysqor spring.jpa.properties.hibernate.hbm2ddl.auto = Update
3. Buat Kelas Startup Program Springboot SpringbootApplication.java
Paket cn.temptation; impor org.springframework.boot.springapplication; impor org.springframework.boot.autoconfigure.springbootApplication; @springbootApplicationPlic class springbootApplication {public static void Main (string [] args) {public static void Main (string [] args) {{@string [] {public static void (string [] {public static (string [] {public {public {public static void (String [] {public {public {public {public {public {public {public) Springapplication.run (springbootApplication.class, args); }}4. Buat Kategori Kelas Entitas.java
package cn.temptation.model;import javax.persistence.*;// library building table//DROP TABLE category;////CREATE TABLE category//(// categoryid INT AUTO_INCREMENT PRIMARY KEY,// categoryname VARCHAR(10) NOT NULL//);////INSERT INTO category VALUES(NULL, 'mobile'), (NULL, 'book'), (NULL, 'clothing'), (Null, 'shoes'); ///// pilih * dari kategori; @entitas @table (name = "kategori") Kategori kelas publik {@id @generatedValue (strategi = generationType.identity) @column (name = "CategoryId") Private Integer CategoryID; @Column (name = "CategoryName") Private String CategoryName; Integer publik getCategoryId () {return CategoryId; } public void setCategoryId (integer CategoryId) {this.categoryId = CategoryId; } public String getCategoryName () {return CategoryName; } public void setCategoryName (String CategoryName) {this.categoryName = CategoryName; }}5. Buat DAO Interface Categorydao.java
Paket cn.temption.dao; impor cn.temption.model.category; impor org.springframework.data.jpa.repository.jparepository; antarmuka publik Kategoridao memperluas jparepository <kategori, integer> {}6. Buat Controller Class CategoryController.java
Paket cn.temption.web; impor cn.temption.dao.categorydao; impor cn.temption.model.category; impor org.springframework.beans.factory.annotation.Autowired; impor org.springframework.data.page.page; org.springframework.data.domain.pagerequest; impor org.springframework.data.domain.pageable; import org.springframework.data.domain.sort; impor org.springframework.stereotype.controller; org.spapppring. org.springframework.web.bind.annotation.requestparam; impor org.springframework.web.servlet.modelandview; import java.util.list; @controllerpublic ClassController {@Autowired Private CategoryDAo Kategori Public; /** * Permintaan Pemberian Pemberian * * @return * /// @RequestMapping ("/CategoryList") // Public ModelAndView CategoryList () {// List <at kategori> List = CategoryDao.findall (); /////////////////////////////////////// // ModelDView MAV = ListAndView ("CategoryList"); ////////////MAVEW (LAGED NEW ModelAndView ("CategoryList"); mav; //}/** * kueri pagination * * @return */@RequestMapping ("/CategoryList") Public ModelAndView CategoryList (@RequestParam (value = "start", defaultValue = "0") start integer, @requestparam (value = "limit", defaultValue = "0) Integer start, @requestparam (value =" limit ", defaultValue =" 0) start integer, @requestparam (value = "limit", defaultValue = "") start "2) {value =" limit ", DefaultValue =" 2)) 0: mulai; Sort sort = new sort (sort.default_direction, "CategoryId"); Pageable Pagable = PageRequest baru (mulai, batas, sortir); Page<Category> page = categoryDao.findAll(pageable);// System.out.println(page.getNumber());// System.out.println(page.getNumberOfElements());// System.out.println(page.getSize());// System.out.println(page.getTotalElements());// System.out.println (page.gettotalpages ()); // system.out.println (page.isfirst ()); // system.out.println (page.islast ()); ModelAndView mav = new ModelAndView ("CategoryList"); mav.addObject ("halaman", halaman); mengembalikan mav; }/*** Tampilan baru dalam kategori* @return*/@RequestMapping ("/CategoryInit") Public String CategoryInit () {return "CategoryInit"; }/** * Operasi baru dalam kategori * @param Model * @Return */@RequestMapping ("/CategoryInsert") Public String CategoryInSert (Model Kategori) {Categorydao.Save (model); return "Redirect: CategoryList"; }/** * Kategori Hapus operasi * @param CategoryId * @Return */@RequestMapping ("/CategoryDelete") Public String CategoryDelete (Integer CategoryID) {Categorydao.DeletebyId (CategoryID); return "Redirect: CategoryList"; }/** * Tampilan pengeditan kategori * @param CategoryId * @return */@RequestMapping ("/CategoryEdit") Public ModelAndView CategoryEdit (Integer CategoryID) {Category Model = Categorydao.getOne (CategoryID); ModelAndView mav = new ModelAndView ("CategoryEdit"); mav.addObject ("kategori", model); mengembalikan mav; }/** * Operasi pengeditan kategori * @param Model * @Return */@RequestMapping ("/CategoryUpdate") Public String CategoryUpdate (Model Kategori) {Categorydao.Save (model); return "Redirect: CategoryList"; }}7. Buat Direktori Template Baru Di Bawah Direktori Sumber Daya dan Buat Lapisan Presentasi: Halaman Daftar Kategori (CategoryList.html), Kategori Halaman Baru (CategoryInit.html), Halaman Edit Kategori (CategoryEdit.html)
Halaman Kategorylist (CategoryList.html)
<! Doctype html> <html lang = "en"> <head> <meta charset = "UTF-8"> <Title> Daftar Kategori </iteme> <tyle> Tabel, TH, TD {border: 1px solid green; Border-Collapse: runtuh; } </tyle> </head> <body> <a th: href = "@{/CategoryInit}"> Tambahkan </a> <dable> <tr> <th> Nomor Kategori </t> <t th> Nama kategori </t> <th> </t th: {'setiap. <tr th: masing -masing = "item: $ {page.content}"> <td th: text = "$ {item.categoryId}"> Nomor kategori </td> <td th: text = "$ {item.categoryName}"> Nama kategori </td> <td> <td> TH: href = "@{/CategoryEdit (CategoryId = $ {item.categoryId})}"> Edit </a> <a th: href = "@{/kategoriDelete (CategoryId = $ {item.categoryId})}"> Delete </a> </td> </td> </td </td </td </tder> </tdet> </tdet> </tdet> </tder> </tder> </tder> </tder> </tder> </tder> TH: href = "@{/categoryList (start = 0)}"> [home] </a> <a th: if = "$ {not page.isfirst ()}" th: href = "@{/categorylist (start = $ {page.totalpage-1}) {{/no {a no." TH: href = "@{/CategoryList (start = $ {page.number+1})}"> [halaman berikutnya] </a> <a th: href = "@{/categorylist (start = $ {page.totalpages-1)}"> [Halaman terakhir] </a> </div>/Body-}} "> [halaman> </a> </a> </totalpages-Halaman baru untuk kategori (CategoryInit.html)
<! Doctype html> <html lang = "en"> <head> <meta charset = "UTF-8"> <Title> Kategori baru </iteme> </head> <body> <bentuk acti name = "CategoryName"/> <br/> <input type = "kirim" value = "kirim"> </form> </body> </html>
Halaman Edit Kategori (CategoryEdit.html)
<! Doctype html> <html lang = "en"> <head> <meta charset = "utf-8"> <title> Kategori Edit </iteme> </head> <body> <form Action = "CategoryUpdate" Method = "POST"> <input type = "hidden" id = "txtcategory" name = "Post"> <input = "hiddid" id = "txtcategory" name = "POST"> <input = "hiddid" id = "txtcategory" name = "Post" TH: field = "$ {Category.CategoryId}"/> <br/> <label untuk = "txtCategoryName"> Nama kategori: </label> <input type = "text" id = "txtCategoryName" name = "CategoryName" th: field = "$ {category.categoryName}"/" value = "Kirim"> </form> </body> </html>Meringkaskan
Di atas adalah Ide+Maven+Springboot+JPA+Thymeleaf dari CRUD dan Pagination yang diperkenalkan kepada Anda oleh editor. Saya harap ini akan membantu semua orang. Jika Anda memiliki pertanyaan, silakan tinggalkan saya pesan dan editor akan membalas semua orang tepat waktu. Terima kasih banyak atas dukungan Anda ke situs web Wulin.com!