1. Mybatis フレームワーク
1. mybatis の概要
MyBatis は、カスタマイズされた SQL、ストアド プロシージャ、高度なマッピングをサポートする優れた永続層フレームワークです。 MyBatis は、ほとんどすべての JDBC コード、パラメータの手動設定、結果セットの取得を回避します。 MyBatis は、単純な XML または注釈を使用して、ネイティブ型、インターフェイス、および Java POJO (Plain Old Java Object、プレーン オールド Java オブジェクト) を構成し、データベース内のレコードにマッピングできます。
2. Mybatis の機能
1)sql语句与代码分离,存放于xml配置文件中,方便管理 2)用逻辑标签控制动态SQL的拼接,灵活方便 3)查询的结果集与java对象自动映射 4)编写原生态SQL,接近JDBC 5)简单的持久化框架,框架不臃肿简单易学
3. 適用可能なシナリオ
MyBatis は SQL 自体に焦点を当てており、十分に柔軟な DAO レイヤー ソリューションです。
MyBatis は、高いパフォーマンス要件があるプロジェクトやニーズの変化があるプロジェクトに適しています。
2. SpringBoot2 との統合
1. プロジェクト構造図
druid 接続プールを使用する、この接続プール。
2. コアの依存関係
<!-- mybatis依赖 --> <dependency> <groupid>org.mybatis.spring.boot</groupid> <artifactid>mybatis-spring-boot-starter</artifactid> <version>1.3.2</version> </dependency> <!-- mybatis的分页插件 --> <dependency> <groupid>com.github.pagehelper</groupid> <artifactid>pagehelper</artifactid> <version>4.1.6</version> </dependency>
3. コア構成
mybatis: # mybatis配置文件所在路径 config-location: classpath:mybatis.cfg.xml type-aliases-package: com.boot.mybatis.entity # mapper映射文件 mapper-locations: classpath:mapper/*.xml
4. リバース エンジニアリングによって生成されたファイル
ここにはコードを投稿しません。
5. 基本的なテスト インターフェイスを作成します
// 增加 int insert(ImgInfo record); // 组合查询 List<img info alt="SpringBoot2 に Mybatis フレームワークを統合する方法" > selectByExample(ImgInfoExample example); // 修改 int updateByPrimaryKeySelective(ImgInfo record); // 删除 int deleteByPrimaryKey(Integer imgId);</imginfo>
6. インターフェイス実装を作成します
@Service public class ImgInfoServiceImpl implements ImgInfoService { @Resource private ImgInfoMapper imgInfoMapper ; @Override public int insert(ImgInfo record) { return imgInfoMapper.insert(record); } @Override public List<img info alt="SpringBoot2 に Mybatis フレームワークを統合する方法" > selectByExample(ImgInfoExample example) { return imgInfoMapper.selectByExample(example); } @Override public int updateByPrimaryKeySelective(ImgInfo record) { return imgInfoMapper.updateByPrimaryKeySelective(record); } @Override public int deleteByPrimaryKey(Integer imgId) { return imgInfoMapper.deleteByPrimaryKey(imgId); } }</imginfo>
7. 制御層テスト クラス
@RestController public class ImgInfoController { @Resource private ImgInfoService imgInfoService ; // 增加 @RequestMapping("/insert") public int insert(){ ImgInfo record = new ImgInfo() ; record.setUploadUserId("A123"); record.setImgTitle("博文图片"); record.setSystemType(1) ; record.setImgType(2); record.setImgUrl("https://avatars0.githubusercontent.com/u/50793885?s=460&v=4"); record.setLinkUrl("https://avatars0.githubusercontent.com/u/50793885?s=460&v=4"); record.setShowState(1); record.setCreateDate(new Date()); record.setUpdateDate(record.getCreateDate()); record.setRemark("知了"); record.setbEnable("1"); return imgInfoService.insert(record) ; } // 组合查询 @RequestMapping("/selectByExample") public List<img info alt="SpringBoot2 に Mybatis フレームワークを統合する方法" > selectByExample(){ ImgInfoExample example = new ImgInfoExample() ; example.createCriteria().andRemarkEqualTo("知了") ; return imgInfoService.selectByExample(example); } // 修改 @RequestMapping("/updateByPrimaryKeySelective") public int updateByPrimaryKeySelective(){ ImgInfo record = new ImgInfo() ; record.setImgId(11); record.setRemark("知了一笑"); return imgInfoService.updateByPrimaryKeySelective(record); } // 删除 @RequestMapping("/deleteByPrimaryKey") public int deleteByPrimaryKey() { Integer imgId = 11 ; return imgInfoService.deleteByPrimaryKey(imgId); } }</imginfo>
8. テスト シーケンス
http://localhost:8010/insert http://localhost:8010/selectByExample http://localhost:8010/updateByPrimaryKeySelective http://localhost:8010/deleteByPrimaryKey
3. 統合ページング プラグイン
1、mybatis 設定ファイル
<?xml version="1.0" encoding="UTF-8" ?> nbsp;configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <plugins> <!--mybatis分页插件--> <plugin> <property></property> </plugin> </plugins> </configuration>
2、ページング実装コード
@Override public PageInfo<img info alt="SpringBoot2 に Mybatis フレームワークを統合する方法" > queryPage(int page,int pageSize) { PageHelper.startPage(page,pageSize) ; ImgInfoExample example = new ImgInfoExample() ; // 查询条件 example.createCriteria().andBEnableEqualTo("1").andShowStateEqualTo(1); // 排序条件 example.setOrderByClause("create_date DESC,img_id ASC"); List<img info alt="SpringBoot2 に Mybatis フレームワークを統合する方法" > imgInfoList = imgInfoMapper.selectByExample(example) ; PageInfo<img info alt="SpringBoot2 に Mybatis フレームワークを統合する方法" > pageInfo = new PageInfo(imgInfoList) ; return pageInfo ; }</imginfo></imginfo></imginfo>
3、テスト インターフェイス
http://localhost:8010/queryPage
以上がSpringBoot2 に Mybatis フレームワークを統合する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

ドリームウィーバー CS6
ビジュアル Web 開発ツール

AtomエディタMac版ダウンロード
最も人気のあるオープンソースエディター

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

DVWA
Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、
