1. Windows 7 Enterprise Edition
2. 아이디어 14
3. JDK 1.8
4. Maven 3.5.2
5. 마리 아드 브
6. Sqlyog
Maven 디렉토리의 conf 디렉토리에 Settings.xml을 다음 내용에 추가하십시오.
1. Alibaba Cloud의 저장소 사용은 공식 웹 사이트보다 훨씬 빠릅니다.
<mirror> <id> Nexus-Aliyun </id> <mirrorof> Central </mirrorof> <name> nexus aliyun </name> <url> http://maven.aliyun.com/nexus/content/groups/public </url> </mirror>
2. 글로벌 JDK 구성
<!-글로벌 JDK 구성, settings.xml-> <profile> <id> jdk18 </id> <활성화> <ctiveBydefault> true </activeByDefault> <JDK> 1.8 </jdk> </activation> <properties> <maven.compiler.source> 1.8 </maven.compiler.source. <maven.compiler.target> 1.8 </maven.compiler.target> <maven.compiler.compilerversion> 1.8 </maven.compiler.compilerversion> </properties> </properties> </profe>
1. Maven 설정 : Maven 디렉토리를 선택하고 동시에 파일 및 로컬 리포지토리를 구성하십시오.
2. 문자 인코딩 설정
자동 임금 활성화를 선택하고 다음과 같이 프로젝트 디렉토리를 만듭니다.
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-instance" xsi : schemalocation = "http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modeversion> 4.0.0 </modelversion> <groupid> cn.temptation </group-stud> <artifactid> <버전> 1.0-snapshot </version> <!-스프링 부팅을 사용하기위한 기본 설정-> <부모> <groupid> org.springframework.boot </groupid> <artifactid> spring-boot-starter-parent </artifactid> <version> 2.0.0.release> </parentmencies> <! <! <groupid> org.springframework.boot </groupid> <artifactid> 스프링-부트-스타터-web </artifactid> </exceentency> <!-thymeleaf-> <prection> <groupId> org.springframework.boot </groupid> </eppoal-bboot-starter-ThomeLeaf </artifactid> </artifactid>. mysql ---> <pectionency> <groupId> mySQL </groupId> <ArtifActId> mySQL-Connector-Java </artifactid> <bersion> version> 5.1.21 </version> </dependency> <!-JPA-> <artifactid> Spring-Boot-Starter-Data-JPA </artifactID> </fectionency> </fectencies> </project>
2. 새로운 응용 프로그램 만들기. 리소스 디렉토리의 프로파일 (물론 Yaml을 사용하려면 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.mysql.jdbc.driver# spring.jpa.properties.hibernate.hbm2ddl.auto = 업데이트
3. SpringBoot 프로그램 시작 클래스 SpringBootApplication.java 만들기
패키지 cn.temptation; import org.springframework.boot.springApplication; import org.springframework.boot.autoconfigure.springbootapplication; @springbootapplicationPublic 클래스 SpringBootApplication {public static void main (string [] args) {// springboot project starting {// springboot project starting SpringApplication.run (SpringBootApplication.class, args); }}4. 엔티티 클래스 카테고리를 작성하십시오
패키지 cn.temptation.model; import javax.persistence.*; // 라이브러리 빌딩 테이블 // 테이블 범주를 드롭 삭제 테이블 범주; /// 테이블 범주 작성 // (// categoryId int auto_increment 기본 키, // 범주 나 이름 varchar (10) null //); //// 'mobile') (null, 'shoes'); //// 선택 *에서 선택 * @entity @table (name = "category") 공개 클래스 카테고리 {@id @generatedValue (rforeing = generationtype.identity) @column (name = "CategoryId") 개인 정수 카테고리; @Column (이름 = "CategoryName") private String categoryName; public integer 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. dao 인터페이스 CategoryDao.java를 만듭니다
패키지 cn.temptation.dao; import cn.temptation.model.category; import org.springframework.data.jpa.repository.jparepository; public interface categorydao는 jparepository <category, integer> {}를 확장합니다.6. 컨트롤러 클래스 CategoryController.java를 만듭니다
패키지 cn.temptation.web; import cn.temptation.dao.categorydao; import cn.temptation.model.category; import org.spramework.beans.beans.annotation.autowired; import org.spramework.data.domain.porgemain.springecrage org.springframework.data.dataain.pageable; import org.springframework.data.datain.sort; import org.spramework.stereotyp.controller; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.bind.bind.bint.bint.bint.bind.bind.bind.bind.bind.bind.bind.bind org.springframework.web.servlet.modelandview; import java.util.list; @controllerpublic class categorycontroller {@autowired private categorydao categorydao; /** * query * * @return * /// @requestmapping ( "/categoryList") // public modelandView categoryList () {// list <category> list = categoryDao.findall (); /// ModelAndView mav = new ModelAndView ( "CategoryList"); // letrOb.AddOb.AddOb.AddOb.AddOb.AddOb.AddOb.AddOb. }/** * Pagination Query * * @return */@requestmapping ( "/categoryList") public modelandView categoryList (@RequestParam (value = "start", defaultValue = "0") 정수 시작, @requestparam (value = "limit", defaultValue = "2") 정수 한계. 0 : 시작; Sort Sort = New Sort (Sort.Default_Direction, "CategoryId"); pageable pagable = new pagerequest (시작, 한계, 정렬); Page <Category> page = categoryDao.Findall (pagable); // system.out.println (page.getNumber ()); // system.out.println (page.getNumberfElements ()); // system.out.println (page.getsize ()); // system.out.println (page.gettotalelement (//)); System.out.println (page.getTotalPages ()); // system.out.println (page.isfirst ()); // system.out.println (page.islast ()); ModelAndView mav = new ModelAndView ( "CategoryList"); mav.addoBject ( "page", page); 반환 mav; }/*** 카테고리의 새로운보기* @return*/@requestmapping ( "/categoryInit") public String categoryInit () {return "categoryInit"; }/** * 카테고리의 새 작업 * @param model * @return */@requestmapping ( "/categoryInsert") public String categoryInsert (카테고리 모델) {categoryDao.save (model); "리디렉션 : categoryList"를 반환합니다. }/** * 카테고리 삭제 작업 * @param categoryId * @return */@requestmapping ( "/categoryDelete") public String CategoryDelete (Integer CategoryId) {CategoryDao.deleteById (CategoryId); "리디렉션 : categoryList"를 반환합니다. }/** * 카테고리 편집보기 * @param categoryId * @return */@requestmapping ( "/categoryEdit") public modelandview categoryEdit (integer categoryId) {category model = categoryDao.getOne (categoryId); ModelAndView mav = new ModelAndView ( "CategoryEdit"); mav.addoBject ( "카테고리", 모델); 반환 mav; }/** * 카테고리 편집 작업 * @param model * @return */@requestmapping ( "/categoryUpdate") public String categoryUpdate (카테고리 모델) {categoryDao.save (model); "리디렉션 : categoryList"를 반환합니다. }}7. 리소스 디렉토리에서 새 템플릿 디렉토리를 만들고 프리젠 테이션 레이어를 작성하십시오 : 카테고리 목록 페이지 (CategoryList.html), 카테고리 새 페이지 (CategoryInit.html), Category Edit Page (CategoryEdit.html)
CategoryList Page (CategoryList.html)
<! doctype html> <html lang = "en"> <head> <meta charset = "utf-8"> <title> 카테고리 목록 </title> <style> 테이블, Th, td {테두리 : 1px solid green; 국경-콜라스 : 붕괴; }. <tr th : eary = "항목 : $ {page.content}"> <td th : text = "$ {item.categoryId}"> 카테고리 번호 </td> <td th : text = "$ {item.categoryName}"> 범주 이름 </td> <td> <a th : href = "@{/categoryEdit (categoryId = $ {item.categoryId})}"> edit </a> <a th : href = "@{/categoryDelete (car th : href = "@{/car th : href = "@{/categoryList (start = $ {page.number+1})}"> [다음 페이지] </a> <a th : href = "@{/categoryList (start = $ {page.totalPages-1})}"> [마지막 페이지] </a> </div> </html> </html>카테고리에 대한 새 페이지 (CategoryInit.html)
<! docType html> <html lang = "en"> <head> <meta charset = "utf-8"> <title> 새로운 카테고리 </ttlectuoryName "> 카테고리 이름 : <input type ="post "> <label"id "id"id "id"post "> <label" "post"> <label "post"> 이름 = "CategoryName"/> <br/> <입력 유형 = "제출"value = "제출"> </form> </body> </html>
카테고리 편집 페이지 (CategoryEdit.html)
<! doctype html> <html lang = "en"> <head> <meta charset = "utf-8"> <title> 카테고리 편집 </title> </head> <body> <form action = "categoryupdate"method = "post"> <입력 유형 = "hidden"id = "txtCategoryId"name = "name" Th : field = "$ {category.categoryId}"/>> <label for = "txtCategoryName"> 카테고리 이름 : </label> <input type = "text"id = "txtCategoryName"name = "CategoryName"th : field = "$ {categoryname}"/> <br/ <br/> input type = "" " 값 = "제출"> </form> </body> </html>요약
위의 것은 아이디어+Maven+SpringBoot+JPA+편집자가 소개 한 CRUD 및 Pagination의 Thymeleaf 구현입니다. 모든 사람에게 도움이되기를 바랍니다. 궁금한 점이 있으면 메시지를 남겨 주시면 편집자가 제 시간에 모든 사람에게 답장을 드리겠습니다. Wulin.com 웹 사이트를 지원해 주셔서 대단히 감사합니다!