1. Windows 7 Enterprise Edition
2. Идея 14
3. JDK 1.8
4. Maven 3.5.2
5. Mariadb
6. SQLYOG
Добавить настройки.
1. Использование хранилища Alibaba Cloud намного быстрее, чем официальный сайт.
<mirror> <id> nexus-aliyun </id> <mirrorof> central </mirrorof> <mame> nexus aliyun </name> <url> http://maven.aliyun.com/nexus/content/groups/public </url> </mirror>
2. Глобальная конфигурация JDK
<!-Глобальная конфигурация JDK, настройки.xml-> <profile> <id> jdk18 </id> <compatation> <CativeByDefault> true </activeBydefault> <jdk> 1.8 </jdk> </activemation> <properties> <maven.compiler.source> 1.8 </maven.compiler.source> <shaven.compiler.source> 1.8 <maven.compiler.target> 1.8 </maven.compiler.target> <maven.compiler.compilerversion> 1.8 </maven.compiler.compilerversion> </properties> </properties> </properties> </profile>
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"> <dolidyversion> 4.0.0 </modelversion> <groupid> cn.temptation </artifactid> </artifactid> </artifactid> <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</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- thymeleaf --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <!-- MySQL ---> <Dependency> <groupId> mysql </GroupId> <ArtifactId> mySQL-connector-java </artifactid> <sersive> 5.1.21 </version> </dependence> <!-JPA-> <Dependency> <groupid> org.spramework.boot </groupid> <Artifactid> Spring-boot-starter-data-jpa </artifactid> </dependency> </dependencies> </project>
2. Создайте новое приложение. Прозрачные в каталоге ресурсов (конечно, если вы хотите использовать YAML, вы можете использовать YAML)
# Соединение базы данных Spring.datasource.url = jdbc: mysql: //127.0.0.1: 3306/testspring.datasource.username = rotspring.datasource.password = saspring.datasource.driver-class-name = com.mysource.jdbc.driver# jpairver# jpairver #driver #driver# jpairver #driver № spring.jpa.properties.hibernate.hbm2ddl.auto = обновление
3. Создание программы Springboot Program Class Class SpringBootApplication.java
Пакет cn.temptation; import org.springframework.boot.springapplication; import org.springframework.boot.autoconfigure.springbootapplication; @springbootapplicationpublic class project {public static void main (string) {// springboot project {public void main (string) {// springboot project {public void void (] args) {// springboot project SpringApplication.Run (SpringBootApplication.class, args); }}4. Создать категорию класса сущности. Java
Пакет cn.temptation.model; Import javax.persistence.*; // таблица библиотеки // категория таблицы Drop; /// Create Table Category // (// Категория int auto_increment Первичный ключ, // категория varchar (10), а не null //); /////////////вставленное в категорий значений (null, '), (null,'); (Null, 'shoes'); ///// select * from category; @entity @table (name = "category") Категория открытого класса {@id @generatedValue (стратегия = GenerationType.identity) @column (name = "categoryid") private Integer CategoryId; @Column (name = "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 Extends JParePository <Category, Integer> {}6. Создать класс контроллера CategoryController.java
Пакет cn.temptation.web; import cn.temptation.dao.categorydao; import cn.temptation.model.category; import org.springframework.beans.factory.annotation.autowired; imporm.springframework.data.domain.page; org.springframework.data.domain.pagable; импорт org.springframework.data.domain.sort; import org.springframework.stepolype.controller; импорт org.springframework.web.bind.annotation.requestmapping; importbramework.web.Annotation.Requestmapping; importBramework.WebINDTATIONTATION.Requestmapping; org.springframework.web.servlet.modelandView; import java.util.list; @ControllerPublic Class CategoryController {@Autowired Private CategoryDao CategoryDao; /** * Неопасный запрос * * @return * /// @requestmapping ("/categorylist") // public modelandView Categorylist () {// list <Category> list = categorydao.findall (); //// modelandView mav = new ModelandView ("CategoryList"); /** * Запрос страниц * * @return */@requestmapping ("/categorylist") public modelandview categorylist (@requestparam (value = "start", defaultValue = "0") integer start, @RequestParam (value = ", ограничение", defaultValue = "2") integer limit) {start = start <0? 0: начало; Sort sort = new Sort (sort.default_direction, "CategoryId"); Pagable Pagable = новый PageRequest (Start, Limit, Sort); Page <Category> page = CategoryDao.findall (Pagable); // System.out.println (page.getNumber ()); // System.out.println (page.getNumberOfelements ()); // System.out.println (page.getsize ()); // system.out.println (page.getoteltes System.out.println (page.getTotalPages ()); // system.out.println (page.isfirst ()); // system.out.println (page.islast ()); ModelandView MAV = New ModelAndView ("CategoryList"); mav.addobject ("page", page); вернуть мав; }/*** Новое представление в категории* @return*/@requestmapping ("/categoryinit") public String Categoryinit () {return "CategoryInit"; }/** * Новая операция в категории * @param model * @return */@requestmapping ("/categoryinsert") public String CategyoryInsert (Category Model) {CategoryDao.Save (Model); вернуть "перенаправление: категория"; }/** * Категория Удалить операцию * @param CategoryId * @return */@requestmapping ("/CategoryDelete") public String CategoryDelete (Integer CategoryId) {CategoryDao.DeleteByID (CategoryId); вернуть "перенаправление: категория"; }/** * Редактирование категории View * @param CategoryId * @return */@requestmapping ("/CategoryEdit") public modelAndView CategoryEdit (Integer CategoryId) {Category Model = CategoryDao.getone (CategoryId); ModelandView MAV = new ModelAndView ("CategoryEdit"); mav.addobject («категория», модель); вернуть мав; }/** * Операция редактирования категории * @param model * @return */@requestmapping ("/categoryupdate") public String Categoryupdate (Category Model) {CategoryDao.save (Model); вернуть "перенаправление: категория"; }}7. Создайте новый каталог шаблонов в каталоге ресурсов и создайте уровень презентации: страница списка категорий (CategoryList.html), новая страница категории (CategoryInit.html), страница редактирования категории (CategoryEdit.html)
Страница CategoryList (CategoryList.html)
<! Doctype html> <html lang = "en"> <head> <meta charset = "utf-8"> <Title> список категорий </title> <style> таблица, td {border: 1px solid green; пограничный коллапс: коллапс; } </style> </head> <body> <a th: href = "@{/categoryInit}"> добавить </a> <table> <tr> <th> Номер категории </th> <Th> Категория имени </th> <Th> операция </th> </tr> <!-no Page Traversal-> <! <th th: chany = "item: $ {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 (CategoryId = $ {item.categoryId})}"> Delete </a> </td> </td> </trt> </trt> Th: href = "@{/categorylist (start = 0)}"> [Home] </a> <a th: if = "$ {not page.isfirst ()}" th: href = "@{/categorylist (start = $ {page.totalpage-1})}"> [предыдущая страница] </a> <a Tht. if = $ ". th: href = "@{/categorylist (start = $ {page.number+1})}"> [следующая страница] </a> <a th: href = "@{/categorylist (start = $ {page.totalpages-1}}"> [Последняя страница] </a> </div> </body> </html>Новая страница для категории (CategoryInit.html)
<! Doctype html> <html lang = "en"> <head> <meta charset = "utf-8"> <Title> Новая категория </title> </head> <body> <form action = "categoryinsert" method = "post"> <label for = "txtCategoryName"> Категория Имя: </label> <INVINTER TIPT = "TXTCATORYNAME"> </label> <INVINTION TIPT = "TXTAMERYNAME" name = "CategoryName"/> <br/> <input type = "Отправить" value = "Opper"> </form> </body> </html>
Страница редактирования категории (CategoryEdit.html)
<! Doctype html> <html lang = "en"> <head> <meta charset = "utf-8"> <Title> Категория редактирование </title> </head> <body> <form action = "categoryupdate" Method = "post"> <input type = "hidden" id = "txtcateryid" = "name" th: field = "$ {category.categoryid}"/> <br/> <label for = "txtcategoryname"> Категория Имя: </label> <input type = "text" id = "txtcategoryname" name = "CategoryName" th: field = "$ {Category.categoryName}"/> <brbr/> <input = "$ {Category.categoryName}"/> <br /> <input = "winte =" winte = "winte =" winte = "category.categoryName}"/> value = "propect"> </form> </body> </html>Суммировать
Выше приведено идея+maven+springboot+jpa+whimeleaf Реализация CRUD и страниц, введенная вам редактором. Я надеюсь, что это будет полезно для всех. Если у вас есть какие -либо вопросы, пожалуйста, оставьте мне сообщение, и редактор ответит всем вовремя. Большое спасибо за вашу поддержку сайту wulin.com!