Mybatis常用代码

来自ling
跳转至: 导航搜索
 queryWrapper.and(wrapper -> wrapper.and(wrapper1 -> wrapper1.eq(DwSubjectDataInfoWw::getYear, year1).ge(DwSubjectDataInfoWw::getWeek, week1))
                    .or(wrapper2 -> wrapper2.eq(DwSubjectDataInfoWw::getYear, year2).le(DwSubjectDataInfoWw::getWeek, week2)));
 //搜索条件可以是专题中文名或英文名
        if (StrUtil.isNotEmpty(keyWord)) {
            queryWrapper.and(wrapper -> wrapper.like(DwSubjectDataInfoWw::getSubjectCname, keyWord).or().like(DwSubjectDataInfoWw::getSubjectEname, keyWord));
        }

WHERE
    (
        (
            (year = ? AND week >= ?)
            OR (year = ? AND week <= ?)
        )
        AND city_name = ?
        AND user_net_type = ?
        AND module_name = ?
        AND (
            subject_cname LIKE ?
            OR subject_ename LIKE ?
        )
    )
ORDER BY
    year DESC,
    week DESC
#mybatis-plus配置控制台打印完整带参数SQL语句
    mybatis-plus:
      configuration:
        log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
        QueryWrapper<User> wrapper = Condition.getQueryWrapper(new User());
//        Calendar calendar = Calendar.getInstance();
//        calendar.add(Calendar.DAY_OF_MONTH, -1);
//        Wrappers.<User>query().lambda()
        wrapper.lambda().in(User::getId, ids);
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.powerlong.plan.base.mapper.PlasUserMapper">

    <!--    &lt;!&ndash; 通用查询映射结果 &ndash;&gt;-->
    <!--    <resultMap id="userResultMap" type="org.springblade.system.user.entity.User">-->
    <!--        <result column="id" property="id"/>-->
    <!--        <result column="tenant_id" property="tenantId"/>-->
    <!--        <result column="create_user" property="createUser"/>-->
    <!--        <result column="create_time" property="createTime"/>-->
    <!--        <result column="update_user" property="updateUser"/>-->
    <!--        <result column="update_time" property="updateTime"/>-->
    <!--        <result column="status" property="status"/>-->
    <!--        <result column="is_deleted" property="isDeleted"/>-->
    <!--        <result column="code" property="code"/>-->
    <!--        <result column="user_type" property="userType"/>-->
    <!--        <result column="account" property="account"/>-->
    <!--        <result column="password" property="password"/>-->
    <!--        <result column="name" property="name"/>-->
    <!--        <result column="real_name" property="realName"/>-->
    <!--        <result column="email" property="email"/>-->
    <!--        <result column="phone" property="phone"/>-->
    <!--        <result column="birthday" property="birthday"/>-->
    <!--        <result column="sex" property="sex"/>-->
    <!--        <result column="role_id" property="roleId"/>-->
    <!--        <result column="dept_id" property="deptId"/>-->
    <!--        <result column="post_id" property="postId"/>-->
    <!--    </resultMap>-->

    <!--    <select id="selectUserPage" resultMap="userResultMap">-->
    <!--        select * from blade_user where is_deleted = 0-->
    <!--        <if test="tenantId!=null and tenantId != ''">-->
    <!--            and tenant_id = #{tenantId}-->
    <!--        </if>-->
    <!--        <if test="user.tenantId!=null and user.tenantId != ''">-->
    <!--            and tenant_id = #{user.tenantId}-->
    <!--        </if>-->
    <!--        <if test="user.account!=null and user.account != ''">-->
    <!--            and account = #{user.account}-->
    <!--        </if>-->
    <!--        <if test="user.realName!=null and user.realName != ''">-->
    <!--            and real_name = #{user.realName}-->
    <!--        </if>-->
    <!--        <if test="user.userType!=null and user.userType != ''">-->
    <!--            and user_type = #{user.userType}-->
    <!--        </if>-->
    <!--        <if test="deptIdList!=null and deptIdList.size>0">-->
    <!--            and id in (-->
    <!--            SELECT-->
    <!--            user_id-->
    <!--            FROM-->
    <!--            blade_user_dept-->
    <!--            WHERE-->
    <!--            dept_id IN-->
    <!--            <foreach collection="deptIdList" index="index" item="item" open="(" separator="," close=")">-->
    <!--                #{item}-->
    <!--            </foreach>-->
    <!--            )-->
    <!--        </if>-->
    <!--        ORDER BY id-->
    <!--    </select>-->

    <!--    <select id="getUser" resultMap="userResultMap">-->
    <!--        SELECT-->
    <!--            *-->
    <!--        FROM-->
    <!--            blade_user-->
    <!--        WHERE-->
    <!--            tenant_id = #{param1} and account = #{param2} and is_deleted = 0-->
    <!--    </select>-->

    <select id="getAllUser" resultType="com.powerlong.plan.base.entity.PlasUser">
        SELECT
        <include refid="userSql"/>
        FROM plas.PLAS_USER t where t.service_status_cd in('1')
    </select>
    <select id="getUsersByDate" resultType="com.powerlong.plan.base.entity.PlasUser">
        SELECT
        <include refid="userSql"/>
        FROM plas.PLAS_USER t where t.CREATED_DATE <![CDATA[>=]]> #{param1} or t.UPDATED_DATE <![CDATA[>=]]> #{param1}
    </select>
    <sql id="userSql">
         PLAS_USER_ID, UIID, USER_BIZ_CD, USER_NAME, SERVICE_STATUS_CD, SEX_CD,email,mobile_phone
    </sql>

</mapper>

blog2string

    public String queryApproveContentByDisplayNo(String sourceNumber) {
        return (String) getSqlMapClient().queryForObject(getNamespace() + ".queryApproveContentByDisplayNo", sourceNumber);
    }

    <select id="queryApproveContentByDisplayNo" parameterClass="String" resultClass="String">
        select c.APPROVE_CONTENT from res_approve_info i LEFT JOIN res_approve_content	c
        on i.res_approve_info_id=c.res_approve_info_id
        where i.DISPLAY_NO=#value#
    </select>