Commit 8e97a67a authored by m1991's avatar m1991

简单登录功能

parent c9af998c
......@@ -43,4 +43,9 @@ public interface UsersMapper extends BaseMapper<User> {
List<User> getList(Map<String, Object> map);
List<User> findAll();
User findByName(String name);
String findPswByName(String UserName);
void save(User user);
}
......@@ -144,4 +144,25 @@
limit #{pageNo},#{pageSize}
</where>
</select>
<!--查询全部-->
<select id="findAll" resultType="User">
select * from User
</select>
<!--查询用户-->
<select id="findByName" resultType="User">
select * from User where user_id = #{userId}
</select>
<!--查询密码-->
<select id="findPswByName" resultType="String">
select password from user where user_id = #{userId}
</select>
<!--用户添加-->
<insert id="save">
insert into user(user_id,password) value (#{userId},#{password})
</insert>
</mapper>
package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.UsersMapper;
import cn.wisenergy.model.app.User;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @ Description: 用户接口实现
* @ Author : 86187
* @ Date : 2021/1/6 16:11
* @author 86187
*/
@Service
@Slf4j
public class UserService extends ServiceImpl<UsersMapper, User> {
@Autowired
private UsersMapper userMapper;
public String login(User user){//TODO:登陆逻辑函数
try {
User userExistN = userMapper.findByName(String.valueOf(user.getUserId()));
if (userExistN != null){
String userExistP = userMapper.findPswByName(String.valueOf(user.getUserId()));
if (userExistP.equals(user.getPassword())){
return user.getUserId()+" 用户登录成功,欢迎您!";
}else {
return "登陆失败,密码错误!";
}
}else {
return "登陆失败,账户不存在";
}
}catch (Exception e) {
e.printStackTrace();
return e.getMessage();
}
}
public String regist(User user){//TODO:注册判断逻辑函数
try{
User userExist = userMapper.findByName(String.valueOf(user.getUserId()));
if (user.getUserId().equals("")){
return "账户名不能为空";
}else if (user.getPassword().equals("")){
return "密码不能为空";
}else if (userExist != null){
return "账户已经存在";
}else {
userMapper.save(user);
return "注册成功";
}
}catch (Exception e){
e.printStackTrace();
return e.getMessage();
}
}
}
package cn.wisenergy.controller;
import cn.wisenergy.model.app.User;
import cn.wisenergy.service.app.impl.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* Created by m1991 on 2021/2/23 15:45
*/
@EnableSwagger2
@RestController
@RequestMapping("/sys")
public class UserController {
@Autowired
UserService userService;
/**
* 登录
*/
@PostMapping("/login")
public String login(User user){
return
userService.login(user);
}
/**
* 注册
* @param user
* @return
*/
@PostMapping("/regist")
public String regist(User user){
return userService.regist(user);
}
}
\ No newline at end of file
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