ssm+maven+bootstrap搭建

  • Post author:
  • Post category:其他




ssm+maven+bootstrap搭建


作者:vashon

时间:2017-05-12


一、架构特点


1、用maven做依赖管理&构建,项目分为父子工程


2、基础框架SSM(SpringMVC+Spring+Mybatis)


3、前端框架Bootstrap


4、pagehelper的分页实现


5、Mybatis的逆向工程Mybatis-Generator


6、前端Jquery校验,后端

JSR303

校验


7、Rest风格的URI


8、

以json格式进行数据交互,同时支持移动端产品


9、

采用logback做日志管理



10、自定义标签及字典


其他。。。




二、创建Maven父子工程


1、步骤:


⑴ 、先创建父工程:











⑵、创建子工程(java工程):











⑶、创建子工程(web工程)










自此,maven创建的父子工程就已经完成了,自动生成的自带jdk版本会很低,这需要在maven的setting.xml配置中进行配置,这里就不多详述了,或者不配置手动设置环境也行;maven创建的父子工程总体结构图如下:









2、各个子工程引入项目依赖的jar


子工程base中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>
	<parent>
		<groupId>com.ywx.ssm</groupId>
		<artifactId>ssm-parent</artifactId>
		<version>0.0.1-SNAPSHOT</version>
		<!-- 以当前文件为基准的父工程pom.xml文件的相对路径 -->
		<relativePath>../pom.xml</relativePath>
	</parent>
	<artifactId>ssm-base</artifactId>

	<!-- 引入项目依赖的jar包 -->
	<dependencies>
		<!-- Mybatis -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
		</dependency>
		<!-- Mybatis整合Spring的适配包 -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
		</dependency>
		<!-- 逆向工程需要的MBG -->
		<dependency>
			<groupId>org.mybatis.generator</groupId>
			<artifactId>mybatis-generator-core</artifactId>
		</dependency>

		<!-- 数据库连接池、驱动 -->
		<dependency>
			<groupId>c3p0</groupId>
			<artifactId>c3p0</artifactId>
		</dependency>
		<!-- Oracle or MySQL驱动 -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
		</dependency>
		<!-- 引入pagehelper分页插件 -->
		<dependency>
			<groupId>com.github.pagehelper</groupId>
			<artifactId>pagehelper</artifactId>
		</dependency>
		<!-- JSR303数据校验支持 ;tomcat7及以上的服务器。如果是tomcat7以下的服务器:el表达式,额外给服务器的lib包中替换新的标准el -->
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-validator</artifactId>
		</dependency>


	</dependencies>

</project>


子工程web工程中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>
	<parent>
		<groupId>com.ywx.ssm</groupId>
		<artifactId>ssm-parent</artifactId>
		<version>0.0.1-SNAPSHOT</version>
		<!-- 以当前文件为基准的父工程pom.xml文件的相对路径 -->
		<relativePath>../pom.xml</relativePath>
	</parent>
	<artifactId>ssm-web</artifactId>
	<packaging>war</packaging>

	<dependencies>
		<!-- 引用ssm-base -->
		<dependency>
			<groupId>com.ywx.ssm</groupId>
			<artifactId>ssm-base</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>
		<!-- 引入项目需要的jar包 -->
		<!-- SpringMVC Spring -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
		</dependency>
		<!-- Spring-jdbc -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
		</dependency>
		<!-- Spring面向切面编程 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aspects</artifactId>
		</dependency>
		<!-- Spring test -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
		</dependency>


		<!-- (jstl、servlet-api、junit) -->
		<dependency>
			<groupId>jstl</groupId>
			<artifactId>jstl</artifactId>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<scope>provided</scope>
		</dependency>
		<!-- 返回json字符串的支持 -->
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
		</dependency>

		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
		</dependency>
		<!-- 导入logback日志的jar -->
		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-classic</artifactId>
		</dependency>
		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-core</artifactId>
		</dependency>


	</dependencies>



	<!-- 配置mavne打包的信息 -->
	<build>
		<finalName>ywx-web</finalName>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<configuration>
					<!-- 对于test不打包 -->
					<skip>true</skip>
				</configuration>
			</plugin>
		</plugins>
	</build>

</project>


