mybatis框架和spring-mvc集成开发的配置

在maven工程中需要的pom.xm配置如下:

4.0.0
com.music
mybatishomework
war
0.0.1-SNAPSHOT
mybatishomework Maven Webapp
"="http://maven.apache.org;

central-repos central Releases "="http://172.16.110.53:8081/nexus/content/groups/public/; nexus-repos Team Nexus Repository "="http://172.16.110.53:8081/nexus/content/groups/public/;

<spring.version>4.0.8.RELEASE</spring.version>
<jdk.version>1.7</jdk.version>
<tomcat.version>2.2</tomcat.version>
<jetty.version>8.1.16.v20140903</jetty.version>
<webserver.port>8181</webserver.port>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

junit junit ${junit.version} test taglibs standard ${taglibs.version} jar javax.servlet jstl ${jstl.version} jar javax.servlet javax.servlet-api ${javax.servlet-api.version} javax.servlet.jsp jsp-api ${jsp-api.version} provided org.springframework spring-beans ${spring.version} org.springframework spring-context ${spring.version} org.springframework spring-webmvc ${spring.version} org.springframework spring-web ${spring.version} org.springframework spring-test ${spring.version} commons-logging commons-logging ${commons-logging.version} org.aspectj aspectjweaver ${aspectj.version} org.aspectj aspectjtools ${aspectj.version} org.aspectj aspectjrt ${aspectj.version} oracle ojdbc 14 org.springframework spring-jdbc ${spring.version} c3p0 c3p0 0.9.1.2 org.springframework spring-orm ${spring.version} org.mybatis mybatis-spring ${mybatis-spring.version} org.mybatis mybatis ${mybatis.version} com.alibaba fastjson 1.2.7 log4j log4j 1.2.17 jstl jstl 1.2 taglibs standard 1.1.2 mybatishomework org.apache.maven.plugins maven-compiler-plugin 2.5.1 ${jdk.version} ${jdk.version} true org.apache.tomcat.maven tomcat7-maven-plugin ${tomcat.version} ${webserver.port} /${project.artifactId} ${project.build.sourceEncoding} org.mortbay.jetty jetty-maven-plugin ${jetty.version} ${webserver.port} /${project.artifactId} org.mortbay.util.URI.charset ${project.build.sourceEncoding}

若是web项目,需要在web.xml配置:

<?xml version="1.0" encoding="UTF-8"?> mybatishomework index.html index.jsp default.html default.htm default.jsp contextConfigLocation classpath*:/Application.xml org.springframework.web.context.ContextLoaderListener org.springframework.web.context.ContextCleanupListener org.springframework.web.context.request.RequestContextListener example org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath*:/spring-mvc.xml 1 example /

spring-mvc配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>

<context:component-scan base-package=“com.dao”>
<context:include-filter type=“annotation” expression=“org.springframework.stereotype.Controller”/>
</context:component-scan>
mvc:annotation-driven</mvc:annotation-driven>
mvc:default-servlet-handler/





Application.xml配置如下:

<?xml version="1.0" encoding="UTF-8"?>


<context:component-scan base-package=“com.dao”>
<context:exclude-filter type=“annotation”
expression=“org.springframework.stereotype.Controller” />
</context:component-scan>

aop:aspectj-autoproxy</aop:aspectj-autoproxy>







<context:property-placeholder location=“classpath:myjdbc.properties” />



<tx:annotation-driven transaction-manager=“txtManager” />

在mybatis框架中有个默认xml配置文件,为了尊重前贤,我们不做任何处理,只是建立此xml文件(mybatis-config.xml):

<?xml version="1.0" encoding="UTF-8" ?>

对应的pojo可写如下配置文件,里面主要为动态sql:

<?xml version="1.0" encoding="UTF-8" ?>

id,name,pwd,account

select count(*) from employee where name=#{name} and pwd=#{pwd}

select SEQ_EMPLOYEE_ID.nextval from dual

