springmvc+mybatis的项目配置参数
pom.xml文件内容
<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/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.shinowit</groupId> <artifactId>mbs</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <org.springframework.version>3.2.5.RELEASE</org.springframework.version> <org.aspectj-version>1.6.10</org.aspectj-version> <org.slf4j-version>1.6.6</org.slf4j-version> </properties> <build> <sourceDirectory>src</sourceDirectory> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.3</version> <configuration> <warSourceDirectory>WebContent</warSourceDirectory> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>${org.aspectj-version}</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>${org.aspectj-version}</version> </dependency> <!-- Commons --> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging-api</artifactId> <version>1.1</version> </dependency> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>3.2</version> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.2.2</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.0.1</version> </dependency> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>20030825.184428</version> </dependency> <dependency> <groupId>commons-pool</groupId> <artifactId>commons-pool</artifactId> <version>20030825.183949</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.9</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.27</version> </dependency> <!-- mybatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.2.3</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.2.1</version> </dependency> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>2.2.2</version> </dependency> <dependency> <groupId>asm</groupId> <artifactId>asm</artifactId> <version>3.3.1</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.2.2</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.2.2</version> </dependency> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> </dependencies> </project>
web.xml文件内容
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>mbs</display-name> <!-- Log4j的配置(在同一容器中部署多个应用时, 不能使用默认的webAppRootKey,必须指定唯一KEY,以免冲突) --> <context-param> <param-name>webAppRootKey</param-name> <param-value>springmvc.root</param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:jdbc_context.xml classpath:springmvc_servlet.xml</param-value> </context-param> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/classes/log4j.properties</param-value> </context-param> <context-param> <param-name>log4jRefreshInterval</param-name> <param-value>60000</param-value> </context-param> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <!-- Creates the Spring Container shared by all Servlets and Filters --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- Processes application requests --> <servlet> <servlet-name>spring_mvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:jdbc_context.xml</param-value> </init-param> --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc_servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring_mvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- 浏览器不支持put,delete等method,由该filter将/blog?_method=delete转换为标准的http delete方法 --> <filter> <filter-name>HiddenHttpMethodFilter</filter-name> <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> </filter> <filter-mapping> <filter-name>HiddenHttpMethodFilter</filter-name> <servlet-name>spring_mvc</servlet-name> </filter-mapping> <!-- 用spring Encoding,解决乱码问题 --> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
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"> <configuration> <settings> <setting name="lazyLoadingEnabled" value="true" /> </settings> </configuration>
spring配置参数文件内容:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd" default-autowire="byName"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://127.0.0.1:3306/test?useUnicode=true"></property> <property name="username" value="root"></property> <property name="password" value="123456"></property> <property name="maxActive"> <value>50</value> </property> <property name="maxWait"> <value>60000</value> </property> <property name="maxIdle"> <value>20</value> </property> <property name="minIdle"> <value>10</value> </property> <property name="validationQuery"> <value>SELECT 1</value> </property> <property name="testOnBorrow"> <value>true</value> </property> </bean> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 声明式事务管理 --> <aop:config> <aop:advisor pointcut="execution(* com.mbs.*Service.*(..))" advice-ref="myAdvice" /> </aop:config> <tx:advice id="myAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="find*" propagation="SUPPORTS" read-only="true" /> <tx:method name="query*" propagation="SUPPORTS" read-only="true" /> <tx:method name="list*" propagation="SUPPORTS" read-only="true" /> <tx:method name="create*" propagation="REQUIRED" /> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="modify*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="*" propagation="SUPPORTS" read-only="true" /> </tx:attributes> </tx:advice> <!-- 自动扫描组件,需要把controller去掉,否则影响事务管理 --> <context:component-scan base-package="com.mbs"> <context:exclude-filter type="regex" expression="com.mbs.web.*" /> </context:component-scan> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="dataSource" /> </bean> <!-- define the SqlSessionFactory, notice that configLocation is not needed when you use MapperFactoryBean --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:mybatis-config.xml" /> <property name="mapperLocations" value="classpath*:com/mbs/dao/**/*.xml" /> </bean> <!-- scan for mappers and let them be autowired --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.mbs.dao.mapper" /> </bean> <!-- <import resource="classpath*:springmvc_servlet.xml"/> --> </beans>
继续spring配置参数文件内容:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> <!-- 启动扫描所有的controller --> <context:component-scan base-package="com.mbs.web" /> <!-- 主要作用于@Controller,激活该模式 下面是一种简写形式,完全可以手动配置替代这种简写形式; 它会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean, 是spring MVC为@Controllers分发请求所必须的 --> <mvc:annotation-driven /> <!-- 定时器开关 开始--> <task:annotation-driven/> <!-- 定时器开关 结束--> <!-- <bean class="com.ddt.service.AutoCountReportController" id="day_rpt"> </bean> --> <!-- 每天0时 0分 0秒 开始汇总数据 <task:scheduled-tasks> <task:scheduled ref="day_rpt" method="work" cron="0 2 0 * * ?"/> </task:scheduled-tasks> --> <!-- <context:annotation-config /> --> <!-- 配置js,css等静态文件直接映射到对应的文件夹,不被DispatcherServlet处理 mapping to WebRoot里面的静态文件位置目录 location 访问地址 --> <!-- 配置静态资源,直接映射到对应的文件夹,不被DispatcherServlet处理,3.04新增功能,需要重新设置spring-mvc-3.0.xsd --> <mvc:resources mapping="/img/**" location="/img/" /> <mvc:resources mapping="/js/**" location="/js/" /> <mvc:resources mapping="/css/**" location="/css/" /> <mvc:resources mapping="/html/**" location="/html/" /> <!-- 配置/WEB-INF/views/目录里面的jsp文件不被DispatcherServlet处理,可以直接通过浏览器访问。 view-name to /WEB-INF/views/里面的jsp文件名(不许后缀即可) path 访问地址 --> <mvc:view-controller path="/header" view-name="header" /> <!-- <mvc:interceptors> <bean class="com.ddt.web.admin.LoginStatusIntercepter" /> </mvc:interceptors> --> <!-- jsp页面解析器,当Controller返回XXX字符串时,先通过拦截器,然后该类就会在/WEB-INF/views/目录下,查找XXX.jsp文件 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/"></property> <property name="suffix" value=".jsp"></property> </bean> </beans>
log4j.properties文件内容
log4j.rootLogger=ERROR,stdout,R log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=[%d{MM-dd HH:mm:ss}] [%t] [%-5p][%C-%L]-%m%n log4j.appender.R=org.apache.log4j.DailyRollingFileAppender log4j.appender.R.File=${springmvc.root}/WEB-INF/logs/log.txt log4j.appender.R.DatePattern ='.'yyyy-MM-dd'.txt' log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%c]-[%p] %m%n #log4j.appender.R.layout=org.apache.log4j.HTMLLayout #log4j.logger.com.ddt=DEBUG,stdout,R #log4j.logger.java.sql=DEBUG,stdout #log4j.logger.org.apache.ibatis=DEBUG,stdout #log4j.org.springframework.web=DEBUG
用于生成mybatis实体类及mapper的xml文件内容:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> <generatorConfiguration> <!-- <classPathEntry location="e://mysql-connector-java-5.1.23-bin.jar" /> --> <classPathEntry location="D://java//jdbc//mysql-connector-java-5.1.27.jar" /> <context id="DB2Tables" targetRuntime="MyBatis3"> <plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin" /> <plugin type="org.mybatis.generator.plugins.SerializablePlugin" /> <plugin type="org.mybatis.generator.plugins.CaseInsensitiveLikePlugin" /> <plugin type="org.mybatis.generator.plugins.RenameExampleClassPlugin"> <property name="searchString" value="Example$" /> <property name="replaceString" value="Criteria" /> </plugin> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/test?useUnicode=true" userId="root" password="123456"> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <javaModelGenerator targetPackage="com.mbs.model" targetProject="src"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <sqlMapGenerator targetPackage="com.mbs.dao.mapper" targetProject="src"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <javaClientGenerator type="XMLMAPPER" targetPackage="com.mbs.dao.mapper" targetProject="src"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <table tableName="user"> <generatedKey column="user_id" sqlStatement="MySql" identity="true" /> </table> </context> </generatorConfiguration>
相关推荐
Mybatis框架** Mybatis是一个优秀的持久层框架,它支持定制化SQL、存储过程以及高级映射。Mybatis避免了几乎所有的JDBC代码和手动设置参数以及获取结果集。Mybatis可以使用简单的XML或注解进行配置和原始映射,将...
在IT行业中,Spring、SpringMVC和MyBatis是三个非常重要的开源框架,它们在企业级Web应用开发中被广泛使用。Spring作为一个全面的后端应用程序框架,提供了依赖注入(DI)和面向切面编程(AOP)等功能,极大地简化了...
SSM(Spring、SpringMVC、Mybatis)是Java Web开发中常见的三大框架整合,用于构建高效、灵活的Web应用程序。下面将详细讲解这三大框架的核心概念、整合过程及应用场景。 1. Spring框架: Spring 是一个开源的 ...
**二、Mybatis框架** Mybatis是一个优秀的持久层框架,它支持定制化SQL、存储过程以及高级映射。Mybatis避免了几乎所有的JDBC代码和手动设置参数以及获取结果集。它允许开发者直接编写原生的SQL语句,同时还能享受到...
这个"Spring+SpringMVC+Mybatis框架整合JAR包"应该是为了方便开发者快速搭建SSM环境而准备的资源集合。 首先,我们来逐一了解这三个框架的核心功能: 1. **Spring**:Spring 是一个全面的Java企业级应用开发框架,...
SSM框架,即Spring、SpringMVC和MyBatis的集成,是Java Web开发中常用的一种轻量级框架组合。这三种技术各有其特点,结合使用可以构建出高效、灵活的Web应用程序。下面我们将深入探讨这三个框架的原理、整合过程以及...
在这个"SpringMvc+mybatis框架结合的一个练习项目"中,开发者利用 SpringMvc 处理 Web 请求,通过 Mybatis 进行数据操作。项目包含了论坛和聊天系统,这涉及到用户认证、消息传递、数据存储等多个方面,充分展示了这...
SpringMVC和MyBatis是两个非常流行的Java Web开发框架,SpringMVC作为控制器层,负责处理HTTP请求,而MyBatis则是一个轻量级的数据访问层,专注于SQL的执行和结果映射。将这两个框架整合在一起,可以构建出高效且...
整合Spring、SpringMVC和MyBatis,首先需要在项目中引入这三个框架的依赖库,然后配置相关的XML文件,如Spring的bean配置文件、SpringMVC的servlet配置文件以及MyBatis的全局配置文件。在MyBatis中,需要编写Mapper...
在本项目中,"springMVC+mybatis实现登录和增删改查"是一个典型的Web应用程序,它结合了SpringMVC、MyBatis两大主流框架,以及Bootstrap前端库,来构建一个用户友好的数据管理平台。以下是这个项目涉及到的主要知识...
2. **MyBatis框架介绍** MyBatis是一个基于Java的持久层框架,它简化了数据库操作,允许开发者将SQL语句直接写在XML配置文件或者注解中。MyBatis避免了几乎所有的JDBC代码和手动设置参数以及获取结果集。通过...
二、MyBatis框架解析 MyBatis是一个优秀的持久层框架,它支持定制化SQL、存储过程以及高级映射。MyBatis避免了几乎所有的JDBC代码和手动设置参数以及获取结果集。MyBatis可以使用简单的XML或注解进行配置和原始映射...
**MyBatis框架** MyBatis是一个优秀的持久层框架,它支持定制化SQL、存储过程以及高级映射。MyBatis避免了几乎所有的JDBC代码和手动设置参数以及获取结果集。MyBatis可以使用简单的XML或注解进行配置和原始映射,将...
SpringMVC和Mybatis是Java开发中常用的两个开源框架,它们在企业级应用开发中扮演着重要的角色。SpringMVC负责处理HTTP请求和响应,提供模型-视图-控制器(MVC)架构,而Mybatis则是一个轻量级的持久层框架,用于...
SSM(Spring MVC + Spring + MyBatis)是Java Web开发中常见的三层架构组合,它将Spring MVC作为表现层框架,Spring作为业务层容器,MyBatis作为数据访问层框架。下面将详细介绍这三个组件以及它们如何协同工作。 *...
以上就是Spring+SpringMVC+MyBatis框架简单工程的搭建过程。通过这个实例,开发者可以学习到如何整合这三大框架,理解它们各自的作用以及如何协同工作。在实际开发中,SSM框架因其灵活性和强大的功能,被广泛应用在...
SpringMVC和MyBatis是两个非常流行的Java Web开发框架,它们在企业级应用中有着广泛的应用。SpringMVC作为Spring框架的一部分,主要用于构建后端控制器,提供模型-视图-控制器(MVC)架构模式的实现。而MyBatis则是...
"Maven模块项目"就是这样一个示例,它演示了如何利用Maven的模块化特性,结合Spring、SpringMVC和MyBatis这三大流行Java Web开发框架进行项目整合。下面将详细介绍这些知识点。 首先,Maven是Apache软件基金会开发...
根据提供的文件信息,我们可以从标题、描述以及标签中提取出几个关键知识点:SpringMVC框架、MyBatis框架以及它们的应用教程。接下来,我们将详细展开这些知识点。 ### SpringMVC框架简介 SpringMVC是Spring框架的...