mybatis的配置檔案mybatis-config.xml和對映檔案的mapper.xml的模板
配置檔案mybatis-config.xml(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"> <configuration> <!--配置別名 typeAliases和environments是平等級別的標籤 type是實體類的完整類名 alias是類的別名 --> <typeAliases> <typeAlias type="com.soft.domain.User" alias="User"/> <typeAlias type="com.soft.domain.DeptEntity" alias="DeptEntity"/> <typeAlias type="com.soft.domain.EmpEntity" alias="EmpEntity"/> </typeAliases> <environments default="development"> <environment id="development"> <transactionManager type="JDBC" /> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost/he" /> <property name="username" value="root" /> <property name="password" value="root" /> </dataSource> </environment> </environments> <mappers> <!-- 對映檔案的位置 --> <mapper resource="com/soft/domain/User.xml" /> </mappers> </configuration>
mapper.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd"> <mapper namespace="test"> <!-- parameterType:引數型別,填寫實體類的完整名字 --> <insert id="save" parameterType="cn.chentging.mybatis.entity.Employee"> insert into net_t_emp values(net_t_emp_seq.nextval,#{name},#{age}) </insert> <select id="findAll" resultType="cn.chentging.mybatis.entity.Employee"> select * from net_t_emp </select> <select id="findById" parameterType="int" resultType="cn.chentging.mybatis.entity.Employee"> select * from net_t_emp where id=#{id1} </select> <update id="modify" parameterType="cn.chentging.mybatis.entity.Employee"> update net_t_emp set name=#{name},age=#{age} where id=#{id} </update> <delete id="delete" parameterType="int"> delete from net_t_emp where id=#{id1} </delete> <!-- 返回Map型別的結果 map是java.util.Map的簡寫形式--> <select id="findById2" parameterType="int" resultType="map"> select * from net_t_emp where id=#{id1} </select> <!-- 使用resultMap解決表的欄位名與實體類的屬性名不一致的情況 --> <resultMap type="cn.chentging.mybatis.entity.Emp" id="empRestultMap"> <result property="empNo" column="id"/> <result property="ename" column="name"/> </resultMap> <select id="findById3" parameterType="int" resultMap="empRestultMap"> select * from net_t_emp where id=#{id1} </select> </mapper>
相關推薦
mybatis的配置檔案mybatis-config.xml和對映檔案的mapper.xml的模板
配置檔案mybatis-config.xml(sqlMapConfig.xml) <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org/
Mybatis 學習筆記——配置檔案SqlMapConfig.xml和對映檔案Mapper.xml
一、SqlMapConfig.xml (一)properties(屬性) 將資料庫連線引數單獨配置在db.properties中,只需要在SqlMapConfig.xml中載入db.properties的屬性值。在SqlMapConfig.xml中就不需要對
利用eclipse工具反向生成hibernate配置檔案,domain類和對映檔案
首先要意識到eclipse是一個整合開發環境,要想實現更多的功能,就必須下載好相關的外掛 1.下載外掛 點選help->install new software,輸入相應的網址(對應的自行百度),這裡是http://download.jboss.org/jbossid
【Mybatis】mapper動態代理和對映檔案配置標籤
提要:主要演示了mybatis中,在類中的其他自定義類,在sql語句中如何取值。sql語句中,範圍sql與集合的對應 一、目錄結構 二、相關實體類 QueryVo package com.test.domain; import java.io.Seria
mybatis generatorConfig.xml如何執行生成實體類和對映檔案
1.首先在src/main/source目錄下建立\generatorConfig.xml配置檔案 2.配置檔案後執行這個配置檔案的方法:右擊專案--run as--maven build.. 3.在彈出對話方塊裡面點選輸入命令:mybatis-generator:gene
Mybatis關聯查詢之一對多和多對一XML配置詳解
平時在開發過程中dao、bean和XML檔案都是自動生成的,很少寫XML的配置關係,今天記錄一下mybatis的關聯查詢中的多對一和一對多的情況。 首先是有兩張表(學生表Student和老師Teacher表),為了更易懂,這裡只設置了最簡單的幾個必要欄位。表結構如下圖
mybatis自動生成對應表的實體類、介面和對映檔案
使用maven構建的專案,其中整合了mybatis,每次使用時都需要建立model實體類,dao介面和mapper對映檔案,為了方便開發,maven中有一種外掛可以直接生成資料庫表對應的實體類,介面和對映檔案 1.首先要在pom.xml檔案中加入外掛依賴,注意直接放在<
mybatis逆向工程生成pojo類和mapper介面和對映檔案
1.下載mybatis-generator-core-1.3.2-bundle.zip,解壓為mybatis-generator-core-1.3.2-bundle。 2.建立Java工程,匯入mybatis.jar,mybatis-generator.jar,
Mybatis學習---Mybatis逆向工程自動生成程式碼(代替手寫pojo類,Mapper和對映檔案)
學習Mybatis後,學會使用dao層對映檔案和Mapper,從資料庫獲取資料,並將資料封裝為相應的物件儲存。將Mybatis框架使用到SSM專案中,實現了:檢視層 + 業務邏輯層 + 資料訪問層。對於資料庫表不多的情況,正常的使用Mybatis框架:手寫pojo類檔案、da
mybatis配置自帶緩存和第三方緩存
word 序列化 efault slf4j nbsp javase image html 自身 參考:https://mybatis.github.io/mybatis-3/zh/sqlmap-xml.html, http://www.yihaomen.com/articl
spring中mybatis配置資料來源讀取不到properties屬性檔案的問題
<bean id="tomcatJdbcDataSourceFactory" class="com.qunar.db.resource.impl.TomcatJdbcDataSourceFactory"/> <bean id="dataSource
讀取xml和properties檔案
.properties配置檔案經常出現在DBCP連線池的使用中,我們通過讀取此檔案來獲得1、反射須要的類名2、url 3、root 4、password .xml 檔案出現在C3P0連線池的使用中,作為配置檔案,當然,C3P0也支援使用.properties 作為配置檔案,我們同樣須要從.x
idea hibernate反轉pojo實體類和對映檔案
![](https://img2018.cnblogs.com/blog/782772/201811/782772-20181106142813914-1007317839.png) ![](https://img2018.cnblogs.com/blog/782772/201811/782772-201
輸入輸出XML和YAML檔案
示例程式:XML和YAML檔案的寫入 //----------------輸入輸出XML和YAML檔案------------------------------------ //描述:XML:可擴充套件標識語言----開發者根據自身需要可定義自己的標記。字尾:.yml // TAML
opencv學習(十七)之XML和YAML檔案讀寫操作
可能大部分人到現在接觸的XML和YAML檔案很少,等以後訓練人臉模型進行人臉識別的時候用的就多了。現在先了解一下這兩種檔案型別。 XML:Extensible Markup Language,可擴充套件標記語言,標準通用語言的子集,是一種用於標記電子檔案使其具
opencv(c++)檔案輸入和輸出使用XML和YAML檔案
你會找到以下問題的答案: 如何使用YAML或XML檔案列印和讀取文字和OpenCV檔案? 如何為OpenCV資料結構做同樣的事情? 如何為你的資料結構做到這一點? 使用OpenCV資料結構,如cv :: FileStorage,cv :: F
OpenCV讀寫xml和yml檔案
轉自:https://www.cnblogs.com/skyfsm/p/7182313.html?utm_source=itdadao&utm_medium=referral有時候我們處理完影象後需要儲存一下資料到檔案上,以供下一步的處理。一個比較廣泛的需求場景就是:
opencv學習筆記(二)-對xml和yaml檔案的讀寫操作
一.xml和yaml的簡單介紹 所謂的xml,就是eXtensible Markup Language, 翻譯成中文就是“可擴充套件標識語言“。首先XML是一種元標記語言,所謂“元標記”就是開發者可以根據自己的需要定義自己的標記,比如開發者可以定義如下標記&
C# EMGU 3.4.1學習筆記(二)XML和YAML檔案的寫入
以下是《OpenCV3程式設計入門》中5.6.3的示例程式的C# + EMGU 3.4.1版,和C++程式相比,有如下幾點不同: 1. 使用Matrix<>儲存多維陣列,多維陣列的各維需要使用{}擴起來,之間用逗號分隔; 2. C#中無法使用<<和
Linux下配置檔案隱藏屬性chattr和顯示檔案隱藏屬性lsattr
通過學習鳥哥的私房菜配置檔案隱藏屬性chattr和顯示檔案隱藏屬性lsattr,為了方便學習總結如下內容,方便以後查閱。 1.配置檔案隱藏屬性chattr 2.顯示檔案隱藏屬性lsattr