SpringBoot+Mybatis完成商品秒杀项目之用户模块开发(三)

本文档介绍了在SpringBoot+Mybatis项目中开发用户模块时,如何使用SpringMVC处理用户信息,包括创建controller、dao、service层以及UserModel。同时,针对直接暴露用户密码的安全问题,提出了在controller层创建viewobject模型对象进行信息筛选的解决方案。此外,文章还详细阐述了定义通用返回对象的过程,包括返回正确信息、错误信息的处理,以及全局异常处理的实现,确保提供有意义的错误信息。
摘要由CSDN通过智能技术生成

1.使用SpringMVC方式开发用户信息

1.增加controller层、dao层、service层
在service层增加UserModel

public class UserModel {
    private Integer id;
    private String name;
    private Byte gender;
    private Integer age;
    private String telphone;
    private String regisitMode;
    private Integer thirdPartyId;
    private String encrptPassword;
}

UserModel需要增加 用户的密码,其通过userPasswordDOMapper从userPasswordDO得到。。。
2创建UserController

@Controller("user")
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/get")
    @ResponseBody
    public UserModel getUser(@RequestParam(name = "id") Integer id) {
        //调用service服务获取对应id的用户对象并返回给前端
        UserModel userModel = userService.getUserById(id);
        return userModel;
    }
}

3.修改userPasswordDOMapper.xml和.java文件
增加方法 selectByUserId

<select id="selectByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
  select
  <include refid="Base_Column_List" />
  from user_password
  where user_id = #{userId,jdbcType=INTEGER}
</select>
userPasswordDO selectByUserId(Integer UserId);

4.编写UserService

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDOMapper userDOMapper;

    @Autowired
    private userPasswordDOMapper userPasswordDOMapper;

    @
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值