나는 최근에 Easyi를 배웠고 그것이 매우 유용하고 인터페이스가 아름답다는 것을 알았습니다. 학습 경험을 여기에 기록하십시오. 이 블로그는 SSH와 Easyi를 작성하여 Datagrid의 Pagination 디스플레이를 구현합니다. 추가, 수정, 삭제, 배치 삭제 등과 같은 다른 기능은 나중에 하나씩 작성됩니다.
먼저, 달성하는 효과를 살펴 보겠습니다. 페이지 당 5 줄의 데이터가 표시되면 :
페이지 당 10 줄의 데이터 라인이 표시되면 효과는 다음과 같습니다.
특정 단계 :
1. Easyi를 다운로드하고 환경을 구축하십시오.
2. SSH 프로젝트를 구축하면 전체 프로젝트의 디렉토리 구조가 그림에 나와 있습니다.
3. Oracle 데이터베이스에서 테이블 학생을 만듭니다. 다음 6 줄의 데이터를 입력하십시오. 추가 작업이 아직 구현되지 않았으므로 먼저 데이터베이스 테이블에 데이터를 추가하십시오. 기본값은 한 줄 당 5 개의 데이터이므로 페이징 테스트를 용이하게하기 위해 최소 6 줄의 데이터를 입력하십시오.
4. web.xml 구성
<? xml version = "1.0"encoding = "utf-8"?> <web-app version = "2.5"xmlns = "http://java.sun.com/xml/xml/ns/javaee"xmlns : xsi = "http://www.w3.org/2001/xmlschema-instance. xsi : schemalocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-sttus2 filter-> <filter-name> struts2 </filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.strutsprepareanDexecuteFilter </filter-class> </filter> <filter-mapping> <filter-name> struts2 </filter-name> <url-pattern>/*</url-pattern> <! <! <slister-mapping> <! <Leater-Class> org.springframework.web.context.contextloaderListener </LearteR-class> </Listener> <!-ApplicationContext.xml의 물리적 위치를 위치시키기-> <countxt-param> <param-name> contextConfigLocation </param-name> <param-value> classeppath : Applicationconxt.xml </param-valxt.xml. </context-param> </web-app>
5. ApplicationContext.xml의 구성
<? xml 버전 = "1.0"alcoding = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans"xmlns : xsi = "http://ww.w.w3.org/2001/xmlschema-instance" xmlns : context = "http://www.springframework.org/schema/context"xmlns : aop = "http://www.springframework.org/schema/aop"xmlns : tx = "http://www.spramwork.org/schema/schema/schema/schema. xsi : schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.xsd http://www.springframework.org/schema/contet http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/sprring--5-2.5.xsd http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.spramework.org/tx/spring-2.5.5 Resource = "ApplicationContext_bean.xml"/> <import resource = "ApplicationContext_db.xml"/> </beans>
6. Com.Model에서 Model Class Student.java를 만듭니다
package com.model; public class student {String studentId; // 1 차 키 스트링 이름; // 이름 문자열 성별; // 성별 문자열 연령; // Age Public String getStudentId () {return windetid; } public void setStudentId (String StudentId) {this.studentId = windentId; } public String getName () {return name; } public void setName (문자열 이름) {this.name = 이름; } public String getGender () {return gender; } public void setgender (문자열 성별) {this.gender = 성별; } public String getage () {반환 연령; } public void setage (String Age) {this.age = age; }} 7. 학생에 따라 해당 매핑 파일을 생성합니다.
<? XML 버전 = "1.0"?> <! DocType Hibernate Mapping Public "-// hibernate/hibernate 매핑 dtd 3.0 // -> <hibernate-mapping> <class name = "com.model.student"table = "winder"> <id name = "windation"type = "java.lang.string"> <column name = "studentId" /<generator /> < /id> <property name = "name" "java.lang.string"> <name " />>>>>>>>>>>>>. type = "java.lang.string"> <column name = "gender"/> </property> <property name = "age"type = "java.lang.string"> <column name = "age"/</property> </class> </hibernate-mapping>
8. 인터페이스 StudentService.java를 작성하십시오
패키지 com.service; import java.util.list; public interface wintentervice {public list getStudentList (문자열 페이지, 문자열 행)는 예외를 던지고 페이지에 따라 데이터를 가져오고 각 페이지에서 데이터를 가져옵니다. public int getStudentTotal ()은 예외를 던졌습니다. 9. 인터페이스 구현 클래스 windenterviceimpl.java를 작성하십시오
패키지 com.serviceimpl; import java.util.list; import org.hibernate.ssessionfactory; import com.service.studentservice; public class elidenterviceimpl eplitationservice {private sessionfactory sessionfactory; // 페이지에 따라 데이터를 가져 와서 페이지 당 여러 행에 대한 데이터를 얻습니다. 공개 목록 getStudEntList (문자열 페이지, 문자열 행) {// 기본값 value int currentPage = integer.parseint ((page == null || page == "));"1 ": page); // int intize = 0 = rows. "10": // 페이지 당 얼마나 많은 행 = this.sessionFactory.getCurrentSession ( "에서") 반환 목록; } // 전체 공개 int getStudentTotal ()에 얼마나 많은 데이터가 있는지 통계 예외 {return this.sessionFactory.getCurrentSession (). find ( "from student"). size (); } public sessionFactory getSessionFactory () {return SessionFactory; } public void setsessionSessionFactory (SessionFactory SessionFactory) {this.sessionFactory = SessionFactory; }} 10. 데이터베이스 응용 프로그램 Contuply application connecting application configuration application configuration file confording application contuply application context_db.xml
<? xml 버전 = "1.0"alcoding = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans"xmlns : xsi = "http://ww.w.w3.org/2001/xmlschema-instance" xmlns : context = "http://www.springframework.org/schema/context"xmlns : aop = "http://www.springframework.org/schema/aop"xmlns : tx = "http://www.spramwork.org/schema/schema/schema/schema. xsi : schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.xsd http://www.springframework.org/schema/contet http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/sprring--5-2.5.xsd http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.spramework.org/schema/tx/spring-2.5.xsd "> <! id = "DataSource"Destroin-Method = "Close"> <!-데이터베이스 드라이버 정의-> <속성 이름 = "driverclass"> value> oracle.jdbc.driver.oracledriver </value> </property> <!-데이터베이스 URL 정의-> <property name = "jdbcurl"> <value> jdbc : oracle : thin : @localhost : 1521 : orcl </value> </property> <!-데이터베이스의 사용자 이름을 정의합니다-> <속성 이름 = "user"> <alue> lhq </value> </property> <! 이름 = "minpoolsize"> <value> 1 </value> </property> <property name = "maxpoolsize"> <value> 40 </value> </property> <속성 이름 = "maxidletime"> <value> 1800 </value> </property> <property name = "accireIncrement"> <value> 2 </property> <속성 이름> <property name = "initialpoolsize"> <value> 2 </value> </value> <속성 이름 = "idleconnectionTestPeriod"> <value> 1800 </value> </property name> <property name = "accureRetchAtMetempts"> <value> 30 </value> </property> <property> <value> </value> </value> </value> <value> <value> 이름 = "testConnectionOnCheckout"> value> false> </value> </value> </value> </bean> <!-최대 절전 모드 세션 변형 정의-> <bean id = "sessionFactory"> <!-DataSource-> <property name = "dataSource"> ref bean = "reforce 속성"-</</</property property ". 이름 = "HibernateProperties"> <props> <prop key = "hibernate.dialect"> org.hibernate.dialect.oracle10gdialect </prop> </props> </property> <!-pojo의 매핑 파일을 정의하십시오.> <propertresours "> value> <values> </stogly/list> </student> hmb.xml </list> <values> <values> <values> <values> <values> <values> <values> <values> <values <values. </property> </bean> <!-트랜잭션 인터셉터 구성-> <bean id = "transactionManager"> <property name = "sessionFactory"ref = "sessionFactory"ref = "sessionFactory"/> </bean> <tx : "txadvice"transaction-manager = "transactionManager"> <tx : <tx : tx : "method*with with with with with with with with with with with with with with with with with" 삭제 및 업데이트를 수행 할 수 있습니다-> <tx : "delete*"propagation = "필수" /> <tx : 메소드 이름 = "update*"propagation = "필수" /> <tx : 메소드 이름 = "*"propagation = "supports"read-only = "true" /> <!-다른 메소드는 읽기 전용 메소드입니다. <aop : pointcut id = "interceptorpointcuts"expression = "execution (*com.serviceimpl ..*.*(..))" /> <!-클래스 인터페이스를 구현하는 패키지의 위치-> <aop : Advisor Advice-Ref = "txAdvice"pointcut-Ref = "interceptorPointCuts" /< /aop : confiG> < /beans>
11. 컨트롤 레이어에 Java 유형을 작성하십시오
패키지 com.action; import java.util.list; import javax.servlet.http.httpservletrequest; import javax.servlet.servlet.http.httpservletresponse; import net.sf.json.jsonobject; import org.apache.log4j.logger; import org.sproot.spruts.spruts.spruts.spruts com.service.studentservice; public class studentAction {정적 로거 로그 = logger.getLogger (StudentAction.Class); 개인 jsonobject jsonobj; 비공개 문자열 행; // 각 페이지에 표시된 레코드 수 개인 문자열 페이지; // 현재 개인 stutentService windent_Services; // 문자열 종속성 주입 // 모든 학생 정보 공개 문자열 getAllStudent () 예외 {log.info ( "모든 학생 정보 쿼리"); 목록 List = Student_Services.getStudentList (페이지, 행); this.tobejson (list, student_services.getStudentTotal ()); 널 리턴; } // JSON 형식으로 변환 public void tobejson (목록 목록, int total)은 예외 {httpservletResponse 응답 = servletactionContext.getResponse (); httpservletrequest 요청 = servletactionContext.getRequest (); jsonObject jobj = new JsonObject (); // new json jobj.accumulate ( "Total", Total); // 총계는 총 jobj.accumulate ( "행", 목록)에 얼마나 많은 데이터가 있는지 나타냅니다. response.getWriter (). writ } public windentService getStudent_Services () {retud Student_Services; } public void setStudent_services (wintentErvice 학생_Services) {this.student_services = windent_services; } public void setjsonobj (jsonobject jsonobj) {this.jsonobj = jsonobj; } public void setrows (문자열 행) {this.rows = 행; } public void setPage (문자열 페이지) {this.page = page; }} 12. Spring의 종속성 주입 ApplicationContext_bean.xml 구성 파일을 쓰십시오
<? xml 버전 = "1.0"alcoding = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans"xmlns : xsi = "http://ww.w.w3.org/2001/xmlschema-instance" xmlns : context = "http://www.springframework.org/schema/context"xmlns : aop = "http://www.springframework.org/schema/aop"xmlns : tx = "http://www.spramwork.org/schema/schema/schema/schema. xsi : schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.xsd http://www.springframework.org/schema/contet http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/sprring--5-2.5.xsd http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.spramework.org/schema/spring-tx-2.5.xsd id = "student_service"> <property name = "sessionFactory"> <ref bean = "sessionFactory"> </ref> </property> </bean> <!-제어 레이어 동작-> <bean id = "windent_action"> <property name = "student_service"> <ref bean = "student_service"/> </beac> </beans>
13. struts.xml 구성 파일을 쓰십시오
<? xml version = "1.0"alcoding = "utf-8"?> <! doctype struts public "-// apache 소프트웨어 재단 // dtd struts configuration 2.0 // en" "http://struts.apache.org/dtds/struts-2.0.dtd"> 학생 정보-> <action name = "getAllStudEntaction"method = "getAllStudent"> <result type = "json"> </result> </action> </package> </struts>
14. JSP ---- Index.jsp를 쓰십시오
<%@ page language = "java"pageencoding = "utf-8"iselignored = "false"%> <%string path = request.getContextPath ();%> <%@ taglib prefix = "s"uri = "/struts-tags"%> <! doctype html public "-// w3c // w3c // en. "http://www.w3.org/tr/tr/html4/loose.dtd"> html> html> http-quiv ="content-type "content ="text/html; charset = utf-8 "> <title> number box> <!-script type ="text/javascript " src = "<%= path%>/js/jss/easyui/jquery-1.8.0.min.js"charset = "utf-8"> </script> <! </script> <!-jQuery_easyui 소개-> <script type = "text/javaScript"<%= path%>/js/easyi/jquery.easyui.min.js " charset = "utf-8"> </script> <! 유형 = "text/javaScript"src = "<%= path%>/js/easyui/locale/easyui-lang-zh_cn.js"charset = "utf-8"> </script> <!-EasyUi 기본 csss format- <link rel = "type/css" href = "<%= path%>/js/easyui/테마/default/easyui.css"/> <!-EasyUi 작은 아이콘을 소개합니다-> <link rel = "stylesheet"type = "text/css"href = "<%= path%>/js/easyui/eseres/esples/icon.css"<text/javascript ". {$ ( '#mydatagrid'). DataGrid ({title : 'datagrid instance', iconcls : 'icon-ok', width : 600, pagesize : 5, // 페이지 당 5 행의 데이터가 페이지 당 5 행의 데이터입니다. 행 배경을 표시합니다. 탁월 : true, // 접이식 버튼 도구 모음 : "#tb", "#tb", // 버튼을 추가, 삭제 및 수정할 때 사용해야합니다 : 'getAllStudentAction.Accient', // URL 호출 Action Method Loadmsg : 'Data Loading ...', SingleSelect : // 싱글로 스케일을 선택할 수 있습니다. // SortName : 'XH', // 데이터 테이블이 초기화 될 때 정렬하는 데 사용되는 열은 // 'desc', // 'asc'또는 'desc'(양수 또는 역 순서) 일 수있는 정렬 순서를 정의합니다. Remotesort : False, Frozencolumns : [[{Field : 'CK', Checkbox : True}]], Pagination : True, // Pagination Rownumbers : True // line 번호}); }); </script> </head> <h2> <b> easyi의 Datagrid 인스턴스 </b> </h2> <table id = "mydatagrid"> <thead> <tr> <th data-options = "field : 'studentid', width : 100, 'center'"> 학생 번호 <th data-options = "field : 'name', width : 100, align : 'center'" "> name </th> <th data-options ="field : 'gender', width : 100, 'center' ""> gender </th> <th data-option = "field : 'age', width : 100, 'center'> ag> </tead> </tead> </tead> </body> </html>15. 프로그램을 시작하고 테스트를 위해 http : // localhost : 8080/easyui/index.jsp를 입력하십시오.
위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.