@desc : */ @Service public class MapperService { @Autowired BaseMapper baseMapper;
public List findAll(){ return baseMapper.findAll(); } public Label findById(String id){ return baseMapper.findById(id); } public List findByKeyword(String label){ return baseMapper.findByKeyword(label); } public List findByKeywords(Label label){ return baseMapper.findByKeysords(label.getLabelname(),label.getFans()); } public void add(Label label){ baseMapper.addLabel(label); } public void upadte(Label label){ baseMapper.updateLabel(label); } public void deleteById(String id){ baseMapper.deleteById(id); } }
@desc : / //该注解说明该类就行相当于一个xxxMapper.xml文件 @Mapper public interface BaseMapper { @Select(“SELECT * FROM tb_label”) List findAll(); @Select(“SELECT * FROM tb_label WHERE id = #{id}”) Label findById(String id); /*
模糊查询 -
因为#{} 取值出会自带引号,${}取值就是去除原值,当参数是基本数据类型,其中必须是value
@param labelname
@return / @Select(“SELECT * FROM tb_label WHERE labelname LIKE ‘%${value}%’”) List findByKeyword(String labelname); /*
Mapper接口方法中多个参数,想要注入到SQL语句中,需要使用注解@Param
@param labelname
@param fans
@return / @Select(“SELECT * FROM tb_label WHERE labelname LIKE ‘%
l
a
b
e
l
n
a
m
e
{labelname}%' AND `fans` LIKE '%
labelname{fans}%’”) List findByKeysords(@Param(“labelname”) String labelname,@Param(“fans”) String fans); /*