Commit 741e2367 authored by Fcant's avatar Fcant

[Code-Updates]:添加修改删除更新后返回UserInfo信息

parent 12b3c48f
Pipeline #4023 failed with stages
......@@ -55,8 +55,9 @@ public class UserController {
* @date 18:40 2019/12/3
*/
@PostMapping("/add")
int addUser(@RequestBody UserInfo userInfo) {
return userService.addUser(userInfo);
UserInfo addUser(@RequestBody UserInfo userInfo) {
userService.addUser(userInfo);
return userInfo;
}
/**
......@@ -68,7 +69,7 @@ public class UserController {
* @date 18:41 2019/12/3
*/
@PutMapping("/update")
int updateUser(@RequestBody UserInfo userInfo) {
UserInfo updateUser(@RequestBody UserInfo userInfo) {
return userService.updateUser(userInfo);
}
......@@ -81,7 +82,7 @@ public class UserController {
* @date 18:41 2019/12/3
*/
@DeleteMapping("/del")
int delUser(@RequestBody UserInfo userInfo) {
UserInfo delUser(@RequestBody UserInfo userInfo) {
return userService.delUser(userInfo);
}
}
package org.hand.train.springboot.springboot.mapper;
import org.hand.train.springboot.springboot.bean.UserInfo;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
......@@ -41,6 +42,7 @@ public interface UserMapper {
* @author Fcant
* @date 18:40 2019/12/3
*/
@Transactional(rollbackFor = Exception.class)
int addUser(UserInfo userInfo);
/**
......@@ -51,6 +53,7 @@ public interface UserMapper {
* @author Fcant
* @date 18:41 2019/12/3
*/
@Transactional(rollbackFor = Exception.class)
int updateUser(UserInfo userInfo);
/**
......@@ -61,5 +64,6 @@ public interface UserMapper {
* @author Fcant
* @date 18:41 2019/12/3
*/
@Transactional(rollbackFor = Exception.class)
int delUser(UserInfo userInfo);
}
......@@ -41,7 +41,7 @@ public interface UserService {
* @author Fcant
* @date 18:40 2019/12/3
*/
int addUser(UserInfo userInfo);
UserInfo addUser(UserInfo userInfo);
/**
* 更新用户信息
......@@ -51,7 +51,7 @@ public interface UserService {
* @author Fcant
* @date 18:41 2019/12/3
*/
int updateUser(UserInfo userInfo);
UserInfo updateUser(UserInfo userInfo);
/**
* 删除用户
......@@ -61,5 +61,5 @@ public interface UserService {
* @author Fcant
* @date 18:41 2019/12/3
*/
int delUser(UserInfo userInfo);
UserInfo delUser(UserInfo userInfo);
}
......@@ -19,6 +19,11 @@ import java.util.List;
@Service
public class UserServiceImpl implements UserService {
/**
* 数据库操作失败的数字返回值
*/
private final int FAILURE_CODE = 0;
@Autowired
UserMapper userMapper;
......@@ -56,8 +61,12 @@ public class UserServiceImpl implements UserService {
* @date 18:40 2019/12/3
*/
@Override
public int addUser(UserInfo userInfo) {
return userMapper.addUser(userInfo);
public UserInfo addUser(UserInfo userInfo) {
int i = userMapper.addUser(userInfo);
if (i == FAILURE_CODE) {
return null;
}
return userInfo;
}
/**
......@@ -69,8 +78,12 @@ public class UserServiceImpl implements UserService {
* @date 18:41 2019/12/3
*/
@Override
public int updateUser(UserInfo userInfo) {
return userMapper.updateUser(userInfo);
public UserInfo updateUser(UserInfo userInfo) {
int i = userMapper.updateUser(userInfo);
if (i == FAILURE_CODE) {
return null;
}
return userInfo;
}
/**
......@@ -82,7 +95,12 @@ public class UserServiceImpl implements UserService {
* @date 18:41 2019/12/3
*/
@Override
public int delUser(UserInfo userInfo) {
return userMapper.delUser(userInfo);
public UserInfo delUser(UserInfo userInfo) {
int i = userMapper.delUser(userInfo);
if (i == FAILURE_CODE) {
return null;
}
userInfo = userMapper.selectUserById(userInfo.getUserId());
return userInfo;
}
}
......@@ -33,7 +33,10 @@
user_id =#{id}
</select>
<insert id="addUser" keyProperty="userId" useGeneratedKeys="true" parameterType="org.hand.train.springboot.springboot.bean.UserInfo">
<insert id="addUser"
keyProperty="userId"
useGeneratedKeys="true"
parameterType="org.hand.train.springboot.springboot.bean.UserInfo">
INSERT INTO user_info(user_id, user_name, age, create_time)
VALUES (#{userId}, #{userName}, #{age}, #{createTime})
</insert>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment