登录成功返回用户名称

This commit is contained in:
wuweida 2022-06-23 17:27:51 +08:00
parent 17199c1573
commit 596b2b7f09
4 changed files with 20 additions and 6 deletions

View File

@ -1,5 +1,6 @@
package com.hisense.monitormanage.controller;
import com.hisense.monitormanage.dto.UserLoginDto;
import com.hisense.monitormanage.entity.Result;
import com.hisense.monitormanage.service.UserLoginService;
import org.springframework.beans.factory.annotation.Autowired;
@ -16,7 +17,7 @@ public class UserLoginController {
@PostMapping("login")
public Result login(String username,String password){
String login = userLoginService.login(username, password);
UserLoginDto login = userLoginService.login(username, password);
Result success = Result.success(login);
return success;
}

View File

@ -0,0 +1,9 @@
package com.hisense.monitormanage.dto;
import lombok.Data;
@Data
public class UserLoginDto {
private String username;
private String status;
}

View File

@ -2,10 +2,9 @@ package com.hisense.monitormanage.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hisense.monitormanage.entity.UserLogin;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
public interface UserLoginMapper extends BaseMapper<UserLogin> {
public interface UserLoginMapper extends BaseMapper<UserLoginMapper> {
@Select("select * from t_user_login")
UserLogin getUserByName();

View File

@ -1,6 +1,7 @@
package com.hisense.monitormanage.service;
import cn.hutool.crypto.SecureUtil;
import com.hisense.monitormanage.dto.UserLoginDto;
import com.hisense.monitormanage.entity.UserLogin;
import com.hisense.monitormanage.mapper.UserLoginMapper;
import lombok.extern.log4j.Log4j2;
@ -14,11 +15,15 @@ public class UserLoginService {
@Autowired
private UserLoginMapper userLoginMapper;
public String login(String username,String password){
public UserLoginDto login(String username, String password){
UserLogin user = userLoginMapper.getUserByName();
UserLoginDto userLoginDto = new UserLoginDto();
if (user.getUsername().equals(username) && user.getPassword().equals(SecureUtil.md5(password))){
return "登录成功";
userLoginDto.setUsername(username);
userLoginDto.setStatus("登录成功");
return userLoginDto;
}
return "账号或密码错误";
userLoginDto.setStatus("账号或密码错误");
return userLoginDto;
}
}