已知scores数据表:-- aokace.scores definition CREATE TABLE `scores` ( `scoresid` int NOT NULL AUTO_INCREMENT, `scorestime` date DEFAULT NULL, `departname` varchar(100) NOT NULL, `positname` varchar(100) NOT NULL, `gradesname` varchar(100) NOT NULL, `emploname` varchar(100) NOT NULL, `scoresa` float NOT NULL, `scoresb` float NOT NULL, `scoresc` float NOT NULL, `scoresd` float NOT NULL, `overviw` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, `manager` float NOT NULL, `admins` float DEFAULT NULL, `average` float DEFAULT NULL, PRIMARY KEY (`scoresid`), KEY `scores_FK` (`departname`), KEY `scores_FK_1` (`positname`), KEY `scores_FK_2` (`gradesname`), KEY `scores_FK_3` (`emploname`), CONSTRAINT `scores_FK` FOREIGN KEY (`departname`) REFERENCES `department` (`departname`), CONSTRAINT `scores_FK_1` FOREIGN KEY (`positname`) REFERENCES `position` (`positname`), CONSTRAINT `scores_FK_2` FOREIGN KEY (`gradesname`) REFERENCES `grades` (`gradesname`), CONSTRAINT `scores_FK_3` FOREIGN KEY (`emploname`) REFERENCES `employe` (`emploname`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; 如何在ScoresController( package com.aokace.controller; import com.aokace.service.ScoresService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * <p> * 前端控制器 * </p> * * @author aokace * @since 2023-06-12 */ @RestController @RequestMapping("/scores") public class ScoresController { @Autowired private ScoresService scoresService; } )中实现在scores表的数据中修改admin数据 保存但不改变 数据的id
时间: 2023-07-22 13:43:12 浏览: 142
实训报告--学生成绩管理系统单表查询.docx
您可以在ScoresController中添加一个@RequestMapping映射,来处理修改admin数据的请求。然后在该方法中,可以调用ScoresService中的方法来获取要修改的数据,并更新其中的admin字段。最后,调用ScoresService中的另一个方法来保存修改后的数据,但不改变数据的id。
具体实现如下:
```java
@RestController
@RequestMapping("/scores")
public class ScoresController {
@Autowired
private ScoresService scoresService;
@RequestMapping("/updateAdmin")
public void updateAdmin(@RequestParam("id") int id, @RequestParam("admin") float admin) {
// 调用ScoresService中的方法获取要修改的数据
Scores scores = scoresService.getById(id);
// 更新admin字段
scores.setAdmins(admin);
// 调用ScoresService中的方法保存修改后的数据,不改变数据的id
scoresService.updateWithoutChangingId(scores);
}
}
```
需要注意的是,这里使用了@RequestParam注解来获取请求参数,其中id是要修改的数据的id,admin是要更新的admin字段的值。ScoresService中的方法需要自行实现。
阅读全文