Mysql在mapper中的条件查询
1. 多条件查询
type 属性用于指定获取sql语句的指定类
method 属性用于指定类中要执行获取sql语句的方法
https://blog.****.net/qq_36872046/article/details/80291939
package com.msp.whg.mapper;
import com.msp.whg.domain.Attendances;
import com.msp.whg.util.AppMapper;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.annotations.SelectProvider;
import java.util.List;
public interface AttendancesMapper extends AppMapper<Attendances> {
@SelectProvider(type = AttendancesMapper.listAttendancess.class, method = "listAttendance")
public List<Attendances> listAttendances(Attendances attendances);
class listAttendancess {
public String listAttendance(Attendances attendances) {
String sql = "select at.SUH_ITEMCODE suhItemcode,at.SUH_NAME suhName,\n" +
"at.SUH_COURSES suhCourses,at.SUH_TIME suhTime,at.SUH_STATE suhState,\n" +
"at.SUH_TYPE suhType,at.SUH_MODE suhMode,at.SUH_CARDTIME suhCardtime \n" +
"from Attendances at where 1 = 1";
if(StringUtils.isNotBlank(attendances.getSuhItemcode())){
sql+=" and at.SUH_ITEMCODE ='"+attendances.getSuhItemcode()+"'";
}
if(StringUtils.isNotBlank(attendances.getSuhType())){
sql+=" and at.SUH_TYPE ='"+attendances.getSuhType()+"'";
}
if(StringUtils.isNotBlank(attendances.getSuhName())){
sql+=" and at.SUH_NAME LIKE '%"+attendances.getSuhName()+"%'";
}
if(StringUtils.isNotBlank(attendances.getSuhCourses())){
sql+=" and at.SUH_COURSES ='"+attendances.getSuhCourses()+"'";
}
if(StringUtils.isNotBlank(attendances.getSuhCardtime())){
sql+=" and at.SUH_CARDTIME LIKE '%"+attendances.getSuhCardtime()+"%'";
}
sql +=" ORDER BY SUH_CARDTIME DESC ";
return sql;
}
}
}
方法二:
@Param注解的用法解析:
https://blog.****.net/u012031380/article/details/54924641/
package com.msp.whg.mapper;
import com.msp.whg.domain.DeclareManage;
import com.msp.whg.util.AppMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.Map;
public interface DeclareMmanageMapper extends AppMapper<DeclareManage>{
@Select(" SELECT * FROM declare_manage WHERE declare_xtbh = #{icItemcode}")
public Map<String,Object> dataListOne(@Param("icItemcode") String icItemcode);
}