Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
|
d43468edb9 | 2 months ago |
@ -0,0 +1,33 @@
|
||||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
@ -0,0 +1,118 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>unilife-server</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>backend</name>
|
||||
<description>backend</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<spring-boot.version>2.7.6</spring-boot.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.persistence</groupId>
|
||||
<artifactId>javax.persistence-api</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<version>8.2.0</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.36</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-jpa</artifactId>
|
||||
<version>3.3.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.maven</groupId>
|
||||
<artifactId>tomcat6-maven-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
|
||||
<version>4.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.24</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<configuration>
|
||||
<mainClass>com.example.unilife.BackendApplication</mainClass>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>repackage</id>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,13 @@
|
||||
package com.unilife;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class UniLifeApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(UniLifeApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
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);
|
||||
}
|
||||
|
||||
public static <T> Result<T> success(T data, String message) {
|
||||
return new Result<>(200, message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败返回结果
|
||||
* @param code 状态码
|
||||
* @param message 消息
|
||||
* @return 结果对象
|
||||
*/
|
||||
public static <T> Result<T> error(Integer code, String message) {
|
||||
return new Result<>(code, message, null);
|
||||
}
|
||||
|
||||
public static <T> Result<T> error(T data,String message){
|
||||
return new Result<>(200,message,null);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.unilife.controller;
|
||||
|
||||
import com.unilife.common.result.Result;
|
||||
import com.unilife.model.dto.LogDTO;
|
||||
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);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "用户登录")
|
||||
@PostMapping("login")
|
||||
public Result login(@RequestBody LogDTO logDTO) { return userService.login(logDTO); }
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.unilife.mapper;
|
||||
|
||||
import com.unilife.model.entity.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
void insert(User user);
|
||||
User FindByEmail(@Param("email") String email, @Param("password") String password);
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.unilife.model.dto;
|
||||
//这个才是登录的DTO
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LogDTO {
|
||||
private String email;
|
||||
private String password;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.unilife.model.dto;
|
||||
//这个是注册的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,15 @@
|
||||
package com.unilife.model.vo;
|
||||
|
||||
import com.unilife.model.entity.User;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LogVO {
|
||||
private String username;
|
||||
private String email;
|
||||
private String nickname;
|
||||
private String studentId;
|
||||
private String department;
|
||||
private String major;
|
||||
private String grade;
|
||||
}
|
@ -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,12 @@
|
||||
package com.unilife.service;
|
||||
|
||||
import com.unilife.common.result.Result;
|
||||
import com.unilife.model.dto.LogDTO;
|
||||
import com.unilife.model.dto.LoginDTO;
|
||||
import com.unilife.model.entity.User;
|
||||
|
||||
|
||||
public interface UserService {
|
||||
Result register(LoginDTO loginDTO);
|
||||
Result login(LogDTO logDTO);
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
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.LogDTO;
|
||||
import com.unilife.model.dto.LoginDTO;
|
||||
import com.unilife.model.entity.User;
|
||||
import com.unilife.model.vo.LogVO;
|
||||
import com.unilife.model.vo.LoginVO;
|
||||
import com.unilife.service.UserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result login(LogDTO logDTO) {
|
||||
User user = new User();
|
||||
BeanUtil.copyProperties(logDTO,user);//将登录的前端传来的消息拷贝给这个user
|
||||
User getuser = userMapper.FindByEmail(user.getEmail(),user.getPassword());
|
||||
if(getuser == null)
|
||||
{
|
||||
return Result.error(logDTO,"用户不存在,登录失败!");
|
||||
}
|
||||
if(!user.getPassword().equals(getuser.getPassword()))
|
||||
{
|
||||
return Result.error(logDTO,"密码错误,登录失败!");
|
||||
}
|
||||
LogVO logVO = new LogVO();
|
||||
return Result.success(logVO);
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
server:
|
||||
port: 8087
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3306/UniLife?useSSL=false&serverTimezone=UTC&characterEncoding=UTF-8
|
||||
username: root
|
||||
password: zhong20050428
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
knife4j:
|
||||
enable: true
|
||||
openapi:
|
||||
title: Knife4j官方文档
|
||||
description: "测试"
|
||||
email: xiaoymin@foxmail.com
|
||||
concat: 八一菜刀
|
||||
url: https://docs.xiaominfo.com
|
||||
version: v4.0
|
||||
license: Apache 2.0
|
||||
license-url: https://stackoverflow.com/
|
||||
terms-of-service-url: https://stackoverflow.com/
|
||||
group:
|
||||
test1:
|
||||
group-name: 分组名称
|
||||
api-rule: package
|
||||
api-rule-resources:
|
||||
- com.unilife
|
||||
mybatis:
|
||||
mapper-locations: classpath:mappers/*.xml
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
@ -0,0 +1,53 @@
|
||||
<?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">
|
||||
<resultMap id="userResultMap" type="com.unilife.model.entity.User">
|
||||
<result column="email" property="email"/>
|
||||
<result column="password" property="password"/>
|
||||
</resultMap>
|
||||
<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>
|
||||
|
||||
<select id="FindByEmail" resultMap="userResultMap">
|
||||
select email,password
|
||||
from users
|
||||
where email = #{email} and password = #{password}
|
||||
</select>
|
||||
</mapper>
|
@ -0,0 +1,6 @@
|
||||
<html>
|
||||
<body>
|
||||
<h1>hello word!!!</h1>
|
||||
<p>this is a html page</p>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,13 @@
|
||||
package com.unilife;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class BackendApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue