①直接添加
目前整合所用到的jar包:
aspectjweaver-1.8.9.jar
c3p0-0.9.1.jar
commons-logging-1.2.jar
jackson-annotations-2.8.0.jar
jackson-core-2.8.8.jar
jackson-databind-2.8.8.jar
jsqlparser-0.9.5.jar
jstl-1.2.jar
mybatis-3.4.2.jar
mybatis-generator-core-1.3.5.jar
mybatis-spring-1.3.1.jar
mysql-connector-java-5.1.41.jar
pagehelper-5.0.0.jar
spring-aop-4.3.7.RELEASE.jar
spring-aspects-4.3.7.RELEASE.jar
spring-beans-4.3.7.RELEASE.jar
spring-context-4.3.7.RELEASE.jar
spring-core-4.3.7.RELEASE.jar
spring-expression-4.3.7.RELEASE.jar
spring-jdbc-4.3.7.RELEASE.jar
spring-tx-4.3.7.RELEASE.jar
spring-web-4.3.7.RELEASE.jar
spring-webmvc-4.3.7.RELEASE.jar
②Maven方式添加:pom.xml
数据库相关信息:dbconfig.properties
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.233.128:3306/mybatis
jdbc.username=root
jdbc.password=*********
#jdbc.driver=oracle.jdbc.OracleDriver
#jdbc.url=jdbc:oracle:thin:@localhost:1521:orcl
#jdbc.username=scott
#jdbc.password=scott
mybatis的配置文件:mybatis-config.xml
web.xml的配配置:
web.xml没有配置字符编码过滤器,需要自己添加
SpringMVC的配置:dispatcherServlet-servlet.xml
【注:当wen.xml不指定springmvc配置文件位置的时候,可以用这种方式来进行配置(servlet名-servlet.xml)】
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
spring的配置文件:applicationContext.xml
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
mybatis的逆向工程配置:MBG.xml
官网:http://www.mybatis.org/mybatis-3/
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
userId="root"
password="koonisession97">
逆向工程代码:TestMBG.java
官网:http://www.mybatis.org/generator
package com.hz.mybatis.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 TestMBG {
public static void main(String[] args) throws Exception {
List
boolean overwrite = true;
File configFile = new File("mybatis-generator.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);
}
}
到此配置文件就编写完成,接下来进行测试:
JSP页面:
效果:
点击:显示数据
点击:清除数据
over~~~