首页 > 其他分享 >springboot注册

springboot注册

时间:2024-03-09 14:45:38浏览次数:21  
标签:username 用户名 springboot 占用 User 注册 import String

查询用户,判断用户名是否被占用。

1.没有被占用,则注册

2.被占用,则显示用户名已被占用!

service : UserService

import com.example.pojo.User;

public interface UserService {
    //根据用户名查询用户
    User findByUserName(String username);
}

mapper : UserMapper

@Mapper
public interface UserMapper {
    //根据用户名查询用户
    @Select("select * from user where username=#{username}")
    User findByUserName(String username);
}

controller : UserController

import com.example.pojo.Result;
import com.example.pojo.User;
import com.example.service.UserService;
import jakarta.validation.constraints.Pattern;
import org.springframework.beans.factory.annotation.Autowired;
@RestController
@RequestMapping("/user")
@Validated
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("/register")
    public Result register(@Pattern(regexp = "^\\S{5,16}$") String username, @Pattern(regexp = "^\\S(5,16)$") String password) {
        //查询用户
        User user = userService.findByUserName(username);
        if(user == null){
            //没有占用,注册
            userService.register(username,password);
            return Result.success();
        }else {
            //占用
            return Result.error("用户名已被占用!");
        }
    }
}

标签:username,用户名,springboot,占用,User,注册,import,String
From: https://www.cnblogs.com/xmz88/p/18062688

相关文章

  • WPF多数类概念性注册加自动扫描
    在java中springboot的配置应用了自动扫描@ComponentScan(value={"com.example","com.fox"})而对于Asp.NetCore可以使用ScrutorstaticvoidMain(string[]args){varcollection=newServiceCollection();collection.Scan(action=>......
  • 注册表调整项可以帮助提升NTFS的性能
    在Windows操作系统中,NTFS(NewTechnologyFileSystem)是默认和推荐的文件系统,它提供了比FAT32更高的数据安全性和恢复能力。虽然大多数NTFS性能优化可以通过系统管理工具进行调整,但仍有一些注册表调整项可以帮助提升NTFS的性能。以下是一些可能影响NTFS性能的注册表项,但请注意,修改......
  • springboot项目构建docker镜像
    springboot项目构建docker镜像springboot项目构建成docker镜像的两种方式手动方式:将springboot项目打成一个jar包,将jar包上次到服务器的指定目录下(具备docker环境),然后在同一目录下编写Dockerfile文件,通过dockerbuild命令构建镜像,之后把镜像发布到远程仓库中。半自动方式:......
  • 基于苍穹外卖写的springboot学习笔记,私聊拿源码
    一.关于md5加密的了解与使用1.分析MD5加密是一种不可逆的加密算法。也就是说我们只能正向加密,无法反向解密。于是乎,当我们用它作为密码加密方式时,我们只能加密码从数据库拿来与前端传来的数据加密后进行比较。2.使用方法他是由springboot框架提供二.关于swagge......
  • springboot项目接入普罗米修斯
    为了更好查询项目的运行状态,这次引入普罗米修斯监控pom依赖<!--starter-actuator--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency><!--下面是/actuato......
  • springboot 2.4.0 启动源码分析
    SpringBoot启动的基本配置SpringBoot启动的配置主要有以下两个部分添加依赖最基本的springboot依赖只需要添加一个springboot启动器的依赖即可,如果是web服务则添加web的启动器<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"......
  • springboot整合nacos注册中心和配置中心
    我的命名空间是centos效果图   可以是yml格式,名称不要变springboot版本2.1.6pom依赖<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchem......
  • nacos成功注册却报异常(http://localhost:8848)
    报错日志:[NACOSHTTP-POST]Themaximumnumberoftolerableserverreconnectionerrorshasbeenreached[fixed-localhost_8848][check-update]getchangeddataIdexception[NACOSConnectExceptionhttpPost]currentServerAddr:http://localhost:8848,err:Connec......
  • SpringBoot 支付宝付款接口类、支付异步回调函数模板
    1.付款接口类1.1.引入Maven依赖<dependency><groupId>com.alipay.sdk</groupId><artifactId>alipay-sdk-java</artifactId><version>4.38.221.ALL</version></dependency>1.2.将下面代码保存为AlipayTemplate.java@Config......
  • SpringBoot-重要注解(1)
    ConfigurationProperties注解https://blog.csdn.net/skh2015java/article/details/120141409@Import、@ImportAutoConfigurationhttps://www.cnblogs.com/imyjy/p/16092825.html当我们需要在一个配置类中导入另一个Configuration配置类时,可以使用@Import、@ImportAuto......