第一课主要是用户端后台接口开发主要功能有用户基本信息(姓名、性别、年龄、手机)的操作、用户日常生理指标(心率、血压、血糖、血脂、体重)的操作。
UserController.java
// 标记controller
@RestController
@RequestMapping("api/v1/user")
public class UserController {
// 自动注入service
@Autowired
private UserService userService;
/**
* 创建用户
* @param user
* @return
*/
@PostMapping("add")
public ResultObject insertUser(@RequestBody User user) {
int modifyId = userService.insertUser(user);
Map<String, Integer> map = new HashMap<>();
map.put("modifyId", modifyId);
ResultObject resultObject = new ResultObject(200, "", map);
return resultObject;
}
/**
* 查询用户
* @param id
* @return
*/
@GetMapping("get")
public ResultObject getUserById(@RequestParam int id) {
User user = userService.getUserById(id);
ResultObject resultObject = new ResultObject(0, "", user);
return resultObject;
}
/**
* 分页查询用户
* @param pageNum, pageSize
* @return
*/
@GetMapping("list")
public ResultObject getAllUser(@RequestParam int pageNum, @RequestParam int pageSize) {
PaginationObject paginationObj = userService.getAllUser(pageNum, pageSize);
ResultObject resultObject = new ResultObject(0, "", paginationObj);
return resultObject;
}
/**
* 删除用户
* @param id
* @return
*/
@DeleteMapping("delete")
public ResultObject deleteUser(@RequestParam int id) {
int modifyId = userService.deleteUser(id);
Map<String, Integer> map = new HashMap<>();
map.put("modifyId", modifyId);
ResultObject resultObject = new ResultObject(200, "", map);
return resultObject;
}
/**
* 更新用户
* @param user
* @return
*/
@PutMapping("edit")
public ResultObject updateUser(@RequestBody User user) {
int modifyId = userService.updateUser(user);
Map<String, Integer> map = new HashMap<>();
map.put("modifyId", modifyId);
ResultObject resultObject = new ResultObject(200, "", map);
return resultObject;
}
}
UserIndexController.java
// 标记controller
@RestController
@RequestMapping("api/v1/userIndex")
public class UserIndexController {
// 自动注入service
@Autowired
private UserIndexService userIndexService;
/**
* 创建用户生理指标数据
* @param userIndex
* @return
*/
@PostMapping("add")
public ResultObject insertUserIndex(@RequestBody UserIndex userIndex) {
int modifyId = userIndexService.insertUserIndex(userIndex);
Map<String, Integer> map = new HashMap<>();
map.put("modifyId", modifyId);
ResultObject resultObject = new ResultObject(200, "", map);
return resultObject;
}
/**
* 通过userID、类型查询用户生理指标数据
* @param userIndex
* @return
*/
@GetMapping("get")
public ResultObject getUserIndexById(@RequestBody UserIndex userIndex) {
List<UserIndex> userIndexIndexs = userIndexService.getUserIndexById(userIndex);
ResultObject resultObject = new ResultObject(200, "", userIndexIndexs);
return resultObject;
}
/**
* 删除用户生理指标数据
* @param id
* @return
*/
@DeleteMapping("delete")
public ResultObject deleteUserIndex(@RequestParam int id) {
int modifyId = userIndexService.deleteUserIndex(id);
Map<String, Integer> map = new HashMap<>();
map.put("modifyId", modifyId);
ResultObject resultObject = new ResultObject(200, "", map);
return resultObject;
}
/**
* 修改用户生理指标数据
* @param userIndex
* @return
*/
@PutMapping("edit")
public ResultObject updateUserIndex(@RequestBody UserIndex userIndex) {
int modifyId = userIndexService.updateUserIndex(userIndex);
Map<String, Integer> map = new HashMap<>();
map.put("modifyId", modifyId);
ResultObject resultObject = new ResultObject(200, "", map);
return resultObject;
}
}
UserMapper.java
@Mapper
@Component(value = "userMapper")
public interface UserMapper {
/**
* 通过id获取用户
* @param id
* @return
*/
@Select("select id, name, gender, age, phone, phone, job, address,createTime " +
"from user where id = #{id};")
public User getById(int id);
/**
* 获取所有用户
* @return
*/
@Select("select id, name, gender, age, phone, phone, job, address,createTime from user")
public List<User> getAll();
/**
* 创建用户
* @param user
* @return
*/
@Insert("insert into user(name, gender, age, phone, job, address, createTime) " +
"values(#{name}, #{gender}, #{age}, #{phone}, #{job}, #{address}, #{createTime})")
public int insert(User user);
/**
* 通过id更新用户
* @param user
* @return
*/
public int update(User user);
/**
* 删除用户
* @param id
* @return
*/
@Delete("delete from user where id = #{id}")
public int delete(int id);
}
UserIndexMapper.java
@Mapper
@Component(value = "userIndexMapper")
public interface UserIndexMapper {
/**
* 通过用户id和指标类型获取用户的所有指标
* @param userIndex
* @return
*/
@Select("SELECT id,indexContent as indexContent,collectDate as collectDate " +
"from user_index where userId = #{userId} and indexType = #{indexType}")
public List<UserIndex> getById(UserIndex userIndex);
/**
* 创建用户生理指标数据
* @param userIndex
* @return
*/
@Insert("insert into user_index(userId, indexType, indexContent, collectDate) " +
"values(#{userId}, #{indexType}, #{indexContent}, #{collectDate})")
public int insert(UserIndex userIndex);
/**
* 更新用户生理指标数据
* @param userIndex
* @return
*/
public int update(UserIndex userIndex);
/**
* 删除用户生理指标数据
* @param userIndexId
* @return
*/
@Delete("delete from user_index where id = #{id}")
public int delete(int userIndexId);
}
文集推荐:
Java基础方法集1
Python基础知识完整版
Spring Boot学习笔记
Linux指令进阶
Java高并发编程
SpringMVC基础知识进阶
Mysql基础知识完整版
健康管理系统学习花絮(学习记录)
Node.js基础知识(随手笔记)
MongoDB基础知识
Dubbo学习笔记
Vue学习笔记(随手笔记)
声明:发表此文是出于传递更多信息之目的。若有来源标注错误或侵犯了您的合法权益,请作者持权属证明与本我们(QQ:981086665;邮箱:981086665@qq.com)联系联系,我们将及时更正、删除,谢谢。
网友评论