欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Spring Boot 整合 Mybatis Annotation 注解的完整 Web 案例

 更新時間:2017年05月12日 15:49:47   投稿:mrr  
這篇文章主要介紹了Spring Boot 整合 Mybatis Annotation 注解的完整 Web 案例,需要的朋友可以參考下

前言

距離第一篇 Spring Boot 系列的博文 3 個月了。雖然 XML 形式是我比較推薦的,但是注解形式也是方便的。尤其一些小系統(tǒng),快速的 CRUD 輕量級的系統(tǒng)。

這里感謝曉春 http://xchunzhao.tk/ 的 Pull Request,提供了 springboot-mybatis-annotation 的實現(xiàn)。

一、運行 springboot-mybatis-annotation 工程

然后Application 應(yīng)用啟動類的 main 函數(shù),然后在瀏覽器訪問:

http://localhost:8080/api/city?cityName=溫嶺市

可以看到返回的 JSON 結(jié)果:

{
"id": 1,
"provinceId": 1,
"cityName": "溫嶺市",
"description": "我的家在溫嶺。"
}

三、springboot-mybatis-annotation 工程配置詳解

1.pom 添加 Mybatis 依賴

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>springboot</groupId>
 <artifactId>springboot-mybatis-annotation</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>jar</packaging>
 <name>springboot-mybatis-annotation</name>
 <description>Springboot-mybatis :: 整合Mybatis Annotation Demo</description>
 <!-- Spring Boot 啟動父依賴 -->
 <parent>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-parent</artifactId>
 <version>1.5.1.RELEASE</version>
 </parent>
 <properties>
 <mybatis-spring-boot>1.2.0</mybatis-spring-boot>
 <mysql-connector>5.1.39</mysql-connector>
 </properties>
 <dependencies>
 <!-- Spring Boot Web 依賴 -->
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-web</artifactId>
 </dependency>
 <!-- Spring Boot Test 依賴 -->
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-test</artifactId>
 <scope>test</scope>
 </dependency>
 <!-- Spring Boot Mybatis 依賴 -->
 <dependency>
 <groupId>org.mybatis.spring.boot</groupId>
 <artifactId>mybatis-spring-boot-starter</artifactId>
 <version>${mybatis-spring-boot}</version>
 </dependency>
 <!-- MySQL 連接驅(qū)動依賴 -->
 <dependency>
 <groupId>mysql</groupId>
 <artifactId>mysql-connector-java</artifactId>
 <version>${mysql-connector}</version>
 </dependency>
 <!-- Junit -->
 <dependency>
 <groupId>junit</groupId>
 <artifactId>junit</artifactId>
 <version>4.12</version>
 </dependency>
 </dependencies>
</project>

2.在 CityDao 城市數(shù)據(jù)操作層接口類添加注解 @Mapper、@Select 和 @Results

/**
* 城市 DAO 接口類
*
* Created by xchunzhao on 02/05/2017.
*/
@Mapper // 標(biāo)志為 Mybatis 的 Mapper
public interface CityDao {
/**
* 根據(jù)城市名稱,查詢城市信息
*
* @param cityName 城市名
*/
@Select("SELECT * FROM city")
// 返回 Map 結(jié)果集
@Results({
@Result(property = "id", column = "id"),
@Result(property = "provinceId", column = "province_id"),
@Result(property = "cityName", column = "city_name"),
@Result(property = "description", column = "description"),
})
City findByName(@Param("cityName") String cityName);
}

@Mapper 標(biāo)志接口為 MyBatis Mapper 接口

@Select 是 Select 操作語句

@Results 標(biāo)志結(jié)果集,以及與庫表字段的映射關(guān)系

其他的注解可以看 org.apache.ibatis.annotations 包提供的,如圖:

可以 git clone 下載工程 springboot-learning-example ,springboot-mybatis-annotation 工程代碼注解很詳細(xì)。 https://github.com/JeffLi1993/springboot-learning-example

以上所述是小編給大家介紹的Spring Boot 整合 Mybatis Annotation 注解的完整 Web 案例,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Java Calendar日歷類的使用介紹

    Java Calendar日歷類的使用介紹

    Candendar類是一個抽象類,提供了一些獲取當(dāng)前時間,或者指定的時間的字段和一些方法,我們可以通過一些方法與字段對他進(jìn)行獲取當(dāng)前天或者當(dāng)月的一些信息
    2022-09-09
  • jvm細(xì)節(jié)探索之synchronized及實現(xiàn)問題分析

    jvm細(xì)節(jié)探索之synchronized及實現(xiàn)問題分析

    這篇文章主要介紹了jvm細(xì)節(jié)探索之synchronized及實現(xiàn)問題分析,涉及synchronized的字節(jié)碼表示,JVM中鎖的優(yōu)化,對象頭的介紹等相關(guān)內(nèi)容,具有一定借鑒價值,需要的朋友可以參考下。
    2017-11-11
  • Spring Boot項目中定制攔截器的方法詳解

    Spring Boot項目中定制攔截器的方法詳解

    這篇文章主要介紹了Spring Boot項目中定制攔截器的方法詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-10-10
  • springboot?自定義啟動器的實現(xiàn)

    springboot?自定義啟動器的實現(xiàn)

    本文主要介紹了springboot?自定義啟動器的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-02-02
  • java基礎(chǔ)的詳細(xì)了解第二天

    java基礎(chǔ)的詳細(xì)了解第二天

    這篇文章對Java編程語言的基礎(chǔ)知識作了一個較為全面的匯總,在這里給大家分享一下。需要的朋友可以參考,希望能給你帶來幫助
    2021-08-08
  • JNI實現(xiàn)最簡單的JAVA調(diào)用C/C++代碼

    JNI實現(xiàn)最簡單的JAVA調(diào)用C/C++代碼

    這篇文章主要介紹了JNI實現(xiàn)最簡單的JAVA調(diào)用C/C++代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • java基于C/S模式實現(xiàn)聊天程序(客戶端)

    java基于C/S模式實現(xiàn)聊天程序(客戶端)

    這篇文章主要為大家詳細(xì)介紹了java基于C/S模式實現(xiàn)聊天程序,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • Java transient關(guān)鍵字與序列化操作實例詳解

    Java transient關(guān)鍵字與序列化操作實例詳解

    這篇文章主要介紹了Java transient關(guān)鍵字與序列化操作,結(jié)合實例形式詳細(xì)分析了java序列化操作相關(guān)實現(xiàn)方法與操作注意事項,需要的朋友可以參考下
    2019-09-09
  • java關(guān)鍵字final用法知識點

    java關(guān)鍵字final用法知識點

    在本篇文章里小編給大家分享的是關(guān)于java關(guān)鍵字final用法知識點以及相關(guān)實例內(nèi)容,有需要的朋友們可以學(xué)習(xí)下。
    2019-09-09
  • Spring工作原理簡單探索

    Spring工作原理簡單探索

    這篇文章主要介紹了Spring工作原理簡單探索,涉及Springaop與IOC,動態(tài)代理靜態(tài)代理,反射等相關(guān)內(nèi)容,具有一定參考價值,需要的朋友可以了解下。
    2017-11-11

最新評論