insert into employee() values(#{id},#{name},#{pwd},#{account})

delete from employee id=#{id} and name=#{name} and account=#{account} update employee name=#{name}, pwd=#{pwd}, account=#{account} where id=#{id} select from employee id=#{id} AND name=#{name} AND account=#{account} select from employee id like '%'||#{id}||'%' OR name like '%'||#{name}||'%' OR account like '%'||#{account}||'%'

当然,此外还有些小配置,如数据库连接,log4j配置输出,如下:
myjdbc.properties:
driver:oracle.jdbc.driver.OracleDriver
url:jdbc:oracle:thin:@172.16.110.53:1521:orcl
user:wanwujiedao
password:1221xu

log4j.properties:
log4j.rootLogger=INFO,CONSOLE,FILE
#DEBUG,CONSOLE,FILE,ROLLING_FILE,MAIL,DATABASE

log4j.addivity.org.apache=true

###################

Console Appender

###################
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.Threshold=INFO
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
#中文要先进行unicodeç¼–ç 
log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} -%-4r [%t] %-5p %x - %m%n
#log4j.appender.CONSOLE.layout.ConversionPattern=[start]%d{DATE}[DATE]%n%p[PRIORITY]%n%x[NDC]%n%t[THREAD] n%c[CATEGORY]%n%m[MESSAGE]%n%n

#####################

File Appender

#####################
log4j.appender.FILE.Threshold=INFO
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=E:/log/spring.log
log4j.appender.FILE.Append=true
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d - %c -%-4r [%t] %-5p %x - %m%n

Use this layout for LogFactor 5 analysis

########################

Rolling File

########################
log4j.appender.ROLLING_FILE=org.apache.log4j.RollingFileAppender
log4j.appender.ROLLING_FILE.Threshold=ERROR
log4j.appender.ROLLING_FILE.File=rolling.log
log4j.appender.ROLLING_FILE.Append=true
log4j.appender.ROLLING_FILE.MaxFileSize=10KB
log4j.appender.ROLLING_FILE.MaxBackupIndex=1
log4j.appender.ROLLING_FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.ROLLING_FILE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n

####################

Socket Appender

####################
log4j.appender.SOCKET=org.apache.log4j.RollingFileAppender
log4j.appender.SOCKET.RemoteHost=localhost
log4j.appender.SOCKET.Port=5001
log4j.appender.SOCKET.LocationInfo=true

Set up for Log Facter 5

log4j.appender.SOCKET.layout=org.apache.log4j.PatternLayout
log4j.appender.SOCET.layout.ConversionPattern=[start]%d{DATE}[DATE]%n%p[PRIORITY]%n%x[NDC]%n%
t[THREAD]%n%c[CATEGORY]%n%m[MESSAGE]%n%n

########################

Log Factor 5 Appender

########################
log4j.appender.LF5_APPENDER=org.apache.log4j.lf5.LF5Appender
log4j.appender.LF5_APPENDER.MaxNumberOfRecords=2000

########################

SMTP Appender

#######################
log4j.appender.MAIL=org.apache.log4j.net.SMTPAppender
log4j.appender.MAIL.Threshold=FATAL
log4j.appender.MAIL.BufferSize=10
log4j.appender.MAIL.From=chenyl@hollycrm.com
log4j.appender.MAIL.SMTPHost=mail.hollycrm.com
log4j.appender.MAIL.Subject=Log4J Message
log4j.appender.MAIL.To=chenyl@hollycrm.com
log4j.appender.MAIL.layout=org.apache.log4j.PatternLayout
log4j.appender.MAIL.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n

########################

JDBC Appender

#######################
#log4j.appender.DATABASE=org.apache.log4j.jdbc.JDBCAppender
#log4j.appender.DATABASE.URL=jdbc:mysql://localhost:3306/test
#log4j.appender.DATABASE.driver=com.mysql.jdbc.Driver
#log4j.appender.DATABASE.user=root
#log4j.appender.DATABASE.password=
#log4j.appender.DATABASE.sql=INSERT INTO LOG4J (Message) VALUES (’[framework] %d - %c -%-4r
#[%t] %-5p %c %x - %m%n’)
#log4j.appender.DATABASE.layout=org.apache.log4j.PatternLayout
#log4j.appender.DATABASE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n

log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.File=SampleMessages.log4j
log4j.appender.A1.DatePattern=yyyyMMdd-HH’.log4j’
log4j.appender.A1.layout=org.apache.log4j.xml.XMLLayout

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值