基于通用mapper编写最基本的CURD接口

  • Post author:
  • Post category:其他




1 Controller层

这里有几个小点需要注意一下

①首先我们需要在类上贴上@RestController标签 , 证明是一个Controller类

②我们还要使用@MapperScan(basePackages = “com.imooc.mapper”) 这个标签 , 另外里边的路径是一个mapper包的路径 , 总之你将dao层的包扫描进来

③除了查询使用get请求 , 其余均使用post请求

package com.imooc.controller;

import com.imooc.pojo.Stu;

import com.imooc.service.StuService;
import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.spring.annotation.MapperScan;

@RestController
@MapperScan(basePackages = "com.imooc.mapper")
public class StuController {

    @Autowired
    private StuService stuService;

    @GetMapping("/findStu")
    public Stu findStu(Integer id){
        Stu stu = stuService



版权声明:本文为qq_45014905原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。