Controller ----Service ----Mapper

UserController(前段控制器的操作 你可以看看如何) —> userService(这个是中间插件类似的一个桥梁)—> UserMapper(实现类的接口 实现具体数据库的操作)

1 首先是Controller 里面 注释@RestController 然后里面注入Service @Autowire Service 进行接口类似的特征
然后 Service 添加@Service 注释 然后在里面注入 mapper 就是 userMapper 注入 加上@Autowire 注解
最后 mapper 里面实现具体的操作 就是实现具体的数据库里的操作 方法!
不要忘记在住的 方法里面添加 @MapperScan

具体如图所示:
在这里插入图片描述------->>>>

---------->>>>>>>>>
在这里插入图片描述
---------->>>>>>>>>>
在这里插入图片描述
------------->>>>>>>>>>>>>>>>>

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我来为您分别编写Mybatis-Plus查询所有分类的servicecontrollermapper代码。 1. Service层代码: ``` import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.example.demo.entity.Category; import com.example.demo.mapper.CategoryMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class CategoryService { @Autowired private CategoryMapper categoryMapper; public List<Category> getAllCategories() { QueryWrapper<Category> queryWrapper = new QueryWrapper<>(); List<Category> categoryList = categoryMapper.selectList(queryWrapper); return categoryList; } } ``` 2. Controller层代码: ``` import com.example.demo.entity.Category; import com.example.demo.service.CategoryService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController @RequestMapping("/category") public class CategoryController { @Autowired private CategoryService categoryService; @GetMapping("/list") public List<Category> getAllCategories() { return categoryService.getAllCategories(); } } ``` 3. Mapper层代码: ``` import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.example.demo.entity.Category; import org.apache.ibatis.annotations.Mapper; @Mapper public interface CategoryMapper extends BaseMapper<Category> { } ``` 在上述代码中,我们使用了Mybatis-Plus提供的BaseMapper接口,并传入了Category实体类作为泛型参数,来实现对Category表的基本增删改查操作。同时,我们在Mapper接口上使用了@Mapper注解,来声明这是一个Mapper接口。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值