Sql语句、多个字段模糊查询、

Sql语句收获
1、
select * from 表 order by time asc
最早时间在前
select * from 表 order by time desc
最新时间在前

2、模糊查询

select id, sys_user.user_name as userName,sys_user.nick_name as nickName,score_theme.theme_name as themeName,score_theme.create_time as createTime
from sys_user
inner join score_theme
on sys_user.user_id = score_theme.fk_publish_user
and deleted = 1

    **<if test="searchValue !=null and searchValue != ''">
        and sys_user.user_name like concat('%',#{searchValue},'%')
           ( or sys_user.nick_name like concat('%',#{searchValue},'%') )
              (  or score_theme.theme_name like concat('%',#{searchValue},'%') )
    </if>**
    order by score_theme.create_time desc
</select>

多个字段模糊查询 concat(’%’,#{searchValue},’%’)
3、mybaties的聚连

<resultMap type="com.gwm.score.domain.vo.ScoreTargetVO" id="ScoreTargetVOResult">
    <result property="id" column="id" />
    <result property="targetName"    column="targetName" />
    <collection property="scoreDimensionVOList"
                select="selectScoreDimensionVoList"
                column="{targetId=targetId,fkVoter=fkVoter}"
                ofType="com.gwm.score.domain.vo.ScoreDimensionVO">
    </collection>
</resultMap>

<select id="getScoreTargetVo" resultMap="ScoreTargetVOResult">
    select target_name as targetName,end_time as endTime,#{fkVoter} as fkVoter,#{targetId} as targetId
    from score_target,score_theme
    where score_target.id=#{targetId}
        and score_target.fk_theme_id=score_theme.id
</select>
<select id="selectScoreDimensionVoList" resultType="com.gwm.score.domain.vo.ScoreDimensionVO">
    select  score_dimension.id,dimension_name as dimensionName,
           (select score from score_record
               where score_record.fk_target_id=#{targetId}
               and state=1
               and fk_dimension_id=score_dimension.id
               and score_record.fk_voter=#{fkVoter}) as score
    from score_dimension
    where fk_theme_id=(select fk_theme_id from score_target where id=#{targetId}) and state =1
</select>

colum对应的不是数据库里的字段 而是你查出来的字段得名字
在这里插入图片描述
注意
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43889487/article/details/120748553