mybatis 分页plugs

java | 2020-11-02 17:10:43 | 阅读 387 次 | 评论(0)


@Data
public class User{
 private String name;
 private String sax;
 private Integer state;
}


一、包米豆

官网地址:https://baomidou.com/

1.1 代码自动生成工具

待补充……


1.2 分页

1.2.1 dao

@Mapper
public interface UserRepository  extends BaseMapper<User> {

IPage<User> selectUserPage(Page page, @Param("iuser") User user);
}
1.2.2 mapper
<select id="selectUserPage" resultType="com.cn.enty.User">
select name,sax from user where state = #{iuser.state}
</select>

1.2.3 service


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;

public interface UserService extends IService<User> {

JSONObject listUser(JSONObject params);

}


1.2.4 impl

public class UserServerImp extends ServiceImpl<UserRepository, User> implement UserServer{ @Autowired
    private UserRepository userMapper;
   public JSONObject listUser(com.alibaba.fastjson.JSONObject params) {
        //返回值
        com.alibaba.fastjson.JSONObject outcome = new com.alibaba.fastjson.JSONObject();
        //转换实体
        User item = JSON.toJavaObject(params, User.class);
        
        //处理信息并设置返回分页信息
        IPage<User> userPage = this.UserMapper.selectUserPage(
                new Page(params.getLongValue(FIELD_CURRENT),
                        params.getLongValue(FIELD_SIZE)), item);
        
        outcome.put("user", userPage);
        return outcome;
  }

}

二、org.mybatis.generator

待补充……

文章评论,共0条
游客请输入验证码
最新评论