마이바티스의 기본 이해하기
ㅋㅋㅋ 보고되었습니다!)
<?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核心配置 配置文件的根元素 --><configuration> <!-- 属性:定义配置外在化 --> <properties></properties> <!-- 设置:定义mybatis的一些全局性设置 --> <settings> <!-- 具体的参数名和参数值 --> <setting></setting> </settings> <!-- 类型名称:为一些类定义别名 --> <typealiases> <!-- 实体类少 建议 第一种取别名方式--> <typealias></typealias> <!--实体类多 建议 第二种取别名方式 默认情况下用这种方式 别名为类名 首字母最好小写 --> <package></package> </typealiases> <!-- 类型处理器:定义Java类型与数据库中的数据类型之间的转换关系 --> <typehandlers></typehandlers> <!-- 对象工厂 --> <objectfactory></objectfactory> <!-- 插件:mybatis的插件,插件可以修改mybatis的内部运行规则 --> <plugins> <plugin></plugin> </plugins> <!-- 环境:配置mybatis的环境 --> <environments> <!-- 环境变量:可以配置多个环境变量,比如使用多数据源时,就需要配置多个环境变量 --> <environment> <!-- 事务管理器 --> <transactionmanager></transactionmanager> <!-- 数据源 配置连接我的数据库--> <datasource> <property></property> <property></property> <property></property> <property></property> </datasource> </environment> </environments> <!-- 数据库厂商标识 --> <databaseidprovider></databaseidprovider> <!-- 映射器:指定映射文件或者映射类 --> <mappers> <mapper></mapper> </mappers></configuration>

데이터 액세스 감소 limt는 페이징을 구현합니다 sql 문: select * from table name limt 0,5;0: 데이터의 시작 위치
5: 길이 the data하나: Mybatis 1 인터페이스
List<user> getUserByLimit(Map<string> map);</string></user>
<select> select * from mybatis.user limit ${starIndex},${pageSize} </select>
<resultmap> <result></result> </resultmap>
3 test
@Test public void getUserByLimitTest() { SqlSession sqlSession = MyBatisUtils.getSqlSession (); UserMapper mapper = sqlSession.getMapper (UserMapper.class); HashMap hashMap = new HashMap<string> (); hashMap.put ("starIndex", 1); hashMap.put ("pageSize", 2); List userByLimit = mapper.getUserByLimit (hashMap); for (Object o : userByLimit) { System.out.println (o); } sqlSession.close (); }</string>
- 두 번째: RowBounds 메서드 사용
- 1.인터페이스
- List getUserList() ; 2. 인터페이스 구현
<select> select * from mybatis.user </select>
3. 테스트: /**
* 测试使用RowBounds实现分页
*/@Test
public void getUserByLimitRowBoundsTest() {
SqlSession sqlSession = MyBatisUtils.getSqlSession ();
RowBounds rowBounds = new RowBounds (0, 2);
List<user> userList = sqlSession.selectList ("com.kuang.w.dao.UserMapper.getUserList", null, rowBounds);
for (User user : userList) {
System.out.println (user);
}
//关闭
sqlSession.close ();
}</user>
세 번째 방법: Mybatis의 페이징 플러그인 pageHeIper
sql 다대일 처리
사용 데이터베이스:
pojo
package com.kuang.w.pojo; import lombok.Data; /** * @author W */ @Data public class Teacher { private int tId; private String tName; }
package com.kuang.w.pojo;import lombok.Data;/** * @author W */@Datapublic class Student { private int id; private int tid; private String name; private String password; private Teacher teacher;}
List<student> getStudentList();</student>
<!-- 多对一查询 1 子查询 mysql 通过一个表里是数据 与另一个表的一个数据相的情况下 查询另一个的数据 一起显示 --> <select> select * from mybatis.user; </select> <resultmap> <!-- 复杂属性 对象用 :association 集合用:collection--> <!--column 数据库中的字段 property 实体类中的属性--> <result></result> <result></result> <result></result> <!--javaType 一个 Java 类的全限定名 ,或一个类型别名(关于内置的类型别名,可以参考上面的表格)。 如果你映射到一个 JavaBean,MyBatis 通常可以推断类型。 然而,如果你映射到的是 HashMap, 那么你应该明确地指定 javaType 来保证行为与期望的相一致。--> <association></association> </resultmap> <select> select * from mybatis.teacher_table where tid = #{id}; </select>
mybatis-config.xm 구성

