天天看點

mybatis_入門程式Mybatis入門

Mybatis入門

(一)、程式環境

1、jar包

mybatis_入門程式Mybatis入門

2、classpath目錄下建立SqlMapConfig.xml。

mybatis的配置檔案。全部設定有如下

mybatis_入門程式Mybatis入門

同時,資料庫的參數可以用properties檔案來分開,本次實作分開。properties檔案為db.properties

為了區分目錄。建立一個source folder(config)用來放置配置檔案。兩個檔案分别如下。

mybatis_入門程式Mybatis入門
mybatis_入門程式Mybatis入門

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

3、mapper.xml檔案(User.xml)

一些CURD的語句。

mybatis_入門程式Mybatis入門

4、SqlMapConfig.xml加上mapper.xml

 如,2中的mappers标簽。

mybatis_入門程式Mybatis入門

5、日志記錄

友善檢視運作狀态。

mybatis_入門程式Mybatis入門

(二)、測試程式和程式結構

1、入門程式

mybatis_入門程式Mybatis入門

2、目錄結構

mybatis_入門程式Mybatis入門

(三)、小結

通過配置檔案來建立mybatis環境。之後可以通過SqlSession來操作statement。(SQL語句在xml檔案)

部分select

mybatis_入門程式Mybatis入門

update

mybatis_入門程式Mybatis入門

insert

mybatis_入門程式Mybatis入門

delete

mybatis_入門程式Mybatis入門

轉載于:https://www.cnblogs.com/jway1101/p/5773205.html