数据库表(还有一个brforeId)
建一个返回菜单数据的实体类user
package com.example.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.util.List;
@Data
@TableName("user")
public class User {
@TableField("user_id")
private Long userId;
@TableField("user_name")
private String userName;
@TableField("phone")
private String phone;
@TableField("user_password")
private String userPassword;
@TableField("parent_id")
private Long parentId;
@TableField("before_id")
private Long beforeId;
@TableField(exist = false)
private List<User> child;
}
注:这里省略了get,set方法,childMenu是用于装子类数据的;@TableField(exist = false)
表示该属性不为数据库表字段,但是必须使用
业务实现层代码:
package com.example.service;
import com.example.domain.User;
import java.util.List;
public interface UserService {
/**
* 获取多级菜单信息
* @param parentId
* @return
*/
List<User> find(Long parentId);
/**
*递归查询多级 这是常用的
* @retu