您的位置:首頁/技術文章
文章詳情頁

JavaEE Spring MyBatis如何一步一步實現數據庫查詢功能

瀏覽:61日期:2023-08-20 09:32:52

配置好一個SptingBoot項目配置好MyBatis

JavaEE Spring~MyBatis是什么? 它和Hibernate的區別有哪些?如何配置MyBatis?

SpringBoot配置文件application.properties簡單介紹

JavaEE Spring MyBatis如何一步一步實現數據庫查詢功能JavaEE Spring MyBatis如何一步一步實現數據庫查詢功能JavaEE Spring MyBatis如何一步一步實現數據庫查詢功能JavaEE Spring MyBatis如何一步一步實現數據庫查詢功能

確保MyBatis配置正確

JavaEE Spring MyBatis如何一步一步實現數據庫查詢功能JavaEE Spring MyBatis如何一步一步實現數據庫查詢功能

手動實現一個xml文件

上面我是用的是一個自定義的接口 此時沒有它對應的xml文件 此時我們需要

JavaEE Spring MyBatis如何一步一步實現數據庫查詢功能

下圖中column表示查詢列, property表示返回類型中的屬性

JavaEE Spring MyBatis如何一步一步實現數據庫查詢功能JavaEE Spring MyBatis如何一步一步實現數據庫查詢功能

在Controller中進行測試

package listen.controller;import listen.mapper.TestMapper;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;/** * Created with IntelliJ IDEA. * Description: If you don’t work hard, you will a loser. * User: Listen-Y. * Date: 2020-08-21 * Time: 23:14 */@RestController@RequestMapping(value = 'user')public class MyselfTest { @Autowired private TestMapper testMapper; @RequestMapping(value = 'test') public Object test() { return testMapper.query(1); }}

JavaEE Spring MyBatis如何一步一步實現數據庫查詢功能

總結

到此這篇關于JavaEE Spring MyBatis如何一步一步實現數據庫查詢功能的文章就介紹到這了,更多相關JavaEE Spring MyBatis數據庫查詢內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Java
相關文章:
国产综合久久一区二区三区