master
parent
ee92647981
commit
81fe96ac36
@ -1,86 +1,86 @@
|
||||
<?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>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.0.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.book</groupId>
|
||||
<artifactId>book</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>book</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
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>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.0.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.book</groupId>
|
||||
<artifactId>book</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>book</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-log4j2</artifactId>
|
||||
</dependency>
|
||||
<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.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-log4j2</artifactId>
|
||||
</dependency>
|
||||
<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.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
@ -1,33 +0,0 @@
|
||||
package com.book.demo.controller;
|
||||
|
||||
import com.book.demo.entity.User;
|
||||
import com.book.demo.mapper.UserMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
public class DemoController {
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
//返回JSON
|
||||
@ResponseBody
|
||||
@RequestMapping("/query")
|
||||
public User queryUserByusername(@RequestParam("username") String username){
|
||||
User user=userMapper.queryUserByusername(username);
|
||||
return user;
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/login")
|
||||
public Integer login(@RequestBody User user){
|
||||
System.out.println(user);
|
||||
User user1=userMapper.queryUserByusername(user.getUsername());
|
||||
if(user1==null)
|
||||
return -1;
|
||||
if(!user1.getPassword().trim().equals(user.getPassword().trim()))
|
||||
return -2;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package com.book.demo.controller;
|
||||
|
||||
import com.book.demo.entity.User;
|
||||
import com.book.demo.mapper.UserMapper;
|
||||
import com.book.demo.services.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Controller
|
||||
public class UserController {
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
@Autowired
|
||||
private Result res;
|
||||
|
||||
//返回JSON
|
||||
@ResponseBody
|
||||
@RequestMapping("/query")
|
||||
public Result queryUserByusername(@RequestParam("username") String username){
|
||||
User user=userMapper.queryUserByusername(username);
|
||||
if(user!=null) {
|
||||
res.setCode(0);
|
||||
res.setMsg("查找成功");
|
||||
res.data.add(user);
|
||||
}
|
||||
else {
|
||||
res.setCode(-1);
|
||||
res.setMsg("数据非法,无此用户");
|
||||
res.data=null;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/login")
|
||||
public Result login(@RequestBody User user){
|
||||
System.out.println(user);
|
||||
User user1=userMapper.queryUserByusername(user.getUsername());
|
||||
if(user1==null){
|
||||
res.setCode(-1);
|
||||
res.setMsg("用户不存在");
|
||||
res.data=null;
|
||||
}
|
||||
else if(!user1.getPassword().trim().equals(user.getPassword().trim()))
|
||||
{
|
||||
res.setCode(-2);
|
||||
res.setMsg("密码错误");
|
||||
res.data=null;
|
||||
}
|
||||
else if(user.getKind()==0){
|
||||
res.setCode(0);
|
||||
res.setMsg("用户登录");
|
||||
res.data.add(user1);
|
||||
}
|
||||
else{
|
||||
res.setCode(1);
|
||||
res.setMsg("管理员登录");
|
||||
res.data.add(user1);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/register")
|
||||
public Result register(@RequestBody User user) {
|
||||
User user1=userMapper.queryUserByusername(user.getUsername());
|
||||
if(user1!=null){
|
||||
res.setCode(-1);
|
||||
res.setMsg("用户已存在");
|
||||
res.data=null;
|
||||
}
|
||||
else{
|
||||
user1=user;
|
||||
user1.setKind(0);
|
||||
if(userMapper.InsertUser(user1)>0){
|
||||
res.setCode(1);
|
||||
res.setMsg("注册成功");
|
||||
}else{
|
||||
res.setCode(-2);
|
||||
res.setMsg("注册失败,稍后再试");
|
||||
}
|
||||
res.data=null;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.book.demo.services;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class Result {
|
||||
public int code;
|
||||
public String msg;
|
||||
public List data;
|
||||
|
||||
Result(){
|
||||
data=new ArrayList();
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public List getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(List data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue