前端发送请求后,会请求deptcontroller的方法list()。
package com.intelligent_learning_aid_system.controller;
import com.intelligent_learning_aid_system.pojo.dept;
import com.intelligent_learning_aid_system.pojo.result;
import com.intelligent_learning_aid_system.service.deptservice;
import lombok.extern.slf4j.slf4j;
import org.slf4j.logger;
import org.slf4j.loggerfactory;
import org.springframework.beans.factory.annotation.autowired;
import org.springframework.web.bind.annotation.*;
import java.util.list;
/**
* 部门管理controller
*/
@slf4j
@restcontroller
public class deptcontroller {
@autowired
private deptservice deptservice;
// @requestmapping(value = "/depts", method = requestmethod.get) // 指定请求参数为 get
@getmapping("/depts") // 等同于上面的写法
public result list() {
// system.out.println("查询全部部门数据");
log.info("查询全部部门数据");
// 调用service查询部门数据
list<dept> deptlist = deptservice.list();
return result.success(deptlist);
}
}在list()中调用deptservice获取数据。
在deptservice中调用deptmapper接口中的方法来查询全部的部门信息。
package com.intelligent_learning_aid_system.service;
import com.intelligent_learning_aid_system.pojo.dept;
import java.util.list;
/**
* 部门管理
*/
public interface deptservice {
/**
* 查询全部部门
* @return
*/
list<dept> list();
}package com.intelligent_learning_aid_system.service.impl;
import com.intelligent_learning_aid_system.mapper.deptmapper;
import com.intelligent_learning_aid_system.pojo.dept;
import com.intelligent_learning_aid_system.service.deptservice;
import lombok.extern.slf4j.slf4j;
import org.apache.ibatis.annotations.select;
import org.springframework.beans.factory.annotation.autowired;
import org.springframework.stereotype.service;
import java.util.list;
@slf4j
@service
public class deptserviceimpl implements deptservice {
@autowired
private deptmapper deptmapper;
/**
* 查询全部部门
*/
public list<dept> list() {
return deptmapper.list();
}
}deptmapper接口会往数据库发送sql语句,查询全部的部门,并且把查询的信息封装到list<dept>集合中。
package com.intelligent_learning_aid_system.mapper;
import com.intelligent_learning_aid_system.pojo.dept;
import org.apache.ibatis.annotations.delete;
import org.apache.ibatis.annotations.insert;
import org.apache.ibatis.annotations.mapper;
import org.apache.ibatis.annotations.select;
import org.springframework.web.bind.annotation.getmapping;
import java.util.list;
/**
* 部门管理
*/
@mapper
public interface deptmapper {
/**
* 查询全部部门
* @return
*/
@select("select * from dept")
list<dept> list();
}最终将集合数据返回给deptservice,deptservice又返回给deptcontroller。deptcontroller拿到数据再返回给前端。

到此这篇关于springboot查询全部部门流程的文章就介绍到这了,更多相关springboot查询全部部门内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论