父工程的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.ywx.ssm</groupId>
	<artifactId>ssm-parent</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>pom</packaging>

	<!-- 使用properties标签自定义统一声明版本号 -->
	<properties>
		<ssm.spring.version>4.3.7.RELEASE</ssm.spring.version>
	</properties>

	<!-- 配置聚合(便于统一打包) -->
	<modules>
		<!-- 指定各个自工程 -->
		<module>ssm-base</module>
		<module>ssm-web</module>
	</modules>

	<!-- 配置依赖的管理(即继承) -->
	<dependencyManagement>
		<dependencies>
			<!-- ===============统一管理ssm-base中的jar版本开始=============== -->
			<!-- Mybatis -->
			<dependency>
				<groupId>org.mybatis</groupId>
				<artifactId>mybatis</artifactId>
				<version>3.4.2</version>
			</dependency>
			<!-- Mybatis整合Spring的适配包 -->
			<dependency>
				<groupId>org.mybatis</groupId>
				<artifactId>mybatis-spring</artifactId>
				<version>1.3.1</version>
			</dependency>
			<!-- 数据库连接池、驱动 -->
			<dependency>
				<groupId>c3p0</groupId>
				<artifactId>c3p0</artifactId>
				<version>0.9.1.2</version>
			</dependency>
			<!-- Oracle or MySQL驱动 -->
			<dependency>
				<groupId>mysql</groupId>
				<artifactId>mysql-connector-java</artifactId>
				<version>5.1.42</version>
			</dependency>
			<!-- MBG -->
			<dependency>
				<groupId>org.mybatis.generator</groupId>
				<artifactId>mybatis-generator-core</artifactId>
				<version>1.3.5</version>
			</dependency>
			<!-- 引入pagehelper分页插件 -->
			<dependency>
				<groupId>com.github.pagehelper</groupId>
				<artifactId>pagehelper</artifactId>
				<version>5.0.1</version>
			</dependency>
			<!-- JSR303数据校验支持 -->
			<dependency>
				<groupId>org.hibernate</groupId>
				<artifactId>hibernate-validator</artifactId>
				<version>5.4.1.Final</version>
			</dependency>
			<!-- ===============统一管理ssm-base中的jar版本结束=============== -->

			<!-- ===============统一管理ssm-web中的jar版本开始=============== -->
			<!-- SpringMVC Spring -->
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-webmvc</artifactId>
				<version>${ssm.spring.version}</version>
			</dependency>
			<!-- Spring-jdbc -->
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-jdbc</artifactId>
				<version>${ssm.spring.version}</version>
			</dependency>
			<!-- Spring面向切面编程 -->
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-aspects</artifactId>
				<version>${ssm.spring.version}</version>
			</dependency>
			<!-- Spring test -->
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-test</artifactId>
				<version>${ssm.spring.version}</version>
			</dependency>
			<!-- (jstl、servlet-api、junit) -->
			<dependency>
				<groupId>jstl</groupId>
				<artifactId>jstl</artifactId>
				<version>1.2</version>
			</dependency>
			<dependency>
				<groupId>javax.servlet</groupId>
				<artifactId>javax.servlet-api</artifactId>
				<version>3.0.1</version>
				<scope>provided</scope>
			</dependency>
			<!-- 返回json字符串的支持 -->
			<dependency>
				<groupId>com.fasterxml.jackson.core</groupId>
				<artifactId>jackson-databind</artifactId>
				<version>2.8.8</version>
			</dependency>
			<dependency>
				<groupId>junit</groupId>
				<artifactId>junit</artifactId>
				<version>4.12</version>
			</dependency>
			<!-- 导入logback日志的jar -->
			<dependency>
				<groupId>ch.qos.logback</groupId>
				<artifactId>logback-classic</artifactId>
				<version>1.2.1</version>
			</dependency>
			<dependency>
				<groupId>ch.qos.logback</groupId>
				<artifactId>logback-core</artifactId>
				<version>1.2.1</version>
			</dependency>
			<!-- ===============统一管理ssm-web中的jar版本结束=============== -->
		</dependencies>
	</dependencyManagement>
</project>


备注:如果创建web工程后,webapp目录下没有web.xml文件,需要重新指定Dynamic Web Module,提供下图看看你就懂得:



