عندما نقوم بتطوير الويب ، لن نتمكن بالتأكيد من الهروب من تقديم النموذج. تنشئ هذه المقالة نموذجًا من خلال صندوق الربيع باستخدام لغة Kotlin.
أدناه ، سنضيف تقديم نموذج المعالجة بناءً على مشروع عرض الويب الخاص بـ "SPRING Boot و Kotlin Penering Web باستخدام محرك Template".
لم يتغير ملف build.gradle. هنا build.gradle الكامل
المجموعة 'name.quanke.kotlin'version' 1.0-snapshot'buildscript {ext.kotlin_version = '1.2.10' ext.spring_boot_version = '1.5.4 classpath ("org.springframework.boot: spring-boot-plugin: $ spring_boot_version") classpath ("org.jetbrains.kotlin: kotlin-allopen: $ kotlin_version")}} تطبيق البرنامج المساعد: 'kotlin'apply plugin: "kotlin-spring" // see https://kotlinlang.org/docs/reference/compiler-plugins.html#kotlin 'org.springframework.boot'jar {basename =' appack11-5-4-service 'version =' 0.1.0 '} المستودعات {mavencentral ()} تبعيات {compile "org.jetbrains.kotlin "org.springframework.boot: spring-boot-starter-web: $ spring_boot_version" compile "org.springframework.boo: spring-boot-starter-thymeleaf: $ spring_boot_version" // compile "org.springframework.boot: spring-boot-starter-test: $ spring_boot_version" testcompile "org.jetbrains.kotlin: kotlin-test-junit: $ kotlin_version"} compilekotlin "1.8"}إنشاء فئة كيان مرحبا
/*** تم إنشاؤه بواسطة http://quanke.name في 2018/1/12. */فئة البيانات Hello (var id: long؟ = 0 ، var content: string؟ = "")
إنشاء وحدة تحكم
استيراد name.quanke.kotlin.chaper11_5_4.entity.helloimport org.springframework.stereotype.controllerimport org.springframework.ui.modelmapport org.springframework.web.bind.annotation.modelattribute org.springframework.web.bind.annotation.postmappingimport org.springframework.web.bind.annotation.requestmapping/*** تم إنشاؤه بواسطة http://quanke.name في 2018/1/10. */ @ @controlRclass HelloconTroller {REquestMapping ("/") فهرس المرح (الخريطة: ModelMap): String {///إضافة سمة لقراءة map.addattrict ("HOST" ، "http://quanke.name") map.addattribute ("hello" ، hello () SRC/MAIN/Resources/Templates/Index.html Return "Index"} postmapping ("/hello") متعة hellopostsubmit (modelattribute hello: hello): string {return "result"}}صفحة عرض الصفحة
SRC/Main/Resources/Templates/Index.html
<! doctype html> <html xmlns: th = "http://www.w3.org/1999/xhtml"> <head lang = "en"> <title> quanke.name </title> <meta http-equiv = "content-type" charset = utf-8 "/> </head> <body> <h1 th: text =" $ {host} "> hello world </h1> <h1> form </h1> <form action ="#"th: action ="@/hello} "th:" $ {hello} "method =" post "> <p> id: <p> الرسالة: <input type = "text" th: field = "*{content}"/> </p> <p> <input type = "president" value = "submit"/> <input type = "reset" value = "reset"/> </p> </pump SRC/Main/Resources/Templates/Result.html
<! doctype html> <html lang = "en" xmlns: th = "http://www.w3.org/1999/xhtml" <title> العنوان </title> </head> <body> <h1> النتيجة </h1> <p th: text = "id: ' + $ {hello.id}"/> <p th: text = "' 'content:' + $ {hello.content}"/>بدء الحذاء الربيعي
استيراد org.springframework.boot.springapplicationimport org.springframework.boot.autoconfigure.springbootapplication/** ** ** ** تم إنشاؤها بواسطة http://quanke.name في 2018/1/9. */@springbootapplicationClass ApplicationFun Main (args: Array <string>) {SpringApplication.run (Application :: class.java ، *args)}ابدأ المشروع وزيارة TTP: // localhost: 8080/:
المرجع: https://spring.io/guides/gs/handling-form-submission/
ما سبق هو كل محتوى هذه المقالة. آمل أن يكون ذلك مفيدًا لتعلم الجميع وآمل أن يدعم الجميع wulin.com أكثر.