mybatis_入門程式,mybatis入門程式

來源:互聯網
上載者:User

mybatis_入門程式,mybatis入門程式
Mybatis入門(一)、程式環境1、jar包

 

 

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

mybatis的設定檔。全部設定有如下

 

 

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

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

 

 

 

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的語句。

 

 

4、SqlMapConfig.xml加上mapper.xml

 如,2中的mappers標籤。

5、日誌記錄

方便查看運行狀態。

 

 

 

(二)、測試程式和程式結構1、入門程式

 

 

2、目錄結構

 

 

 

(三)、小結

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

 

 

部分select

 

 

update

 

 

 

insert

 

 

 

delete

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.