11 changed files with 190 additions and 40 deletions
-
81pom.xml
-
6src/main/java/com/dreamworks/boditech/BoditechApplication.java
-
23src/main/java/com/dreamworks/boditech/controller/BaseController.java
-
19src/main/java/com/dreamworks/boditech/controller/DeviceController.java
-
4src/main/java/com/dreamworks/boditech/controller/TestController.java
-
54src/main/java/com/dreamworks/boditech/controller/UserController.java
-
6src/main/java/com/dreamworks/boditech/controller/entity/ApiResponse.java
-
9src/main/java/com/dreamworks/boditech/entity/User.java
-
21src/main/java/com/dreamworks/boditech/mapper/UserMapper.java
-
1src/main/resources/application.properties
-
6src/main/resources/application.yml
@ -1,41 +1,50 @@ |
|||
<?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>3.1.5</version> |
|||
<relativePath/> <!-- lookup parent from repository --> |
|||
</parent> |
|||
<groupId>com.dreamworks</groupId> |
|||
<artifactId>boditech</artifactId> |
|||
<version>0.0.1-SNAPSHOT</version> |
|||
<name>boditech</name> |
|||
<description>boditech</description> |
|||
<properties> |
|||
<java.version>17</java.version> |
|||
</properties> |
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-web</artifactId> |
|||
</dependency> |
|||
<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.dreamworks</groupId> |
|||
<artifactId>boditech</artifactId> |
|||
<version>0.0.1-SNAPSHOT</version> |
|||
<name>boditech</name> |
|||
<description>boditech</description> |
|||
|
|||
<parent> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-parent</artifactId> |
|||
<version>3.1.5</version> |
|||
<relativePath/> <!-- lookup parent from repository --> |
|||
</parent> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-test</artifactId> |
|||
<scope>test</scope> |
|||
</dependency> |
|||
</dependencies> |
|||
<properties> |
|||
<java.version>17</java.version> |
|||
</properties> |
|||
|
|||
<build> |
|||
<plugins> |
|||
<plugin> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-maven-plugin</artifactId> |
|||
</plugin> |
|||
</plugins> |
|||
</build> |
|||
<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>3.0.2</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.mysql</groupId> |
|||
<artifactId>mysql-connector-j</artifactId> |
|||
<scope>runtime</scope> |
|||
</dependency> |
|||
</dependencies> |
|||
|
|||
<build> |
|||
<plugins> |
|||
<plugin> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-maven-plugin</artifactId> |
|||
</plugin> |
|||
</plugins> |
|||
</build> |
|||
</project> |
@ -0,0 +1,23 @@ |
|||
package com.dreamworks.boditech.controller; |
|||
import com.dreamworks.boditech.controller.entity.ApiResponse; |
|||
public class BaseController { |
|||
protected ApiResponse success(Object data ) { |
|||
ApiResponse response = new ApiResponse(); |
|||
response.success = true; |
|||
response.message = "OK"; |
|||
response.data = data; |
|||
return response; |
|||
} |
|||
|
|||
protected ApiResponse success() { |
|||
return this.success(null); |
|||
} |
|||
|
|||
protected ApiResponse error( String message ) { |
|||
ApiResponse response = new ApiResponse(); |
|||
response.success = false; |
|||
response.message = message; |
|||
response.data = null; |
|||
return response; |
|||
} |
|||
} |
@ -0,0 +1,19 @@ |
|||
package com.dreamworks.boditech.controller; |
|||
import com.dreamworks.boditech.controller.entity.ApiResponse; |
|||
import org.springframework.stereotype.Controller; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.ResponseBody; |
|||
@Controller |
|||
public class DeviceController extends BaseController { |
|||
@ResponseBody |
|||
@PostMapping("/api/device/start") |
|||
public ApiResponse start() { |
|||
return this.success(); |
|||
} |
|||
|
|||
@ResponseBody |
|||
@PostMapping("/api/device/stop") |
|||
public ApiResponse stop() { |
|||
return this.success(); |
|||
} |
|||
} |
@ -0,0 +1,4 @@ |
|||
package com.dreamworks.boditech.controller; |
|||
|
|||
public class TestController { |
|||
} |
@ -0,0 +1,54 @@ |
|||
package com.dreamworks.boditech.controller; |
|||
import com.dreamworks.boditech.controller.entity.ApiResponse; |
|||
import com.dreamworks.boditech.entity.User; |
|||
import com.dreamworks.boditech.mapper.UserMapper; |
|||
import jakarta.annotation.Resource; |
|||
import org.springframework.stereotype.Controller; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.ResponseBody; |
|||
|
|||
@Controller |
|||
public class UserController extends BaseController { |
|||
@Resource |
|||
UserMapper userMapper; |
|||
|
|||
@ResponseBody |
|||
@PostMapping("/api/user/login") |
|||
public ApiResponse login( String name, String pin ) { |
|||
User user = userMapper.findByName(name); |
|||
if ( null == user || !user.pin.equals(pin) ) { |
|||
return this.error("无效的用户名或PIN"); |
|||
} |
|||
return this.success(user); |
|||
} |
|||
|
|||
@ResponseBody |
|||
@PostMapping("/api/user/pin-update") |
|||
public ApiResponse pinUpdate( int id, String pin ) { |
|||
User user = userMapper.findById(id); |
|||
if ( null == user ) { |
|||
return this.error("无效的用户id : " + id); |
|||
} |
|||
user.pin = pin; |
|||
int changeCount = userMapper.update(user); |
|||
if ( 1 != changeCount ) { |
|||
return this.error("数据更新异常"); |
|||
} |
|||
return this.success(); |
|||
} |
|||
|
|||
@ResponseBody |
|||
@PostMapping("/api/user/delete") |
|||
public ApiResponse delete( int id ) { |
|||
User user = userMapper.findById(id); |
|||
if ( null == user ) { |
|||
return this.error("无效的用户id : " + id); |
|||
} |
|||
|
|||
int deleteCount = userMapper.delete(user); |
|||
if ( 1 != deleteCount ) { |
|||
return this.error("数据删除异常"); |
|||
} |
|||
return this.success(); |
|||
} |
|||
} |
@ -0,0 +1,6 @@ |
|||
package com.dreamworks.boditech.controller.entity; |
|||
public class ApiResponse { |
|||
public boolean success ; |
|||
public String message; |
|||
public Object data; |
|||
} |
@ -0,0 +1,9 @@ |
|||
package com.dreamworks.boditech.entity; |
|||
public class User { |
|||
public int id; |
|||
public String name; |
|||
public String pin; |
|||
public int isAdmin; |
|||
public int createdAt; |
|||
public int createdBy; |
|||
} |
@ -0,0 +1,21 @@ |
|||
package com.dreamworks.boditech.mapper; |
|||
import com.dreamworks.boditech.entity.User; |
|||
import org.apache.ibatis.annotations.Delete; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
import org.apache.ibatis.annotations.Select; |
|||
import org.apache.ibatis.annotations.Update; |
|||
|
|||
@Mapper |
|||
public interface UserMapper { |
|||
@Select("SELECT * FROM bdt_users WHERE id=#{id}") |
|||
User findById(int id); |
|||
|
|||
@Select("SELECT * FROM bdt_users WHERE name=#{name} LIMIT 1") |
|||
User findByName(String name); |
|||
|
|||
@Update("UPDATE bdt_users SET name=#{name}, pin=#{pin}, isAdmin=#{isAdmin} WHERE id=#{id}") |
|||
int update(User user); |
|||
|
|||
@Delete("DELETE FROM bdt_users WHERE id=#{id}") |
|||
int delete(User user); |
|||
} |
@ -1 +0,0 @@ |
|||
|
@ -0,0 +1,6 @@ |
|||
spring: |
|||
datasource: |
|||
url: jdbc:mysql://localhost:3306/boditech |
|||
username : root |
|||
password: 123456 |
|||
driver-class-name: com.mysql.cj.jdbc.Driver |
Write
Preview
Loading…
Cancel
Save
Reference in new issue