Mapper层
@Mapper
public interface HospitalSetMapper extends BaseMapper {
}
Service层接口
public interface HospitalSetService extends IService {
}
Service实现类
@Service
public class HospitalSetServiceImpl extends ServiceImpl implements HospitalSetService {
}
注意:原来service调用mappe需要把mapper注入到service,但是我们继承了ServiceImpl,里面已经帮助我们完成了注入,直接使用BaseMapper完成调用
Controller层
@RestController
@RequestMapping("/admin/hosp/hospitalSet")
public class HospitalSetController {
@Autowired
private HospitalSetService hospitalSetService;
}
在MyBatis-Plus不仅在Mapper中给我们封装了方法,在Service也进行了封装,在写代码是会非常的方便,直接通过controller去掉service中的方法,很方便的实现对数据库的操作
Mapper层
public interface AppUserMapper extends BaseMapper {
}
Service层接口
public interface BaseService extends IService {
}
实现类BaseServiceImpl
@Slf4j 继承了ServiceImpl,里面已经帮助我们完成了注入BaseMapper
public class BaseServiceImpl, T extends Object> extends ServiceImpl implements BaseService{
}
业务层公共接口
public interface IAppUserService extends BaseService {
}
业务层实现类AppUserServiceImpl
@Service
public class AppUserServiceImpl extends BaseServiceImpl
implements IAppUserService {
}
Controller层
@Slf4j
@Api(tags="App用户")
@RestController
@RequestMapping("/bus/user")
public class AppUserController extends BaseController {
@Autowired
private IAppUserService appUserService;
}
Controller接口
@AutoLog(value = "用户管理-分页列表查询")
@ApiOperation(value = "App用户-分页列表查询", notes = "App用户-分页列表查询")
@GetMapping(value = "/list")
public Result queryPageList(AppUserReq appUserReq, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
Page page = new Page<>(pageNo, pageSize);
IPage pageList = appUserService.queryPageList(page, appUserReq);
return Result.ok(pageList);
}
Service接口
public interface IAppUserService extends BaseService {
IPage queryPageList(IPage page, AppUserReq appUserReq);
}
实现类:
@Service
public class AppUserServiceImpl extends BaseServiceImpl implements IAppUserService {
@Override
public IPage queryPageList(IPage page, AppUserReq appUserReq) {
Map reqParam = new HashMap<>();
reqParam.put("companyName", appUserReq.getCompanyName());
reqParam.put("userMobile", appUserReq.getPhone());
IPage resultList = this.baseMapper.queryPage(page, reqParam);
return resultList;
}
Mapper接口
public interface AppUserMapper extends BaseMapper {
IPage queryPage(IPage page, @Param(value = "p") Map reqParam);
}
Mapper.xml:写sql
select
id,
user_name,
company_name,
phone user_mobile,
user_type,
company_review_type companyReviewType,
user_level,
company_name companyName,
locked,
signup_time signupTime
from app_user