머리말
Mybatis Mapper 파일에 Select, Insert, Update 및 Delete 요소에는 Mapper 인터페이스 메소드에 의해 허용되는 해당 매개 변수 유형에 사용되는 ParameterType 속성이 있습니다. 이 기사는 주로 mybatis의 매개 변수 매개 변수 유형에 대한 관련 내용을 소개합니다. 참조와 학습을 위해 공유됩니다. 나는 아래에서 많이 말하지 않을 것입니다. 자세한 소개를 함께 살펴 보겠습니다.
1. 매개 변수 유형의 mybatis 유형은 두 가지 유형으로 나뉩니다.
1. 1. 기본 데이터 유형 : int, String, Long, Date;
1. 2. 복잡한 데이터 유형 : 클래스 및 맵
2. 매개 변수에서 값을 얻는 방법 :
2.1 기본 데이터 유형 : #{파라미터} 매개 변수에서 값 가져옵니다.
2.2 복잡한 데이터 유형 : #{속성 이름}, #{key}
3. 사례 :
3.1 기본 데이터 유형 사례
<sql id = "base_column_list"> id, car_dept_name, car_maker_name, iCon, car_maker_py, hot_type < /sql> <select id = "selectByPrimaryKey"resultMap = "baseresultMap"parameterType = "java.lang.lang.lang"vanue refid = "vase refid ="vaseeresultmap "java.lang.lang" common_car_make where id = #{id, jdbctype = bigint} </select>3.2 복잡한 유형 맵 유형
< "QueryCarmakerList"resultmap = "vaseresultMap"ParameterType = "java.util.map"> select <common_car_make cm에서 refid = "base_column_list" /> includ <refid = "id! = null"> 및 cm.id = # #< # # # # # #if} if includ includ <refid = "base_column_list" /> includ < test = "cardeptname! = null"> 및 cm.car_dept_name = #{cardeptname, jdbctype = varchar} </if> <if test = "carmakername! = null"> 및 cm.car_maker_name = #{carmakername, jdbctype = varchar} <if test = "null"> if test. 그리고 cm.hot_type = #{Hottype, jdbctype = bigint} </if> cm.id </select>3.3 복잡한 유형 수업 유형
<업데이트 id = "updateByPrimaryKeySelective"parameterType = "com.epeit.api.model.commonCarmake"> 업데이트 common_car_make <set> <if test = "cardeptname! = null"> car_dept_name = #{cardeptname, jdbctype = varchar}, </if> if test = "" > car_maker_name = #{carmakername, jdbctype = varchar}, </if> <if test = "icon! = null"> icon = #{icon, jdbctype = varchar}, </if> if test = "carmakerpy! = null"> car_maker_py = #{carmakerpy, jdbcmakerpy, jdbcmakerpy. </if> <test = "hottype! = null"> hot_type = #{hottype, jdbctype = bigint}, </if> </set> id = #{id, jdbctype = bigint} </update>3.4 복잡한 유형-배열이 맵에 포함 된 경우
<select id = "selectProorderByOrdId"resultType = "com.epeit.api.model.model.porder"parametertype = "java.util.hashmap"> select sum (pro_order_num) proordernum, product_id productId, promotion_id promotion, promotion_id promotion 1 = 1 <111 < ""orderiz ". 항목 = "항목"Open = "Order_Id in ("seplicator = ","close = ")"> #{item, jdbctype = bigint} </foreach> </if> group by product_id, promotion_id </select>4. 주석 @Param : 이것은 매우 특별하지만 이해하기 쉽습니다.
Case 1:
@Param(value="startdate") String startDate : 단일 속성에 주석을 달았습니다. 이것은 매개 변수를 한 번 바꾸는 것과 유사합니다
예를 들어 *mapper.xml mybatis에서 sql 문 (dao layer)을 구성합니다.
list <string> selectIdBySortTime (@param (value = "startDate") StrattDate);
그런 다음 XML의 명령문은 @Param 브래킷의 내용과 일치해야합니다. 매개 변수는 startDate입니다.
<select id = "selectIdBySortTime"resultType = "java.lang.string"parametertype = "java.lang.string"> sorttime> = to_date (#{startDate, jdbctype = varChar}, 'yyyyy-mm-dated and and'sured _) keyValue in Case 2:
주석 javabean,@param (value = "datevo") datevo datevo; 서면 매개 변수에주의를 기울여야합니다
list <string> selectIds (@param (value = "datevo") datevo datevo);
해당 매핑 파일
<select id="selectIds" resultType="java.lang.String" parameterType="com.api.entity.DateVo"> select distinct ajlcid from ebd_fh_ajlc where sorttime >= to_date(# {dateVo.startDate,jdbcType=VARCHAR},'YYYY-MM-DD') and create_date = updated_date 및 keyValue in장점과 단점에 관해서는, 그것은 당신의 개인적인 취향에 따라 다릅니다.
요약
위는이 기사의 전체 내용입니다. 이 기사의 내용에 모든 사람의 연구 나 작업에 대한 특정 참조 가치가 있기를 바랍니다. 궁금한 점이 있으면 의사 소통을 위해 메시지를 남길 수 있습니다. Wulin.com을 지원 해주셔서 감사합니다.