三、框架整合


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">

	<!-- 1、启动Spring的容器 -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:/spring/applicationContext.xml</param-value>
	</context-param>
	<!-- 配置使用logback日志 -->
	<context-param>
		<param-name>logbackConfigLocation</param-name>
		<param-value>classpath:main/resources/logback.xml</param-value>
	</context-param>

	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<!--2、springmvc的前端控制器,拦截所有请求 -->
	<!-- The front controller of this Spring Web application, responsible for 
		handling all application requests -->
	<servlet>
		<servlet-name>dispatcherServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<!-- Map all requests to the DispatcherServlet for handling -->
	<servlet-mapping>
		<servlet-name>dispatcherServlet</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>

	<!-- 3、字符编码过滤器,一定要放在所有过滤器之前 -->
	<filter>
		<filter-name>CharacterEncodingFilter</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>forceRequestEncoding</param-name>
			<param-value>true</param-value>
		</init-param>
		<init-param>
			<param-name>forceResponseEncoding</param-name>
			<param-value>true</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>CharacterEncodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<!-- 4、使用Rest风格的URI,将页面普陀的post请求 转为指定的delete或者put请求 -->
	<filter>
		<filter-name>HiddenHttpMethodFilter</filter-name>
		<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>HiddenHttpMethodFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<!-- 配置过滤器:要求支持直接发送PUT之类的请求还要封装请求体的数据 。 AJAX发送请求方式为PUT时,tomcat不会封装请求体的数据为map,只有POST形式请求才封装到请求体。 -->
	<filter>
		<filter-name>HttpPutFormContentFilter</filter-name>
		<filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>HttpPutFormContentFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>


	<display-name>ssm-web</display-name>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
</web-app>


applicationContext.xml中的配置:

<?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:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
		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-4.3.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">

	<!-- 扫描业务逻辑组件,控制器不扫描 -->
	<context:component-scan base-package="com.ywx">
		<context:exclude-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
	</context:component-scan>

	<!-- Spring配置文件的核心点(数据源、与mybatis的整合、事务控制) -->
	<import resource="classpath:/spring/persistence.xml" />
	
</beans>


1、


Spring与Mybatis的整合配置(与业务逻辑组件,控制器等的配置无关的分开,如:持久层配置等):


与持久层整合的配置我们需要从applicationContext.xml拎出来(后续其他的配置归类存放,便于管理):




persistence.xml配置如下:


<?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:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
		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-4.3.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">

	<!-- Spring的配置文件,主要配置和业务逻辑有关的 -->
	<!-- =========================数据源配置开始========================= -->
	<context:property-placeholder location="classpath:dbconfig.properties" />
	<bean id="pooledDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
		<property name="driverClass" value="${jdbc.driverClass}"></property>
		<property name="user" value="${jdbc.user}"></property>
		<property name="password" value="${jdbc.password}"></property>
	</bean>
	<!-- =========================数据源配置结束========================= -->

	<!-- 配置和Mybatis的整合 -->
	<!-- ========================mybatis整合配置开始======================== -->
	<bean id="SqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<!-- 指定mybatis全局配置文件的位置 -->
		<property name="configLocation" value="classpath:mybatis-config.xml"></property>
		<property name="dataSource" ref="pooledDataSource"></property>
		<!-- 指定mybatis.mapper的文件位置 -->
		<property name="mapperLocations" value="classpath:mapper/*.xml"></property>
	</bean>
	<!-- 配置扫描器,将mybatis接口的实现加入到ioc容器中 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<!-- 扫描所有dao接口实现,加入到ioc容器中 -->
		<property name="basePackage" value="com.ywx.ssm.dao"></property>
	</bean>
	<!-- 配置一个可以执行批量的sqlSession -->
	<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
		<constructor-arg name="sqlSessionFactory" ref="SqlSessionFactory"></constructor-arg>
		<constructor-arg name="executorType" value="BATCH"></constructor-arg>
	</bean>
	<!-- ========================mybatis整合配置结束======================== -->

	<!-- ========================事务控制配置开始======================== -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<!-- 控制住数据源 -->
		<property name="dataSource" ref="pooledDataSource"></property>
	</bean>
	<!-- 基于注解的事物,使用xml配置形式的事物(必要重要的都是使用配置式) -->
	<aop:config>
		<!-- 切入点表达式 -->
		<aop:pointcut expression="execution(* com.ywx.ssm.service..*(..))"
			id="txPoint" />
		<!-- 配置事务增强 -->
		<aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint" />
	</aop:config>

	<!-- 配置事务增强,事务如何切入 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<!-- 所有方法都是事务方法 -->
			<tx:method name="*" />
			<!-- 以get、query、select开始的所有方法 -->
			<tx:method name="get*" read-only="true" />
			<tx:method name="query*" read-only="true" />
			<tx:method name="select*" read-only="true" />
		</tx:attributes>
	</tx:advice>
	<!-- ========================事务控制配置结束======================== -->

