新增功能
Entity
TypeScript package com.example.entity;
import lombok.Data;
@Data public class College { private Integer id; private String name; private String content; private Integer score; }
|
前端
Manager.vue
修改Manager.vue,添加College导航,并将用户管理的index修改为3

XML <el-sub-menu index="2"> <template #title> <el-icon><Promotion /></el-icon> <span>信息管理</span> </template> <el-menu-item index="/college"> <el-icon><OfficeBuilding /></el-icon> <span>学院信息</span> </el-menu-item> </el-sub-menu>
|
路由
添加college路由

TypeScript { path: 'college', component: () => import('@/views/manager/College.vue')},
|
College.vue
将资料College.vue添加到views/manager中
[College.vue]
后端
CollegeController
Java package com.example.controller;
/** * 学院信息前端请求的接口入口 */ @RestController @RequestMapping("/college") public class CollegeController { @Resource private CollegeService collegeService;
/** * 新增 */ @PostMapping("/add") public Result add(@RequestBody College college) { collegeService.add(college); return Result.success(); } }
|
CollegeService
TypeScript package com.example.service;
import com.example.entity.College;
public interface CollegeService { void add(College college); }
|
CollegeServiceImpl
Java package com.example.service.impl;
import com.example.entity.College; import com.example.mapper.CollegeMapper; import com.example.service.CollegeService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;
@Service public class CollegeServiceImpl implements CollegeService { @Autowired private CollegeMapper collegeMapper; @Override public void add(College college) { collegeMapper.insert(college); } }
|
CollegeMapper
TypeScript package com.example.mapper;
import com.example.entity.College;
public interface CollegeMapper { void insert(College college); }
|
CollegeMapper.xml
XML <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.example.mapper.CollegeMapper">
<insert id="insert" parameterType="com.example.entity.College" useGeneratedKeys="true"> insert into college (id, name, content, score) values (#{id}, #{name}, #{content}, #{score}) </insert> </mapper>
|
分页查询和条件查询
CollegeController
TypeScript /** * 分页查询 */ @GetMapping("/selectPage") public Result selectPage(String name, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize){ PageInfo<College> pageInfo = collegeService.selectPage(name, pageNum, pageSize); return Result.success(pageInfo); }
|
CollegeServiceImpl
TypeScript @Override public PageInfo<College> selectPage(String name, Integer pageNum, Integer pageSize) { List<College> list = new ArrayList<>(); PageHelper.startPage(pageNum, pageSize); if (ObjectUtil.isNotEmpty(name)) { list = collegeMapper.selectByName(name); } else { list = collegeMapper.selectAll(); } return PageInfo.of(list); }
|
CollegeMapper
Java @Select("select * from college") List<College> selectAll();
@Select("select * from college where name like concat('%', #{name}, '%')") List<College> selectByName(String name);
|
查询所有功能
完善新增或编辑学生时的院校信息显示

CollegeController
TypeScript /** * 查询所有 */ @GetMapping("/selectAll") public Result selectAll() { List<College> list = collegeService.selectAll(); return Result.success(list); }
|
CollegeServiceImpl
TypeScript @Override public List<College> selectAll() { return collegeMapper.selectAll(); }
|
更新功能
CollegeController
SQL /** * 更新 */ @PutMapping("/update") public Result update(@RequestBody College college) { collegeService.updateById(college); return Result.success(); }
|
CollegeServiceImpl
TypeScript @Override public void updateById(College college) { collegeMapper.updateById(college); }
|
CollegeMapper
TypeScript @Update("update college set name = #{name}, content = #{content}, score = #{score}" + " where id = #{id} ") void updateById(College college);
|
删除功能
CollegeController
SQL /** * 根据id删除 */ @DeleteMapping("/deleteById/{id}") public Result deleteById(@PathVariable Integer id) { collegeService.deleteById(id); return Result.success(); }
|
CollegeServiceImpl
TypeScript public void deleteById(Integer id) { collegeMapper.deleteById(id); }
|
CollegeMapper
TypeScript @Delete("delete from college where id = #{id}") void deleteById(Integer id);
|
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
评论(0)