MyBais中xxMap.xml中的知识点

添加新的mapper的时候下面两个标红的地方要注意,如果统一约定好命名的话都还好,但是就怕一会这样一会那样的业务代码;
总之小心!
<!-- spring与mybatis整合配置,扫描所有dao,指定的映射器类是接口,接口方法可以用注解来指定 SQL 语句,但是 MyBatis 的映射器 XML 文件也可以用。 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
p:basePackage="com.cloudwalk.shark.mapper"
p:sqlSessionFactoryBeanName="sqlSessionFactory"/>

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:/spring/mybatis.xml"/>

<property name="typeAliasesPackage" value="com.cloudwalk.shark.model"/>

<property name="mapperLocations" value="classpath*:mapper/*.xml"/>
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<!--使用下面的方式配置参数,一行配置一个 -->
<value>
dialect=mysql
</value>
</property>
</bean>
</array>
</property>
</bean>


<resultMap id="advertResult" type="cn.bankbrain.advert.inter.service.advert.result.AdvertResult">

<id property="id" column="ID" jdbcType="VARCHAR"></id>
<result property="commercialId" column="COMMERCIAL_ID" jdbcType="VARCHAR"></result>
<result property="planName" column="PLAN_NAME" jdbcType="VARCHAR"></result>
<result property="startDate" column="START_DATE" jdbcType="VARCHAR"></result>
<result property="endDate" column="END_DATE" jdbcType="VARCHAR"></result>
<result property="version" column="VERSION" jdbcType="VARCHAR"></result>
<result property="adStatus" column="AD_STATUS" jdbcType="VARCHAR"></result>
<result property="adType" column="AD_TYPE" jdbcType="VARCHAR"></result>
<result property="merchantName" column="MERCHANT_NAME" jdbcType="VARCHAR"></result>
<result property="isForver" column="IS_FORVER" jdbcType="VARCHAR"></result>
<collection property="advertFileList" ofType="cn.bankbrain.advert.inter.service.advert.result.AdvertFileResult">
<result property="filePath" column="FILE_PATH" jdbcType="VARCHAR"/>
<result property="fileName" column="FILE_NAME" jdbcType="VARCHAR"/>
</collection>
</resultMap>

<sql id="querySql">a.id,a.plan_name ,a.version,
a.start_date ,a.end_date , a.ad_status ,
m.merchant_name ,a.commercial_id,f.file_path,f.file_name,
case when a.start_date is null or a.end_date is null
then 1 else 0 end as is_forver
</sql>

<!--查询条件集-->
<sql id="condition_list">
where 1=1
<if test="id != null">AND a.ID = #{id}</if>
<if test="merchantName != null">AND m.MERCHANT_NAME = #{merchantName}</if>
</sql>

<select id="findAdvertByMap" parameterType="java.util.Map" resultMap="advertResult">
select <include refid="querySql"></include>
from cw_pay_advert a join CW_PAY_COMMERCIAL_TENANT m on
a.commercial_id = m.id
left join cw_pay_advert_file f on a.id = f.advert_id
<include refid="condition_list"></include>
</select>
posted @ 2019-05-15 10:02  龙X  阅读(1001)  评论(0编辑  收藏  举报