이 기사는 참조를 위해 LibrarySystem Library Management System의 두 번째 기사를 공유합니다. 특정 내용은 다음과 같습니다
1 단계 : 데이터베이스 구성 파일을 추가합니다
jdbc.properties
# 데이터베이스 드라이버 jdbc.driver = com.mysql.jdbc.jdbc.driver # 데이터베이스 주소 jdbc.url = jdbc : mysql : // localhost : 3306/library? useunicode = true & charac 연결 maxactive = 20 # 최대 유휴 연결 maxidle = 20 # 최소 유휴 연결 minidle = 1 # 시간 초과 대기 시간 maxwait = 60000
2 단계 : MyBatis 구성 파일을 추가하십시오
mybatis-config.xml
<? xml version = "1.0"encoding = "utf-8"?> <! doctype configuration public "-// mybatis.org//dtd config 3.0 // en" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <! <! JDBC의 기본 키를 얻기 위해 JDBC의 GetGeneratedKeys-> <setting name = "usegeneratedKeys"value = "true"/> <!-열 이름을 별칭으로, 기본 ture-> <setting name = "usecolumnlabel"value = "true"/<! <setting name = "mapunderscoretocamelcase" ""/> < "mapunderscoretocamelcase" </구성>
3 단계 : 스프링 구성 파일을 추가합니다
리소스/스프링 디렉토리에서 두 개의 새 파일을 만듭니다.
Spring
Spring-mybatis.xml
Spring-service.xml
Spring-mvc.xml
Spring-mvc.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 : p = "http://www.springframework.org/schema/p"xmlns : context = "http://www.springframework.org/schema/mvc"xsi : schemalocation = "http://www.springfrfringwork.org/schema/schema/schema/schema/schema http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/sprging-4.0.xtext-4 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd "> <!-구성 요소 스캐너-> <context : component-scan base-package ="-accontray.controller "//>. <mvc : default-servlet handler/<!-주석 모드 활성화-> <mvc : mvc : mvc : mvc : message-converters> <bean> <property name = "supportedMediAtypes"> <list> <!-Solve-<walue> 텍스트/plain; charset = utf-8 </value> <text/html; <value> application/json; charset = utf-8 </value> </list> </property> </bean> </mvc : message-converters> </mvc : view parser-> <ean bean> <!-prefix-> <property name = "prefix"value = "/web-inf/views/"! value = ". jsp"/> </bean> </beans>
Spring-mybatis.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 : "http://www.springframework.org/schema/tx"xsi : schemalocation = "http://www.spramwork.org/schema/schema http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/sprging-3.1.xtd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd "> <! <!-1. 구성 데이터베이스-관련 매개 변수-> 컨텍스트 : property-placeholder location ="classpit : jdbc.properies. druid data source-> <bean id = "dataSource"init-method = "init"destroy-method = "close"> <!-연결 풀 속성 구성-> <속성 이름 = "driver className"value = "$ {jdbc.driver}"/> <property name = "url"value = "$ jdbc.url}. value = "$ {jdbc.username}"/> <속성 이름 = "password"value = "$ {jdbc.password}"/> <!-초기화 크기, 최소, 최대 값-> <속성 이름 = "이니셜"value = "1"/> <property name = "minidle"value "1"1 "1"! 연결 대기 시간 초과-> <속성 이름 = "maxwait"value = "10000"/> <!-감지 간격을 수행하는 데 걸리는 시간을 구성하고 감지에는 밀리 초의 유휴 연결을 닫아야합니다 .-> <속성 이름 = "TimeBetweenevictionRunsmillis"value = "60000"/> <! milliseconds-> <property name = "minevictabledletimemillis"value = "300000" /> <!-연결이 유효하고 다른 데이터 구성이 다르는지 확인하는 SQL-> <속성 이름 = "validationQuery"value = "Select 1" /> <! 이름 = "testwhileIdle"value = "true"/> <!-검색된 연결이 이용할 수없는 것을 방지하기 위해 여기에서 true로 구성하는 것이 좋습니다-> <property name = "readonborring"value = "true"/> <property name = "testonborry"value = "true"/> <property name = "testonreturn"/> <! <property name = "poolpreparedStatements"value = "true"/> <속성 이름 = "maxpoolpreparedStatementperConnectionsize"value = "20"/> <!-여기서 제출 방법을 구성하십시오. 기본값은 참입니다. 구성없이 할 수 있습니다-> <속성 이름 = "defaultAutocommit" "true"/>-enable druid의 모니터링 기능-enable druid의 모니터링. 이름 = "필터"value = "stat"/> </bean> <!-3. myBatis의 sqlsessionFactory 객체-> <bean id = "sqlsessionFactory"> <!-구성 myBatis 글로벌 구성 파일을 구성합니다. name = "dataSource"ref = "dataSource"/> <!-구성 파일을 스캔합니다-> <property name = "mapperLocations"value = "classPath : Mapping/*. XML"/> </bean> <!-4. 스캔 한 DAO 인터페이스 패키지를 끈으로, DAO 인터페이스를 동적으로 구현하고 스프링 컨테이너를 주입합니다. -> <property name = "basepackage"value = "com.ray.dao"/> </bean> </beans>Spring-service.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 : "http://www.springframework.org/schema/tx"xsi : schemalocation = "http://www.spramwork.org/schema/schema http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.sprampramework.org/schema/context/spring-conxt.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd "> <!-자동 스캔-> <context : component-scan base-package ="com.ray "> <id id ="id = "id ="id = " 이름 = "dataSource"ref = "dataSource"/> </bean> <!-트랜잭션 제어에 대한 주석 지원을 켜십시오-> <TX : 주석 중심 트랜잭션-매너 = "TransactionManager"/> </beans>
4 단계 : 로그백 구성 파일을 추가합니다
로그백 구성은 log4J보다 간단하며 함수는 비슷합니다.
∎ 자원
logback.xml
리소스 폴더에서 새 파일을 만듭니다 : logback.xml
<? xml version = "1.0"encoding = "utf-8"?> <configuration debug = "true"> <appender name = "stdout"> <coder> <pattern> %d {hh : mm : ss.sss} [ %스레드] %-5level %logger {36}- %msg %n </pattern> 콘솔에서 로그 인쇄-> <루트 레벨 = "디버그"> <Appender-Ref ref = "stdout"/> </root> </configuration>5 단계 : Web.xml 구성
web.xml
<web-app xmlns = "http://xmlns.jcp.org/xml/ns/javaee"xmlns : xsi = "http://www.w3.org/2001/xmlschema-instance" xsi : schemalocation = "http://xmlns.jcp.org/xml/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_3_1.xsd"3.1 "Metadata-complete ="true "> <plitiet web-name> <!-DispatcherServlet-> <servlet> <servlet-name> seckill-dispatcher </servlet-name> <servlet-class> org.springframework.web.servlet.dispatcherservlet </servlet-class> <!-SpringMVC에로드 해야하는 구성 파일 Spring-dao.xml, spring-service.xml, spring-web.xml mybatis-> spring-> springmvc-> <param-name> contextConfiglocation </param-name> <param-value> classpath : spring/spring-*. xml </initar-param> <로드 된 spring-*1 </load- value> <Sync-supported> true </async-supported> </servlet> <servlet-mapping> <servlet-mapping> <servlet-name> seckill-dispatcher </servlet-name> <!-기본적으로 모든 요청을 일치시킵니다-> <url-pattern>/</url-pattern> </servlet-mapping> <fil tarbled-> <filter hanter>. <filter-name> atriblicedodingfilter </filter-name> <filter-class> org.springframework.web.filter.characterencododingfilter </filter-class> <init-param> <param-name> encoding </param-name> <param-value> utf-8 </param-value> </init-param> </param> <filter-name> 문자 인코딩 필터 </filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
프로젝트 구조 :
위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.