</beans>




2、

Spring与SpringMVC的整合配置:


dispatcherServlet-servlet.xml中的配置:


<?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:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
		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-4.3.xsd">

	<!--SpringMVC的配置文件,包含网站跳转逻辑的控制,配置 -->
	<context:component-scan base-package="com.ywx"
		use-default-filters="false">
		<!--只扫描控制器。 -->
		<context:include-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
	</context:component-scan>

	<!--配置视图解析器,方便页面返回 -->
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/views/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean>

	<!--两个标准配置 -->
	<!-- 将springmvc不能处理的请求交给tomcat -->
	<mvc:default-servlet-handler />
	<!-- 能支持springmvc更高级的一些功能,JSR303校验,快捷的ajax...映射动态请求 -->
	<mvc:annotation-driven />

</beans>




3、Mybatis逆向工程:


导入mybatis逆向工程需要的jar(上面总的pom.xml已提供),配置如下:


<!-- 逆向工程需要的MBG -->
<dependency>
	<groupId>org.mybatis.generator</groupId>
	<artifactId>mybatis-generator-core</artifactId>
	<version>1.3.5</version>
</dependency>

generatorConfig.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>

	<context id="DB2Tables" targetRuntime="MyBatis3">
		<commentGenerator>
			<!-- 设置为true则不生成注释 -->
			<property name="suppressAllComments" value="true" />
		</commentGenerator>
		<!-- 配置数据库连接 -->
		<jdbcConnection driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:mysql://localhost:3306/ssm" userId="root"
			password="root">
		</jdbcConnection>

		<javaTypeResolver>
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>

		<!-- 指定javaBean生成的位置 -->
		<javaModelGenerator targetPackage="com.ywx.ssm.bean"
			targetProject=".\src\main\java">
			<property name="enableSubPackages" value="true" />
			<property name="trimStrings" value="true" />
		</javaModelGenerator>

		<!--指定sql映射文件生成的位置 -->
		<sqlMapGenerator targetPackage="mapper" targetProject=".\src\main\resources">
			<property name="enableSubPackages" value="true" />
		</sqlMapGenerator>

		<!-- 指定dao接口生成的位置,mapper接口 -->
		<javaClientGenerator type="XMLMAPPER"
			targetPackage="com.ywx.ssm.dao" targetProject=".\src\main\java">
			<property name="enableSubPackages" value="true" />
		</javaClientGenerator>


		<!-- table指定每个表的生成策略 -->
		<!-- <table tableName="t_emp" domainObjectName="Employee"></table>
		<table tableName="t_dept" domainObjectName="Department"></table> -->
		<table tableName="xt_dic_config" domainObjectName="DicConfig"></table>
		<table tableName="xt_dic_resource" domainObjectName="DicResource"></table>
	</context>
</generatorConfiguration>


该文件可以在eclipse中运行逆向生成bean对象,为了运行方便写个main程序执行它:

package com.ywx.ssm.test;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

public class MBG {
	public static void main(String[] args) throws Exception {
		List<String> warnings = new ArrayList<String>();
		boolean overwrite = true;
		File configFile = new File("generatorConfig.xml");
		ConfigurationParser cp = new ConfigurationParser(warnings);
		Configuration config = cp.parseConfiguration(configFile);
		DefaultShellCallback callback = new DefaultShellCallback(overwrite);
		MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
				callback, warnings);
		myBatisGenerator.generate(null);

	}

}


4、pagehelper分页插件


引入分页需要的jar,配置如下:


<!-- 引入pagehelper分页插件 -->
<dependency>
	<groupId>com.github.pagehelper</groupId>
	<artifactId>pagehelper</artifactId>
	<version>5.0.1</version>
</dependency>

然后在base工程的resource路径下的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="mapUnderscoreToCamelCase" value="true"/>
	</settings>
	
	<typeAliases>
		<package name="com.ywx.ssm.bean"/>
	</typeAliases>
	<!-- 分页插件 -->
	<plugins>
		<plugin interceptor="com.github.pagehelper.PageInterceptor">
			<!-- 分页参数合理化 -->
			<property name="reasonable" value="true"/>
		</plugin>
	</plugins>

</configuration> 

5、。。。




四、其他


补充:Maven环境的搭建及配置(

jdk版本、私服、继承、聚合、打包部署等的配置



1、


2、


3、






逐步更新中。。。





版权声明:本文为yangwenxue_admin原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。