간단한 프레임 워크 구성에서 내장 방법에서 정상 프레임 워크 사용에 이르기까지 JFinal을 사용하여 처음으로 기록하십시오.
JFinal 공식 웹 사이트 : http://www.jfinal.com/
Jfinal은 Java 언어를 기반으로하는 빠른 Web + ORM 프레임 워크입니다. 핵심 설계 목표는 빠른 개발, 소규모 코드 볼륨, 간단한 학습, 강력한 기능, 가벼운, 확장이 쉬우 며 편안합니다. Java의 모든 장점이 있지만 Ruby, Python 및 PHP와 같은 동적 언어의 개발 효율도 있습니다.
JFinal에는 다음과 같은 주요 기능이 있습니다.
MVC 아키텍처, 절묘한 디자인 및 간단한 사용
COC 원칙, 제로 구성, XML 없음을 따르십시오
원래 DB + 레코드 모드, 유연하고 편리합니다
ActivereCord 지원으로 데이터베이스 개발이 매우 빠릅니다
수정 된 Java 파일을 자동으로로드하면 개발 중에 웹 서버를 다시 시작할 필요가 없습니다.
AOP는 유연한 인터셉터 구성 및 강력한 기능을 지원합니다
플러그인 아키텍처, 강력한 확장 성
멀티 뷰 지원, 프리 마커, JSP, 속도
강력한 유효성 검사기 백엔드 확인 기능
Struts2의 대부분의 함수와 함께 완전 함수
작은 크기는 632k에 불과하며 타사 종속성은 없습니다
예:
먼저 Maven을 사용하고 먼저 Maven 프로젝트를 만듭니다.
내 프로젝트가 만들어지면 먼저 설정해야합니다.
그런 다음 적용을 클릭하십시오
다른 설정이 있습니다. 내 질문은 여기에 건너 뜁니다.
그런 다음 pom.xml에서 Jar 패키지를 소개합니다.
Maven Search Jar 패키지 : http://mvnrepository.com/
공식 데모 pom.xml :
JSON은 여기에 소개되지 않았으며, 마지막 데모 방법은 JSON이 필요합니다.
<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/0.0.0.0 http://maven.apache.org/maven-v4_0_0.xsd "> <modelversion> 4.0.0 </modelversion> <groupid> com.demo </groupid> <artifactid> jfinal_demo_for_maven </artifactid> war </packaging </packaging> 3.2 </packaging> 3. <name> jfinal_demo_for_maven maven webapp </name> <url> http://maven.apache.org </url> <proferties> <project.build.sourceencoding> utf-8 </project.build.sourceencoding> <maven.compiler.encoding> utf-8 </maven.compiler.encoding> </properties> <!-Alibaba Maven 라이브러리를 사용하여-> <repositories> <repository> <id> ali-maven </id> <url> http://maven.aliyun.com/nexus/cont/cont/cont/cont/cont/cont/cont/cont/cont/cont/cont/cont/roup. <릴리스> <enabled> true </enabled> </릴리스> <snapshots> <snapshots> <enabled> true </enabled> <ududfolicy> 항상 </updatepolicy> <checksumpolicy> fail </checksumpolicy> </snapshots> </repository> </repository> </repository> <! <!-repositories> <repository> <id> Sonatype-nexus-snapshots </id> <name> Sonatype Nexus Snapshots </name> <url> https://oss.sonatype.org/content/repositories/snapshots/ </url> <릴리스> <fally> </enabled> true </enabled> <ududpolicy> daily </updatepolicy> </snapshots> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </reposatory> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository> </repository <Scope> 테스트 </scope> </fectionement> <pectionement> <groupId> com.jfinal </groupid> <artifactid> jetty-server </artifactid> <bersion> 8.1.8 </version> <!-여기의 스코프 값은 적합합니다. 쓸모없는 항아리를 시작하기 위해 아이디어 아래 프로젝트를 시작할 때만 제공 될 때만 제공 될 필요가 있습니다. <spection> </scope> </scope> </scope> <prection> <groupid> com.jfinal </groupId> <artifactid> jfinal </artifactid> <version> 3.3 </dependency> <ponmential> <group 4J. <Artifactid> log4j </artifactid> <bersion> 1.2.16 </version> </fectionency> <pectionement> <groupid> mysql </groupid> <artifactid> mysql-connector-java </artifactid> </areplency> <groupbaba </grallid> <artifactid> druid </artifactid> <bersion> 1.0.29 </version> </dependency> <pectionency> <groupid> com.jfinal </groupid> <artifactid> cos </artifactid> <bersion> 2017.5 </version> </dependency> </dependence> <flusname> <groupid> org.mortbay.jetty </groupid> <artifactid> jetty-maven-plugin </artifactid> <버전> 8.1.8.v20121106 </version> <stopkey> stop </stopkey> <stopport> 5599 </stopport> <webAppConfig>/contextPath>/webAppConfig <ScanIntervalSeconds> 5 </scanintervalseconds> <connector> <커넥터 구현 = "org.eclipse.jetty.server.nio.selectchannelconnector"> <port> <port> <maxidletime> 60000 </maxidletime> </connector> </connecturation> </flugins> </config>
그런 다음 web.xml의 구성이 있습니다.
알아채다:
democonfig.java 파일이있는 패키지와 자체 파일 이름은 web.xml의 param-value 태그의 구성과 일치해야합니다 (이 경우 구성은 demo.democonfig입니다).
<filter> <filter-name> jfinal </filter-name> <filter-class> com.jfinal.core.jfinalfilter </filter-class> <init-param> <param-name> configclass </param-name> <param -value> demo.democonfig </param-value> </init-param> </filter> <filter-mapping> <filter-name> jfinal </filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
다음으로 Java 파일을 만듭니다.
democonfig를 만들고 jfinalconfig를 상속하십시오. Democonfig가 기본 파일입니다. 일반 Java 파일 기본을 실행하는 것처럼 프로젝트를 시작하려면이 파일을 실행하십시오. 동시에 실행 한 후 다른 코드를 수정하면 다시 시작할 필요가 없습니다. 프레임 워크가 자동으로 수정됩니다. 수정 된 컨텐츠를 보려면 직접 새로 고침 할 수 있습니다.
초기 간단한 데모는 다음과 같습니다.
패키지 데모; import com.jfinal.config.*; public class democonfig는 jfinalConfig {public void configconstant (constants me) {me.setdevmode (true);} public void configroute (me) {me.add ( "/hello", hellocontroller.class);}}}} configplugin (플러그인 me) {} public void configinterceptor (interceptors me) {} public void confighandler (handlers me) {}}그런 다음 컨트롤러를 구성합니다.
패키지 데모; import com.jfinal.core.controller; public class hellocontroller 확장 컨트롤러 {public void index () {rendertext ( "Hello Jfinal World.");}}그런 다음 브라우저를 열고 http : // localhost/hello를 직접 입력하면 페이지가 hello jfinal world를 출력하는 것을 볼 수 있습니다.
다음은 사용하는 가장 기본적인 예입니다. 여기 내 프로그램이 있습니다.
패키지 데모; import com.jfinal.config.*; import com.jfinal.core.jfinal; import com.jfinal.kit.propkit; import com.jfinal.plugin.activecord.activerecordplugin; import com.jfinal.plugin.c3p0.c3p0plugin; import Com.plugin.druid.druid.druid.druid com.jfinal.template.engine; import controller.studentController; import demo.model.classes; import demo.model.student; public class democonfig는 jfinalconfig {public static void main (String [] args) {jfinal.start ( "src/main/webapp", 80, "/", 5); } public void configConstant (constants me) {me.setDevMode (true); //이 메소드는 개발 모드 상수 DevMode 구성과 같은 JFinal 상수 값을 구성하는 데 사용됩니다. 다음 코드는 개발 모드에서 JFinal // 실행을 구성합니다. 개발 모드에서 JFinal은 각 요청에 대한 보고서를 출력하여 URL, 컨트롤러, 방법 // 요청에 의해 운반되는 매개 변수를 출력합니다. } public void configroute (lourtes me) {me.add ( "/", hellocontroller.class); me.add ( "/test/mytest", hellocontroller.class, "test"); me.add ( "/student", StudentController.class); //me.add("/classes ", classescontroller.class); } public void configEngine (Engine ME) {} public void configplugin (플러그인 me) {// c3p0plugin cp = new c3p0plugin ( "jdbc : mysql : // localhost/db_name", // "username", "password"); // me.add (cp); loadPropertyFile ( "a_little_config.txt"); druidplugin dp = 새로운 druidplugin (getProperty ( "jdbcurl"), getProperty ( "사용자"), getProperty ( "password")); me.add (dp); activerecordplugin arp = 새로운 activerecordplugin (dp); me.add (arp); arp.addmapping ( "학생", "학생이", 학생 .class); arp.addmapping ( "classe", "classeD", class.class); //이 메소드는 JFinal의 플러그인을 구성하는 데 사용됩니다. 다음 코드는 DRUID 데이터베이스 연결 풀 플러그인 및 ACTIVERECORD // 데이터베이스 액세스 플러그인을 구성합니다. 다음 구성을 사용하면 ActiveRecord를 사용하여 응용 프로그램에서 데이터베이스를 작동하는 것이 매우 편리합니다. } public void configinterceptor (interceptors me) {//me.add(new authinterceptor ()); //이 메소드는 JFinal의 글로벌 인터셉터를 구성하는 데 사용됩니다. 글로벌 인터셉터는 // @Clear를 사용하여 컨트롤러에서 지우지 않는 한 모든 작업 요청을 가로 채 웁니다. 다음 코드는 Authinterceptor라는 인터셉터를 구성합니다. } public void confighandler (핸들러 나) {}}여기에 각 방법에 대한 간단한 설명은 주석에 작성됩니다.
그런 다음 컨트롤러가 있습니다.
서비스가 여기에 선언되어 있지만 사용되지 않습니다. 컨트롤러 방법에 직접 사용됩니다.
패키지 컨트롤러; import java.util.list; import java.util.map; import com.alibaba.fastjson.jsonobject; import com.jfinal.aop.before; import com.jfinal.core.controller; import studentinterceptor.studentvalidator.studentvalidator; import studentvalidator.studentvalidator; demo.model.student; import service.studentservice; Public Class StudentController 확장 컨트롤러 { /*** 학생을 얻는 방법에는 여러 가지가 있습니다.이 방법은 프론트 엔드 패스 매개 변수 쓰기 방법과 일치합니다. 컨트롤러는 getpara 시리즈 방법을 제공합니다. 공식 API는 매우 상세합니다. JFinal은 원래 SQL 문을 사용합니다. 이는 간단하고 편리합니다. setattr ( "학생 목록", 목록); 결과를 요청 범위로 설정하십시오. JFinal은 또한 개체를 객체로 포장하는 양식을 직접 얻는 방법을 가지고 있습니다. 즉, struts2와 마찬가지로 양식 이름은 Add, StudentId Student.set ( "StudentId", "mySequence.nextVal")에 매우 편리합니다. Save (); JFinal에는 여러 가지 반환 방법이 있으며 JSON 데이터를 반환 할 수도 있습니다. 렌더 시리즈 방법은 공식 API*/ 정적 학생 서비스 서비스 = New StudentService ()에서 매우 상세합니다. @Before (StudentInterceptor.class) public void index () {list <tudent> list = student.dao.find ( "select * from student"); setattr ( "학생 목록", 목록); // 아래 경로에/가있는 경우, 루트 디렉토리에서보기 시작합니다. render ( "index.html"); } public void add () {render ( "add.html"); } public void test () {list <guldent> list = whitith.dao.find ( "select * from student"); setattr ( "학생 목록", 목록); setattr ( "학생", list.get (0)); render ( "test.jsp"); } public void getList () {list <tudent> list = student.dao.find ( "select * from student"); jsonobject jo = new jsonobject (); Jo.put ( "Code", 0); Jo.put ( "msg", true); jo.put ( "count", list.size ()); Jo.put ( "data", list); Renderjson (Jo); } public void layui () {list <tudent> list = student.dao.find ( "select * from student"); setattr ( "학생 목록", 목록); render ( "index3.html"); } public void delete () {// 양식 도메인 이름의 값을 가져옵니다. windentId Student.dao.deleteById (getPara ( "StudentId")); ForwardAction ( "/Student"); } public void delete1 () {// URL 요청 학생의 첫 번째 값을 가져옵니다 .dao.deletebyid (getParatoint ()); ForwardAction ( "/Student"); } public void update () {학생 학생 = getModel (Student.class); 학생 .update (); ForwardAction ( "/Student"); } public void get () {학생 학생 = 학생 .dao.findbyid (getpara ( "StudentId")); setattr ( "학생", 학생); render ( "index2.html"); } public void get1 () {Student Student = Student.dao.findbyid (getParatoint ()); setattr ( "학생", 학생); render ( "index2.html"); } @before (wichingvalidator.class) public void save () { /*** getModel은 페이지 양식 필드에서 전달 된 모델 객체를 수신하는 데 사용됩니다. 양식 필드 이름은 "modelname.attrname"으로 명명되었습니다. http://www.jfinal.com. getModel에서 사용하는 attrname은 데이터 테이블 필드 이름과 정확히 동일해야합니다. GetBean 방법은 JFNAL Generator를 사용하여 Getter 및 Setter 방법을 생성하는 모델을 포함하여 기존 Java Bean을 지원하는 데 사용됩니다. 페이지 양식에 인수를 전달할 때는 데이터 테이블 필드 이름이 아닌 세터 메소드와 일치하는 attrname을 사용하십시오. GetModel과 GetBean의 차이점은 전자가 숫자 테이블 필드 이름을 사용하고 후자는 데이터 주입을위한 세터 방법과 일치하는 속성 이름을 사용한다는 것입니다. 먼저 GetBean 메소드를 사용하는 것이 좋습니다. */// getBean (whity.class) .save (); getModel (Student.class) .save (); 리디렉션 ( "/Student"); } @before (whitedValidator2.class) public void savebean () {getbean (whening.class) .save (); 리디렉션 ( "/Student"); }}동일한 간단한 설명도 주석에 기록됩니다.
방법은 기본적으로 여기에 있습니다. 여기에 다른 구성이 있습니다.
이것은 엔티티 클래스입니다.
패키지 demo.model; import com.jfinal.plugin.activeCord.Model; Public Class 학생 확장 모델 <tudent> {public static final student dao = new Student (); /*** ActivereCord는 JFinal의 가장 핵심 구성 요소 중 하나입니다. ActiveRecord를 통해 데이터베이스를 작동하면 코드의 양이 크게 줄어들고 개발 효율성을 크게 향상시킵니다. 구성이 뒷면에 있습니다. 여기서 모델을 사용하고 있습니다. 모델은 ActiveRecord에서 가장 중요한 구성 요소 중 하나이며 MVC 모드에서 모델 부분으로 작용합니다. 위 코드의 사용자는 즉시 모델을 상속하여 데이터베이스를 작동하는 많은 편리한 방법이 있습니다. 사용자에 선언 된 DAO 정적 객체는 쿼리 작업의 편의를 위해 정의되어 있으며 객체는 필요하지 않습니다. ActivereCord를 기반으로 한 모델은 속성, 게터 및 세터 메소드, XML 구성 및 주석 구성을 정의 할 필요가 없으므로 코드 양이 크게 줄어 듭니다. 일반적인 모델 방법은 공식 API에서 발견됩니다. JFinal은 또한 원래 DB + 레코드 모드, DB 클래스 및 동반 레코드 클래스를 보유하고 있으며,이 레코드 클래스는 모델 클래스 외부에서 더 풍부한 데이터베이스 작업 기능을 제공합니다. DB 및 레코드 클래스를 사용할 때는 데이터베이스 테이블을 매핑 할 필요가 없으며 레코드는 일반 모델과 같습니다. 일반적인 DB 방법은 공식 API에서 발견됩니다. */}StudentValidator :
PACKED StudentValidator; import com.jfinal.core.controller; import com.jfinal.validate.validator; Public Class StudentValidator 확장 유효성 검사기 {//@컨트롤러 컨트롤러 (Controller Controller) {Controller.keeppara ( "Student.tudentName"); Controller.render ( "/add.html"); } @override protected void validate (컨트롤러 컨트롤러) {// 양식 필드 이름을 확인하고, 정보 키를 반환하고, 정보 값을 반환하고, validateRequiredString ( "withy.studentName", "Studentnamemsg", "학생 이름을 입력하십시오!"); }} PACKATE STUDIONVALIDATOR; import com.jfinal.core.controller; import com.jfinal.validate.validator; Public Class StudentValidator2 extends validator {// 보호 된 void handerError (컨트롤러 컨트롤러) {controller.keeppara ( "Studentname"); Controller.render ( "/add.html"); } @override protected void validate (컨트롤러 컨트롤러) {// 양식 필드 이름을 확인하고, 정보 키를 반환하고, 정보 값을 반환하고 validateRequiredString ( "StudentName", "Studentnamemsg", "학생 이름을 입력하십시오!"); }}학생 interceptor :
PACKED StudentInterceptor; import com.jfinal.aop.interceptor; import com.jfinal.aop.invocation; public class Studentinterceptor interceptor {public void intercept (호출 ai) {system.out.println ( "조치 호출 전"); ai.invoke (); System.out.println ( "조치 호출 후"); }}그런 다음 프론트 데스크 디스플레이 페이지 :
프론트 데스크 페이지와 관련하여 문서의 여섯 번째 장, JFinal Template Engine의 내용을보고 프론트 데스크에 JFinal이 어떻게 표시되는지 이해해야합니다. 이것은 매우 중요합니다.
<! docType html> <html> <head> <meta charset = "utf-8"> <title> 학생 관리 </title> <script type = "text/javaScript"src = "/jquery-1.12.4.min.js"> </script> </head> <h1 <h1> <a href = "/jsp">] <a href = "/student/layui"> test layui </a> <a href = "/student/test"> index 0 </a> <br> <a href = "/student/add"> add </a> <br> <form action = "/get"> id : <input type = "affore"<at value = <input = <input = <input = "input" "<app action ="in pute = "input" "<br. href = "/student/delete"> delete </a> <form action = "/student/delete"> id : <input type = "text"name = "studentid"> <input type = "value ="delete "> </form> #for (x : <Th> gender </th> <th> age </th> <th> 주소 </th> <th> email </th> <th> 운영 </th> </tr> #for (x : StudentList) <tr> <td style = "text-align : left;">#(x.studentid) <td style-remign : left; ">#">#"(x. Style = "Text-Align;">#">#(x.sex) </td> <td style ="text-align : left; ">##(x.age) </td> <td style ="text-align : ">#(x.address) </td> <td style ="text-align : left : ">##<; Style = "Text-Align;"> "> <a href ="/student/delete? studentId =#(x.studentId) "> delete </a> <a href ="/student/delete1/#(x.studentId) "> delete </a> <a href ="/student/get? studling =###</a> </a> href = "/student/get1/#(x.studentId)"> modify </a> <a href = "/withy/get1/#(x.studentId)"> modify </a> </td> </tr> #end </tbody> </table> </body> </html>
이것은 스타일이 없기 때문에 페이지 효과입니다. 거칠어 보입니다. 그런 다음 다음은 Layui의 정상적인 사용 및 데이터를 반환하기위한 정상적인 습관 방법으로 구성됩니다.
<! docType html> <html> <head> <meta charset = "utf-8"> <title> 학생 관리 layui </title> <script type = "text/javaScript"src = "/layui-v2.2.45/layui/layui.js"> href = "/layui-v2.2.45/layui/css/layui.css"media = "all"> </head> <body> <div style = "margin : 0px; 배경색; 백색; 마진 : 0 10px;"> <blockquote> <a href = "/student/adt"> <button = "useas"ind = "inds ="inds = "inds ="ind = "ind" aria-hidden = "true"> </i> 추가 </button> </a> <form style = "float : right;" onsubmit = "return false"> <div> 사용자 검색 : <div> <input name = "name"id = "demoreload"autocomplete = "off"> </div> <button style = "transform : translatey (-3px); Data-Type = "Reload"> 검색 </div> </div> </div> </div> </blockquote> </div> <Table Lay-Data = "{url : '/student/getList', id : 'idtest', height : 'full-60',}"lay-filter = "demo"> 너비 : '20%',} "> id </th> <th lay-data ="{field :'studentname ', 너비 : '20%'} "> name </th> <th lay-data ="{field : 'sex', width : '20%'} "> gender </th> <th lay-data ="ag> <agth : '20%} ", lay-data = "{field : 'add id = "edit"lay-event = "edit"> modify </a> <a lay-event = "del"> delete </a> </a> </a> </a> </body> <script> layui.use ( 'table', function () {var table = layui.table, form = layui.form;; // cheeckbox (obj) '{wectsole (obj)' });//Speak Toolbar Table.on ( '도구 (Demo)', function (obj) {var data = obj.data; if (obj.event === 'del') {layer.confirm ( 'Really Deeleting the User', function (index) {$ .ajax ({type : "post", delete? 데이터 유형 : // returned 성공 : return.reload ( "idtest"), function (msg) {obj.event == index. [ '380px', '80%'], 내용 : "/student/get?studentid="+data.studentid, cancel (index, layero) {index.reload ("idtest "); $ (wind URL : "<%= basepath%>/sys/user/passuser", data : {id : data.id}, // datatype : // return success : function (returnData) {layui.use ( 'layer', function (returndata.msg); 1},}; layer.alert (json.stringify (data)); checkstatus ( 'idtest'); });}); </script> </html>이것은 내가 처음 사용하고 테스트를 수행 할 때만이기 때문에 조금 더 나아 졌기 때문에 여전히 비교적 거칠기 때문입니다.
그런 다음 이러한 방식으로 데이터 리턴 문제에 주목하는 것이 중요합니다.
public void getList () {list <tudent> list = student.dao.find ( "select * from student"); jsonobject jo = new jsonobject (); Jo.put ( "Code", 0); Jo.put ( "msg", true); jo.put ( "count", list.size ()); Jo.put ( "data", list); Renderjson (Jo); }이것은 Layui 테이블 URL이 지적한 방법입니다. 여기서는 JSON 데이터를 RenderJSON 방식으로 반환해야합니다.
그런 다음 목록 컬렉션을 직접 반환하려고 시도했다는 점에 유의해야합니다. 이 방법은 실현 가능하지만 Layui 테이블은 데이터를 수신하려면 위의 형식이어야하므로 페이지에 표시되지 않습니다. 그러나 Jo를 직접 반환하면 배경 오류가보고 되었으며이 문제는 내일만 배우고 해결할 수 있습니다.
다음은 반환 된 렌더 메소드를 사용하는 몇 가지 방법입니다.
그런 다음 메소드 호출 및 매개 변수 전송에주의를 기울여야합니다.
다음과 같이 두 가지 방법과 매개 변수 전송 방법이 있습니다.
<a href = "/student/delete? studentId =#(x.studentId)"> delete </a> </a> <a href = "/withy/delete1/#(x.studentId)"> delete </a> <a href = "/get? student/get? studentid =#(x.studentId)"> 수정 </a> <a href = "/student/get1/#(x.studentId)"> modify </a> <a href = "/withy/get1/#(x.studentId)"> modify 1 </a>
컨트롤러 방법은 다음과 같습니다.
public void delete () {// 양식 도메인 이름의 값을 가져옵니다. windentId wident.dao.deletebyid (getpara ( "windertid")); ForwardAction ( "/Student"); } public void delete1 () {// URL 요청 학생의 첫 번째 값을 가져옵니다 .dao.deletebyid (getParatoint ()); ForwardAction ( "/Student"); } public void update () {학생 학생 = getModel (Student.class); 학생 .update (); ForwardAction ( "/Student"); } public void get () {학생 학생 = 학생 .dao.findbyid (getpara ( "StudentId")); setattr ( "학생", 학생); render ( "index2.html"); } public void get1 () {Student Student = Student.dao.findbyid (getParatoint ()); setattr ( "학생", 학생); render ( "index2.html"); }마지막으로 수락 엔티티 클래스를 추가하는 두 가지 방법이 있습니다.
@before (whitedValidator.class) public void save () { /*** getModel은 페이지 양식 필드에서 전달 된 모델 객체를 수신하는 데 사용됩니다. 양식 필드 이름은 "modelname.attrname"으로 명명되었습니다. http://www.jfinal.com. getModel에서 사용하는 attrname은 데이터 테이블 필드 이름과 정확히 동일해야합니다. GetBean 방법은 JFNAL Generator를 사용하여 Getter 및 Setter 방법을 생성하는 모델을 포함하여 기존 Java Bean을 지원하는 데 사용됩니다. 페이지 양식에 인수를 전달할 때는 데이터 테이블 필드 이름이 아닌 세터 메소드와 일치하는 attrname을 사용하십시오. GetModel과 GetBean의 차이점은 전자가 숫자 테이블 필드 이름을 사용하고 후자는 데이터 주입을위한 세터 방법과 일치하는 속성 이름을 사용한다는 것입니다. 먼저 GetBean 메소드를 사용하는 것이 좋습니다. */// getBean (whity.class) .save (); getModel (Student.class) .save (); 리디렉션 ( "/Student"); } @before (whitedValidator2.class) public void savebean () {getbean (whening.class) .save (); 리디렉션 ( "/Student"); }내 데모의 두 번째 getbean 메소드는 설정되지 않았으며 ID 만 생성되고 다른 데이터가 추가되지 않습니다.
필요한 경우. 공식 데모는 다음과 같습니다.
package com.demo.common.model; import com.demo.common.model.base.baseblog;/** *이 데모는 가장 피상적 인 Jfinal 사용법 만 표현하며 자세한 내용은 더 가치 있고 실용적인 엔터프라이즈 수준의 사용법을 나타냅니다. 자세한 내용은 http://jfinal.com/club *를 참조하십시오. * 필드 이름과 같은 Java 코드와의 일관성을 용이하게하기 위해 데이터베이스 필드 이름에 Camel Naming 규칙을 사용하는 것이 좋습니다. userId */@suppresswarnings ( "Serial") 공개 클래스 블로그 확장 BaseBlog <blog> {} package com.demo.common.model.base; import com.jfinal.plugin.activecord.model; import com.jfinal.plugin.activecord.ibean;/*** jfinal에 의해 생성 된이 파일을 수정하지 마십시오. */@suppresswarnings ({ "Serial", "Checked"}) 공개 초록 클래스 BaseBlog <m은 baseblog <m >> 확장 <m> 확장 <m> emplements ibean {public m setid (java.lang.integer id) {set ( "id", id); 반환 (m) 이것; } public java.lang.integer getId () {return getInt ( "id"); } public m settitle (java.lang.string title) {set ( "title", title); 반환 (m) 이것; } public java.lang.string getTitle () {return getStr ( "title"); } public m setContent (java.lang.string content) {set ( "content", content); 반환 (m) 이것; } public java.lang.string getContent () {return getStr ( "Content"); }}위의 JFinal Fast Development Framework 사용 메모를 공유하는 것은 내가 공유하는 모든 콘텐츠입니다. 나는 당신이 당신에게 참조를 줄 수 있기를 바랍니다. 그리고 당신이 wulin.com을 더 지원할 수 있기를 바랍니다.