<!--2 多表联查--> <select> select u.id uid, u.name uname, u.password upassword, u.tid utid, t.tname from mybatis.user u, mybatis.teacher_table t where t.tid = u.tid; </select> <!-- 映射--> <resultmap> <result></result> <result></result> <result></result> <result></result> <association> <result></result> </association> </resultmap>
<?xml version="1.0" encoding="UTF8" ?>nbsp;configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration> <properties></properties> <settings> <setting></setting> </settings> <typealiases> <typealias></typealias> <typealias></typealias> </typealiases> <environments> <environment> <transactionmanager></transactionmanager> <datasource> <property></property> <property></property> <property></property> <property></property> </datasource> </environment> </environments> <mappers> <!-- <mapper resource="com/kuang/w/dao/TeacherMapper.xml"></mapper> <mapper resource="com/kuang/w/dao/StudentMapper.xml"></mapper>--> <mapper></mapper> <mapper></mapper> </mappers></configuration>
데이터 테이블 구조에 해당하는 엔터티 클래스는 변경되지 않습니다.
첫 번째 방법: 다중 테이블 공동 쿼리
@Test public void getStudentListTest() { SqlSession sqlSession = MyBatisUtils.getSqlSession (); StudentMapper mapper = sqlSession.getMapper (StudentMapper.class); List<student> studentList = mapper.getStudentList (); for (Student student : studentList) { System.out.println (student); } sqlSession.commit (); sqlSession.close (); }</student>
List<teacher> getTeacher(int tid);</teacher>
<select> select t.tid, t.tname, u.id, u.name, u.password from mybatis.user u, mybatis.teacher_table t where t.tid = u.tid and t.tid = #{tid}; </select>
<resultmap> <result></result> <result></result> <!-- 复杂属性 对象用 :association 集合用:collection--> <collection> <!--javaType 指定属性类型 一个 Java 类的全限定名--> <result></result> <result></result> <result></result> <result></result> </collection> </resultmap>
/*测试一对多*/ @Test public void getTeacherTest2() { SqlSession sqlSession = MyBatisUtils.getSqlSession (); TeacherMapper mapper = sqlSession.getMapper (TeacherMapper.class); List<teacher> teacher = mapper.getTeacher (1); for (Teacher teacher1 : teacher) { System.out.println (teacher1); } //提交事务 架子 这里可以不要 sqlSession.commit (); // 关闭 sqlSession.close (); }</teacher>
1인터페이스com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 com.kuang.w.dao.myTest,getTeacherTest2
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.PooledDataSource forcefully closed/removed all connections.PooledDataSource forcefully closed/removed all connections.PooledDataSource forcefully closed/removed all connections.PooledDataSource forcefully closed/removed all connections.Opening JDBC Connection
Created connection 164974746.Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@9d5509a]==> Preparing: select t.tid, t.tname, u.id, u.name, u.password from mybatis.user u, mybatis.teacher_table t where t.tid = u.tid and t.tid = ?; ==> Parameters: 1(Integer)
List<teacher> getTeacher(int tid);</teacher>
3테스트 위와 같습니다. . . .
관련 무료 학습 권장 사항:
(동영상)
위 내용은 마이바티스의 기본 이해하기의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

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

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

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

Clothoff.io
AI 옷 제거제

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

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

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

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

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

뜨거운 주제











InnoDB의 전체 텍스트 검색 기능은 매우 강력하여 데이터베이스 쿼리 효율성과 대량의 텍스트 데이터를 처리 할 수있는 능력을 크게 향상시킬 수 있습니다. 1) InnoDB는 기본 및 고급 검색 쿼리를 지원하는 역 색인화를 통해 전체 텍스트 검색을 구현합니다. 2) 매치 및 키워드를 사용하여 검색, 부울 모드 및 문구 검색을 지원합니다. 3) 최적화 방법에는 워드 세분화 기술 사용, 인덱스의 주기적 재건 및 캐시 크기 조정, 성능과 정확도를 향상시키는 것이 포함됩니다.

이 기사는 MySQL의 Alter Table 문을 사용하여 열 추가/드롭 테이블/열 변경 및 열 데이터 유형 변경을 포함하여 테이블을 수정하는 것에 대해 설명합니다.

전체 테이블 스캔은 MySQL에서 인덱스를 사용하는 것보다 빠를 수 있습니다. 특정 사례는 다음과 같습니다. 1) 데이터 볼륨은 작습니다. 2) 쿼리가 많은 양의 데이터를 반환 할 때; 3) 인덱스 열이 매우 선택적이지 않은 경우; 4) 복잡한 쿼리시. 쿼리 계획을 분석하고 인덱스 최적화, 과도한 인덱스를 피하고 정기적으로 테이블을 유지 관리하면 실제 응용 프로그램에서 최상의 선택을 할 수 있습니다.

예, MySQL은 Windows 7에 설치 될 수 있으며 Microsoft는 Windows 7 지원을 중단했지만 MySQL은 여전히 호환됩니다. 그러나 설치 프로세스 중에 다음 지점이 표시되어야합니다. Windows 용 MySQL 설치 프로그램을 다운로드하십시오. MySQL의 적절한 버전 (커뮤니티 또는 기업)을 선택하십시오. 설치 프로세스 중에 적절한 설치 디렉토리 및 문자를 선택하십시오. 루트 사용자 비밀번호를 설정하고 올바르게 유지하십시오. 테스트를 위해 데이터베이스에 연결하십시오. Windows 7의 호환성 및 보안 문제에 주목하고 지원되는 운영 체제로 업그레이드하는 것이 좋습니다.

클러스터 인덱스와 비 클러스터 인덱스의 차이점은 1. 클러스터 된 인덱스는 인덱스 구조에 데이터 행을 저장하며, 이는 기본 키 및 범위별로 쿼리에 적합합니다. 2. 클러스터되지 않은 인덱스는 인덱스 키 값과 포인터를 데이터 행으로 저장하며 비 예산 키 열 쿼리에 적합합니다.

기사는 MySQL Workbench 및 Phpmyadmin과 같은 인기있는 MySQL GUI 도구에 대해 논의하여 초보자 및 고급 사용자를위한 기능과 적합성을 비교합니다. [159 자].

기사는 MySQL에서 파티셔닝, 샤딩, 인덱싱 및 쿼리 최적화를 포함하여 대규모 데이터 세트를 처리하기위한 전략에 대해 설명합니다.

이 기사에서는 Drop Table 문을 사용하여 MySQL에서 테이블을 떨어 뜨리는 것에 대해 설명하여 예방 조치와 위험을 강조합니다. 백업 없이는 행동이 돌이킬 수 없으며 복구 방법 및 잠재적 생산 환경 위험을 상세하게합니다.
