目录
1-Mapper:
1.1-**Mapper.java
1.2-**Mapper.xml
2- LambdaQueryWrapper+MyBatis-Plus
小记:
查询user_name==’rushi’, role_state==3的数据。
1-Mapper:
小记:
如果有分表的库表,使用Mapper实现增删改查较方便些。
1.1-**Mapper.java
List<UserBlogDTO>?getUserByNameState(@Param("userName")?String?userName,?@Param("roleState")?Integer?roleState);
1.2-**Mapper.xml
?????<select?id="getUserByNameState"?resultType="org.lcy.com.data.entity.BlogUsers">
?????????select?id,?user_name,?nick_name
?????????from?blog_users
?????????where?user_id=#{userId}?and?role_state=#{roleState}
?????</select>
2- LambdaQueryWrapper+MyBatis-Plus
public?List<BlogUsersDTO>?getUserByNameState(String?userName,?Integer?roleState)?{
????????LambdaQueryWrapper<BlogUsers>?queryWrapper?=?new?LambdaQueryWrapper<>();
????????queryWrapper.eq(BlogUsers::getUserName,?userName);
????????queryWrapper.eq(BlogUsers::getRoleState,?roleState);
????????queryWrapper.select(BlogUsers::getId,?BlogUsers::getUserName,BlogUsers::getNickName);
????????List<BlogUsers>?blogUsers?=?list(queryWrapper);
????????return?blogUsers.stream().map(BlogUsersConverter::convertToDTO).collect(Collectors.toList());
????}
-------------------- 作者:Username1898625 创作不易,转载已注明出处 --------------------
|