ssm整合模板

  • 为了方便开发,(懒省事)设置一个模板

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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.zhityou100</groupId>
    <artifactId>ssm</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <!-- 集中定义依赖版本号 -->
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <junit.version>4.12</junit.version>
        <spring.version>5.3.9</spring.version>
        <mybatis.version>3.5.1</mybatis.version>
        <mybatis.spring.version>1.3.1</mybatis.spring.version>
        <mybatis.paginator.version>1.2.15</mybatis.paginator.version>
        <mysql.version>5.1.38</mysql.version>
        <slf4j.version>1.6.4</slf4j.version>
        <druid.version>1.1.12</druid.version>
        <pagehelper.version>5.1.2</pagehelper.version>
        <jstl.version>1.2</jstl.version>
        <servlet-api.version>3.0.1</servlet-api.version>
        <jsp-api.version>2.0</jsp-api.version>
        <jackson.version>2.9.6</jackson.version>
    </properties>
    <dependencies>
        <!-- spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!--spring mvc-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!--spring jdbc-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!--spring 切面-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jms</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!--spring text-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- Mybatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>${mybatis.version}</version>
        </dependency>
        <!--mybatis 与 spring 整合-->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>${mybatis.spring.version}</version>
        </dependency>
        <dependency>
            <groupId>com.github.miemiedev</groupId>
            <artifactId>mybatis-paginator</artifactId>
            <version>${mybatis.paginator.version}</version>
        </dependency>
        <!--mybatis 分页插件-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>${pagehelper.version}</version>
        </dependency>
        <!-- MySql -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>
        <!-- 连接池 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>${druid.version}</version>
        </dependency>

        <!-- junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>


        <!-- JSP相关 -->
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>${jstl.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <scope>provided</scope>
            <version>${jsp-api.version}</version>
        </dependency>
        <!-- Jackson Json处理工具包 -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20140107</version>
        </dependency>
        <!--文件异步上传-->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.1</version>
        </dependency>

        <!--log4j 日志文件-->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.2</version>
        </dependency>
        <!--lombok-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.20</version>
        </dependency>
    </dependencies>

    <!-- 插件配置 -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
        <!--识别所有的配置文件-->
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>
</project>

mybatis-conf.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="logImpl" value="STDOUT_LOGGING"/>
        <!--映射下划线到驼峰大小写-->
        <setting name="mapUnderscoreToCamelCase" value="true"/>
    </settings>
    <typeAliases>
        <!--1. 一次性为一个类起别名,-->
        <!--        <typeAlias type="com.zhiyou100.ssm.pojo.User" alias="user"/>-->
        <!--2. 批量起别名
            package标签:为某个包下的所有类批量起别名
                属性 name 指定包名,当前以及下面的后代的每一个类都起一个别名【默认类名小写】
        -->
        <package name="com.zhiyou100.ssm.pojo"/>
        <!--3. package标签 批量起别名的情况下,使用 @Alias注解为某个类型指定新的别名-->
    </typeAliases>
    <!--注册分页插件-->
    <plugins>
        <plugin interceptor="com.github.pagehelper.PageInterceptor">
            <!--分页参数合理化-->
            <property name="reasonable" value="true"/>
        </plugin>
    </plugins>
</configuration>

spring-mybatis.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/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd

       http://www.springframework.org/schema/context
       https://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop
         https://www.springframework.org/schema/aop/spring-aop.xsd
         http://www.springframework.org/schema/tx
         http://www.springframework.org/schema/tx/spring-tx.xsd">
    <!--###########spring核心配置文件############-->

    <!--业务逻辑扫描 与 mybatis 扫描不同,spring值扫描没有标注 controller注解-->
    <!--===============================数据源,事务控制xxx========================================-->
    <!--业务逻辑也要扫描,他和 springmvc 不同它除了控制器不要其他的要-->
    <context:component-scan base-package="com.zhiyou100.ssm">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    <!--spring 的配置文件,这里主要配置业务逻辑有关的-->
    <!--数据源,事务控制,xxx-->
    <context:property-placeholder location="classpath:db.properties"/>
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <!-- 基本属性 url、user、password -->
        <property name="url" value="${mysql.url}"/>
        <property name="driverClassName" value="${mysql.driver}"/>
        <property name="username" value="${mysql.username}"/>
        <property name="password" value="${mysql.password}"/>

        <!-- 配置初始化大小、最小、最大 -->
        <property name="initialSize" value="1" />
        <property name="minIdle" value="1" />
        <property name="maxActive" value="20" />

        <!-- 配置获取连接等待超时的时间 -->
        <property name="maxWait" value="60000" />

        <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
        <property name="timeBetweenEvictionRunsMillis" value="60000" />

        <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
        <property name="minEvictableIdleTimeMillis" value="300000" />

        <property name="validationQuery" value="SELECT 'x'" />
        <property name="testWhileIdle" value="true" />
        <property name="testOnBorrow" value="false" />
        <property name="testOnReturn" value="false" />

        <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
        <property name="poolPreparedStatements" value="true" />
        <property name="maxPoolPreparedStatementPerConnectionSize" value="20" />

        <!-- 配置监控统计拦截的filters,去掉后监控界面sql无法统计 -->
        <property name="filters" value="stat" />
    </bean>
    <!--================================MyBatis 整合配置===============================-->
    <!--  mybatis核心配置  -->
    <bean class="org.mybatis.spring.SqlSessionFactoryBean" id="sqlSessionFactory">
        <!--指定 mybatis==》sqlSessionFactoryBean 创建需要的参数-->
        <!--加载mybatis全局配置文件-->
        <property name="configLocation" value="classpath:mybatis/mybatis-conf.xml"/>
        <!--数据源 datasource-->
        <property name="dataSource" ref="dataSource"/>
        <!--mapperLocations,指定 mybatis mapper.xml 文件的位置-->
        <property name="mapperLocations" value="classpath:mappers/*.xml"/>
    </bean>
    <!--配置扫描器,将mybatis 接口的实现加入到 ioc容器中-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" id="mapperScannerConfigurer">
        <!--扫描所有的 dao接口的实现加入到 ioc容器中,如果需要扫描多个包,中间使用半角逗号隔开-->
        <property name="basePackage" value="com.zhiyou100.ssm.dao"/>
    </bean>
    <!--配置一个可执行批量的 sqlsession-->
    <bean class="org.mybatis.spring.SqlSessionTemplate" id="sessionTemplate">
        <constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory"/>
        <constructor-arg name="executorType" value="BATCH"/>
    </bean>
    <!--===============================事务控制的配置========================================-->
    <bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager">
        <!--控制数据源-->
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!--开启基于注解的事务,使用 xml配置形式的事务【比较主要的都是用配置式】-->
    <aop:config>
        <!--切入点表达式【双点就是 service下的包,包括子包】-->
        <aop:pointcut id="txPoint" expression="execution(* com.zhiyou100.ssm.service..*(..))"/>
        <!--配置事务增强-->
        <aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/>
    </aop:config>
    <!--配置事务增强,事务如何切入-->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <!--name=* 表示所有方法都是事务方法-->
            <tx:method name="*"/>
            <!--以get开始的所有方法 都是只读的 -->
            <tx:method name="get*" read-only="true"/>
        </tx:attributes>
    </tx:advice>
</beans>

spring-mvc.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/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
         https://www.springframework.org/schema/context/spring-context.xsd
         http://www.springframework.org/schema/mvc
         https://www.springframework.org/schema/mvc/spring-mvc.xsd">
    <!--##########SpringMVC 的配置文件,包括网站跳转逻辑的控制###############-->
    <!--扫描所有的业务逻辑组件,配置 use-default-filters:默认是扫描所有的,禁用掉-->
    <context:component-scan base-package="com.zhiyou100.ssm" use-default-filters="false">
        <!--只扫描【控制器】 标注了 Controller的注解-->
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    <!--配置视图解析器 jsp,方便页面返回解析-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!--所有的页面放在 template下 【注意前后斜杠!!!】-->
        <property name="prefix" value="/WEB-INF/template/"/>
        <!--后缀都是 jsp页面-->
        <property name="suffix" value=".jsp"/>
    </bean>
    <!--====两个标准的配置====-->
    <!--将 springmvc 不能处理的请求都交给 tomcat,动态静态都可以访问-->
    <mvc:default-servlet-handler/>
    <!--能支持 springmvc 更高级的一些功能 jsr303,快捷的 ajax、、映射动态请求-->
    <!-- 开启mvc注解驱动 -->
    <mvc:annotation-driven>
        <mvc:message-converters>
            <!-- 处理响应中文内容乱码 -->
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="defaultCharset" value="UTF-8" />
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/html</value>
                        <value>application/json</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

    <!--文件上传 id必须是这个否则报错:multipartResolver-->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!--设置上传最大尺寸为50MB-->
        <property name="maxUploadSizePerFile" value="52428800"/>
        <property name="defaultEncoding" value="UTF-8"/>
        <property name="resolveLazily" value="true"/>
    </bean>

    <!-- 静态资源映射 -->
    <mvc:resources mapping="/css/**" location="/static/css/"/>
    <mvc:resources mapping="/js/**" location="/static/js/"/>
    <mvc:resources mapping="/img/**" location="/static/imgs/"/>
    <mvc:resources mapping="/plugin/**" location="/static/plugin/"/>


    <!--spring 视图,启动访问 index.jsp 欢迎页-->
<!--    <mvc:view-controller path="/" view-name="index"/>-->
</beans>

db.properties

mysql.driver=com.mysql.jdbc.Driver
mysql.url=jdbc:mysql:
mysql.username=root
mysql.password=

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<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/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <!--1. 启动 spring的容器-->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring/spring-mybatis.xml</param-value>
    </context-param>
    <!--配置监听器,来加载spring容器-->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!--2. springmvc 的前端控制器,拦截所有的请求-->
    <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring/spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <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>
    </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>
</web-app>

逆向工程

mgb.xlm

<?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="/Program Files/IBM/SQLLIB/java/db2java.zip" />-->
    <!--
    一个数据库一个 context
    targetRuntime="MyBatis3Simple" :生成简单版的crud
    targetRuntime="MyBatis3" :豪华版
    -->
    <context id="DB2Tables" targetRuntime="MyBatis3">

        <!-- 生成的Java文件的编码 -->
        <property name="javaFileEncoding" value="UTF-8"/>
        <!-- 格式化java代码 -->
        <property name="javaFormatter" value="org.mybatis.generator.api.dom.DefaultJavaFormatter"/>
        <!-- 格式化XML代码 -->
        <property name="xmlFormatter" value="org.mybatis.generator.api.dom.DefaultXmlFormatter"/>
        <!--添加分隔符-->
        <property name="beginningDelimiter" value="'"/>
        <property name="endingDelimiter" value="'"/>


        <!--默认生成getter/setter方法,使用插件忽略生成getter/setter方法-->
        <!--<plugin type="com.mybatis.plugin.IngoreSetterAndGetterPlugin" />-->
        <!--用于在实体类中实现java.io.Serializable接口-->
        <plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
        <!--用于重写equals 和 hashCode 方法-->
        <plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin">
            <property name="useEqualsHashCodeFromRoot" value="true"/>
        </plugin>
        <!--用于生成 toString 方法-->
        <plugin type="org.mybatis.generator.plugins.ToStringPlugin">
            <property name="useToStringFromRoot" value="true"/>
        </plugin>

        <!--生成注释信息的配置-->
        <commentGenerator>
            <!--阻止生成注释,默认为false-->
            <property name="suppressAllComments" value="true"/>
            <!--阻止生成的注释包含时间戳,默认为false-->
            <property name="suppressDate" value="true"/>
            <!--注释是否添加数据库表的备注信息,默认为false-->
            <property name="addRemarkComments" value="true"/>
        </commentGenerator>

        <!--jdbcConnection:指定如何连接到数据库-->
        <jdbcConnection
                driverClass="oracle.jdbc.driver.OracleDriver"
                connectionURL="jdbc:oracle:thin:@//192.168.217.64:1521/orcl"
                userId="scott"
                password="scott">
        </jdbcConnection>
        <!--Java类型解析器-->
        <javaTypeResolver>
            <!-- 默认为false,可以把数据库中的decimal以及numeric类型解析为Integer,
            为true时会解析为java.math.BigDecimal) -->
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <!--生成实体类地址
        javaModelGenerator:指定JavaBean的生成策略
                targetPackage=目标报名
                targetProject=目标工程
        -->
        <javaModelGenerator targetPackage="com.zhiyou100.taxi.entity" targetProject=".\src\main\java">
            <property name="enableSubPackages" value="true"/>
            <!-- 是否针对string类型的字段在set的时候进行trim调用 -->
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!--sqlMapGenerator:sql映射生成映射策略-->
        <sqlMapGenerator targetPackage="mappers" targetProject=".\src\main\resources">
            <!-- 是否在当前路径下新加一层schema,
            如果为fase路径com.shop.dao.mapper,
             为true:com.shop.dao.mapper.[schemaName]
             这个情况主要是oracle中有,mysql中没有schema -->
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!--mapper接口生成位置
        javaClientGenerator:指定mapper接口所在的位子-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.zhiyou100.taxi.dao" targetProject=".\src\main\java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <!--指定要逆向分析那些表:根据表创建JavaBean-->
        <!--        <table tableName="" domainObjectName=""/>-->
        <table tableName="tab_car" domainObjectName="Car"/>
        <table tableName="tab_car_check" domainObjectName="CarCheck"/>
        <table tableName="tab_car_in" domainObjectName="CarIn"/>
        <table tableName="tab_car_out" domainObjectName="CarOut"/>
        <table tableName="tab_customer" domainObjectName="Customer"/>
        <table tableName="tab_department" domainObjectName="Department"/>
        <table tableName="tab_dictionary" domainObjectName="Dictionary"/>
        <table tableName="tab_role" domainObjectName="Role"/>
        <table tableName="tab_role_url" domainObjectName="RoleUrl"/>
        <table tableName="tab_url" domainObjectName="Url"/>
        <table tableName="tab_user" domainObjectName="User"/>
        <table tableName="tab_user_role" domainObjectName="UserRole"/>
    </context>
</generatorConfiguration>
public class MbgTest {
	@Test
	public void test1() {
		try {
			ArrayList<String> warnigs = new ArrayList<>();
			boolean overwrite = true;
			File configFile = new File("mbg.xml");//该项目下
			ConfigurationParser cp = new ConfigurationParser(warnigs);
			Configuration config = cp.parseConfiguration(configFile);
			DefaultShellCallback callback = new DefaultShellCallback(overwrite);
			MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnigs);
			myBatisGenerator.generate(null);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

log4j.properties

# Configure logging for testing: optionally with log file
 log4j.rootLogger=WARN, stdout, logfile

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n

log4j.appender.logfile=org.apache.log4j.FileAppender
log4j.appender.logfile.File=target/ForestBlog.log
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n

其他

  • mapper:mybatis的 mapper.xml 文件
  • static:web的资源文件:比如 jquery.js
  • template:页面
posted @ 2021-11-12 21:44  MikiKawai  阅读(73)  评论(0编辑  收藏  举报