1分钟左右完成一个Bean管理的后端部分
基于Springboot MybatisPlus Maven框架
在安全性低、功能简单的小型项目上使用非常快
package com.humor.courseselection.controller;
import com.humor.courseselection.bean.Teacher;
import com.humor.courseselection.service.ITeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author humor
* @since 2020-03-23
*/
@RestController
@RequestMapping("/courseselection/teacher")
public class TeacherController {
@Autowired
private ITeacherService iTeacherService;
@RequestMapping("/add")
public String add(Teacher teacher)
{
try {
if (teacher.getId()==null)
{
if (iTeacherService.insert(teacher))
return "添加成功";
}
else
{
if (iTeacherService.updateById(teacher))
return "修改成功";
}
}catch (Exception e)
{
e.printStackTrace();
}
return "数据有误,提交失败";
}
@RequestMapping("/del")
public String del(int id)
{
try {
if (iTeacherService.deleteById(id))
return "删除成功";
}catch (Exception e)
{
e.printStackTrace();
}
return "删除失败,刷新后重试";
}
@RequestMapping("/getById")
public Teacher getById(int id )
{
return iTeacherService.selectById(id);
}
@RequestMapping("/getAll")
public List<Teacher> getAll()
{
return iTeacherService.selectList(null);
}
}
只需要拿着复制进去,对
iTeacherService
iTeacherService
Teacher
teacher
等几个关键字符串进行替换成新的就行,即可在1分钟左右完成一个Bean管理的后端部分