mybatis introduction and configuration

First, the concept

1, SpringMVC, what is the principle?

1) The client sends a request, the front end of the Spring capture DispatherServlet

2) parse url, find the handler, execution handler

3) DispatherServlet return ModelandView

4) ModelandView select the appropriate ViewResolver

5) ViewResolver model and view returned to the client

 

2, SpringMVC mvc is a frame, the data to be, separated by business and presentation achieve model-view-controller pattern.

2, the role: to simplify the dao layer, a part of the frame, often called the SSM, or SSI

3. History: The previous version called ibatis, called mybatis after three editions

4. What is the orm?

      object, relational, mapping objects, relationships, mapping

      It simply is a mapping between the entity classes and sql statement

      It is listed entity classes and tables

5, the common entity class named

        entity,bean,model,pojo,vo,form

 

Second, the operating

 

 

Information package provided by the teacher

1, mybatis \ mybatis-generator-core-1.3.2 folder copy in the D drive, easy to operate

2, D: \ mybatis-generator-core-1.3.2 \ lib in this folder, there is a generator.xml file,

Right-click to open with Notepade ++, the comment may garbled, then choose the encoding in the menu bar, choose to use ANSI code, the garbage problem will be solved

In generator.xml file needs to be changed at 6

1)

<! - appropriate database driver mysql: mysql-connector-java-5.1.22-bin.jar; oracl: ojdbc14.jar ->

<classPathEntrylocation="mysql-connector-java-5.1.22-bin.jar"/>

<!--<classPathEntrylocation="ojdbc14.jar"/>-->

 

2)

<-! Database link URL, user name, password, like the need to change with the appropriate name jdbc ->

<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/new" userId="root" password="root">

<!--<jdbcConnection driverClass="oracle.jdbc.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="scott" password="tiger">-->

  </jdbcConnection>

 

3)

<! - package name and location of the generated model ->

<javaModelGenerator targetPackage="com.unite.test.pojo" targetProject="src">

4)

<! - DAO generated name and location of the package ->

<javaClientGenerator type="XMLMAPPER" targetPackage="com.unite.test.dao" targetProject="src">

 

5)

 <! - the package name and location of the generated map file ->

<sqlMapGenerator targetPackage="com.unite.test.mapper" targetProject="src">

 

6)

<! - To generate a table which, there are several tables generated several ->

<table tableName="tabaccount" domainObjectName="Account" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>

 

3, cmd program

Enter d: Enter will

Enter a space to paste the path --cd

- in the last sentence copy generator.xml (java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite) Enter

- automatically generating a corresponding packet in the packet under src lib

4、javaee

1) create a web 3.0 version of the project, tomcat using 9.0, select the Generate web.xml file, guide mybatis required jar package

 

2) mynatis-3-mapper.dtd packet replication under mapper

3) log4j.properties and mybatis-3-config.dtd copy the src file

4) Create a file mybatis.xml

 

Configure the repository to write the correct corresponding database,

After mapping the source via write correctly, hold down cl + left mouse button to jump to the page, there are several paths to write several maps

5) change mapper package, automatically generated file mapper.xml

Change

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "./mybatis-3-mapper.dtd" >

按住cl+鼠标单击可以实现跳转

 

 

 

Guess you like

Origin www.cnblogs.com/wangxue1314/p/11852137.html