Merge branch 'main' of https://bdgit.educoder.net/pizvue73f/unilife
commit
0b923dd66a
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||||
|
<data-source source="LOCAL" name="unilife@localhost" uuid="9c6c9710-15d0-4710-8fca-930cc43549e9">
|
||||||
|
<driver-ref>mysql.8</driver-ref>
|
||||||
|
<synchronize>true</synchronize>
|
||||||
|
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||||
|
<jdbc-url>jdbc:mysql://localhost:3306/unilife</jdbc-url>
|
||||||
|
<jdbc-additional-properties>
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||||
|
</jdbc-additional-properties>
|
||||||
|
<working-dir>$ProjectFileDir$</working-dir>
|
||||||
|
</data-source>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -1,4 +1,4 @@
|
|||||||
package com.example.unilife;
|
package com.unilife;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
@ -0,0 +1,51 @@
|
|||||||
|
package com.unilife.common.result;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class Result<T>{
|
||||||
|
/***
|
||||||
|
* 状态码
|
||||||
|
*/
|
||||||
|
private Integer code;
|
||||||
|
/***
|
||||||
|
* 消息
|
||||||
|
*/
|
||||||
|
private String message;
|
||||||
|
/***
|
||||||
|
*数据
|
||||||
|
*/
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
/***
|
||||||
|
*
|
||||||
|
* @param data 数据
|
||||||
|
* @return 结果对象
|
||||||
|
* @param <T> 数据类型
|
||||||
|
*/
|
||||||
|
public static <T>Result<T>success(T data){
|
||||||
|
return new Result<T>(200, "success", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功返回结果
|
||||||
|
* @return 结果对象
|
||||||
|
*/
|
||||||
|
public static Result<Void> success() {
|
||||||
|
return new Result<>(200, "success", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败返回结果
|
||||||
|
* @param code 状态码
|
||||||
|
* @param message 消息
|
||||||
|
* @return 结果对象
|
||||||
|
*/
|
||||||
|
public static <T> Result<T> error(Integer code, String message) {
|
||||||
|
return new Result<>(code, message, null);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.unilife.controller;
|
||||||
|
|
||||||
|
import com.unilife.common.result.Result;
|
||||||
|
import com.unilife.model.dto.LoginDTO;
|
||||||
|
import com.unilife.service.UserService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@Api(tags = "用户管理")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/users")
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@ApiOperation(value = "用户注册")
|
||||||
|
@PostMapping("register")
|
||||||
|
public Result register(@RequestBody LoginDTO loginDTO) {
|
||||||
|
return userService.register(loginDTO);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.unilife.mapper;
|
||||||
|
|
||||||
|
import com.unilife.model.entity.User;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface UserMapper {
|
||||||
|
public void insert(User user) ;
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.unilife.model.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class LoginDTO {
|
||||||
|
private String username;
|
||||||
|
private String email;
|
||||||
|
private String password;
|
||||||
|
private String nickname;
|
||||||
|
private String studentId;
|
||||||
|
private String department;
|
||||||
|
private String major;
|
||||||
|
private String grade;
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
package com.unilife.model.entity;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class User implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
private String nickname;
|
||||||
|
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
private String bio;
|
||||||
|
|
||||||
|
private Byte gender;
|
||||||
|
|
||||||
|
private String studentId;
|
||||||
|
|
||||||
|
private String department;
|
||||||
|
|
||||||
|
private String major;
|
||||||
|
|
||||||
|
private String grade;
|
||||||
|
|
||||||
|
private Integer points = 0;
|
||||||
|
|
||||||
|
private Byte role = 0;
|
||||||
|
|
||||||
|
private Byte status = 1;
|
||||||
|
|
||||||
|
private Byte isVerified = 0;
|
||||||
|
|
||||||
|
private String loginIp;
|
||||||
|
|
||||||
|
private LocalDateTime loginTime;
|
||||||
|
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.unilife.model.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class LoginVO {
|
||||||
|
private Integer id;
|
||||||
|
private String username;
|
||||||
|
private String nickname;
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.unilife.service;
|
||||||
|
|
||||||
|
import com.unilife.common.result.Result;
|
||||||
|
import com.unilife.model.dto.LoginDTO;
|
||||||
|
|
||||||
|
|
||||||
|
public interface UserService {
|
||||||
|
Result register(LoginDTO loginDTO);
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.unilife.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import com.unilife.common.result.Result;
|
||||||
|
import com.unilife.mapper.UserMapper;
|
||||||
|
import com.unilife.model.dto.LoginDTO;
|
||||||
|
import com.unilife.model.entity.User;
|
||||||
|
import com.unilife.model.vo.LoginVO;
|
||||||
|
import com.unilife.service.UserService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UserServiceImpl implements UserService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserMapper userMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result register(LoginDTO loginDTO) {
|
||||||
|
User user = new User();
|
||||||
|
BeanUtil.copyProperties(loginDTO,user);
|
||||||
|
userMapper.insert(user);
|
||||||
|
LoginVO loginVO = new LoginVO();
|
||||||
|
return Result.success(loginVO);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
|
<mapper namespace="com.unilife.mapper.UserMapper">
|
||||||
|
<insert id="insert" parameterType="com.unilife.model.entity.User" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
INSERT INTO users (
|
||||||
|
username,
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
nickname,
|
||||||
|
avatar,
|
||||||
|
bio,
|
||||||
|
gender,
|
||||||
|
student_id,
|
||||||
|
department,
|
||||||
|
major,
|
||||||
|
grade,
|
||||||
|
points,
|
||||||
|
role,
|
||||||
|
status,
|
||||||
|
is_verified,
|
||||||
|
login_ip,
|
||||||
|
login_time
|
||||||
|
) VALUES (
|
||||||
|
#{username},
|
||||||
|
#{email},
|
||||||
|
#{password},
|
||||||
|
#{nickname},
|
||||||
|
#{avatar},
|
||||||
|
#{bio},
|
||||||
|
#{gender},
|
||||||
|
#{studentId},
|
||||||
|
#{department},
|
||||||
|
#{major},
|
||||||
|
#{grade},
|
||||||
|
#{points},
|
||||||
|
#{role},
|
||||||
|
#{status},
|
||||||
|
#{isVerified},
|
||||||
|
#{loginIp},
|
||||||
|
#{loginTime}
|
||||||
|
)
|
||||||
|
</insert>
|
||||||
|
</mapper>
|
@ -1,4 +1,4 @@
|
|||||||
package com.example.unilife;
|
package com.unilife;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
Loading…
Reference in new issue