1. Mybatis 프레임워크
1. mybatis 소개
MyBatis는 맞춤형 SQL, 저장 프로시저 및 고급 매핑을 지원하는 뛰어난 지속성 계층 프레임워크입니다. MyBatis는 거의 모든 JDBC 코드와 매개변수 수동 설정 및 결과 세트 검색을 방지합니다. MyBatis는 간단한 XML 또는 주석을 사용하여 기본 유형, 인터페이스 및 Java POJO(Plain Old Java Objects, Plain Old Java Object)를 구성하고 데이터베이스의 레코드에 매핑할 수 있습니다.
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>
7. 컨트롤 레이어 테스트 클래스
@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>
3. 페이징 플러그인 통합
1. @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>
2. 페이징 구현 코드http://localhost:8010/insert
http://localhost:8010/selectByExample
http://localhost:8010/updateByPrimaryKeySelective
http://localhost:8010/deleteByPrimaryKey
3. 테스트 인터페이스<?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>
위 내용은 SpringBoot2에 Mybatis 프레임워크를 통합하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

드림위버 CS6
시각적 웹 개발 도구

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는
