目录


创建对应的页面

项目名:nacos-nuxt-student-service-classes
pom文件
yml文件(端口号、服务名、数据库)

启动类
拷贝配置类
基本结构

1)后端

package com.czxy.classes.controller;
import com.czxy.classes.service.TbClassesService;
import com.czxy.classes.service.TbTeacherService;
import com.czxy.domain.TbTeacher;
import com.czxy.vo.BaseResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
* @author 桐叔
* @email liangtong@itcast.cn
* @description
*/
@RestController
@RequestMapping("/teacher")
public class TbTeacherController {
@Resource
private TbTeacherService tbTeacherService;
/**
* 查询所有
* @author 桐叔
* @email liangtong@itcast.cn
* @return
*/
@GetMapping
public BaseResult findAll() {
List list = tbTeacherService.list();
return BaseResult.ok("查询成功", list);
}
}
2)前端
显示表单
展示所有老师
显示表单
添加 重置
展示所有老师

{{classes}} 添加 重置
需求:如果某类型的老师已选,将除当前老师,其他该类型的老师禁用
实现:完善ClassesAdd.vue

{{ teacher.tname }} {{teacher.type==1? '授课老师': teacher.type==2 ? '助理老师' : '辅导员老师'}} {{classes.teacher1.tname}} {{classes.teacher2.tname}} {{classes.teacher3.tname}} 添加 重置

package com.czxy.classes.controller;
import com.czxy.classes.service.TbClassesService;
import com.czxy.domain.TbClass;
import com.czxy.vo.BaseResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* @author 桐叔
* @email liangtong@itcast.cn
* @description
*/
@RestController
@RequestMapping("/classes")
public class TbClassesController {
@Resource
private TbClassesService tbClassesService;
@PostMapping
public BaseResult add(@RequestBody TbClass tbClass) {
boolean result = tbClassesService.save(tbClass);
if(result) {
return BaseResult.ok("添加成功");
}
return BaseResult.error("添加失败");
}
}

async classesAdd() {
// ajax添加
let { data:baseResult } = await this.$axios.post('/classes-service/classes', this.classes)
// 处理
if(baseResult.code == 20000) {
this.$message.success(baseResult.message)
// 跳转列表页
this.$router.push('/classes/classesList')
} else {
this.$message.error(baseResult.message)
}
}