升级微服务项目
This commit is contained in:
28
javamemories-common/pom.xml
Normal file
28
javamemories-common/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>cn.mayiming</groupId>
|
||||||
|
<artifactId>javamemories-parent</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>javamemories-common</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>javamemories-common</name>
|
||||||
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
14
javamemories-common/src/main/java/cn/mayiming/App.java
Normal file
14
javamemories-common/src/main/java/cn/mayiming/App.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package cn.mayiming;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hello world!
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Spring
|
||||||
|
public class App
|
||||||
|
{
|
||||||
|
public static void main( String[] args )
|
||||||
|
{
|
||||||
|
System.out.println( "Hello World!" );
|
||||||
|
}
|
||||||
|
}
|
||||||
38
javamemories-common/src/test/java/cn/mayiming/AppTest.java
Normal file
38
javamemories-common/src/test/java/cn/mayiming/AppTest.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package cn.mayiming;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for simple App.
|
||||||
|
*/
|
||||||
|
public class AppTest
|
||||||
|
extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create the test case
|
||||||
|
*
|
||||||
|
* @param testName name of the test case
|
||||||
|
*/
|
||||||
|
public AppTest( String testName )
|
||||||
|
{
|
||||||
|
super( testName );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the suite of tests being tested
|
||||||
|
*/
|
||||||
|
public static Test suite()
|
||||||
|
{
|
||||||
|
return new TestSuite( AppTest.class );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rigourous Test :-)
|
||||||
|
*/
|
||||||
|
public void testApp()
|
||||||
|
{
|
||||||
|
assertTrue( true );
|
||||||
|
}
|
||||||
|
}
|
||||||
134
pom.xml
134
pom.xml
@@ -2,96 +2,106 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<!-- 父工程坐标 -->
|
||||||
<groupId>cn.mayiming</groupId>
|
<groupId>cn.mayiming</groupId>
|
||||||
<artifactId>javamemories</artifactId>
|
<artifactId>javamemories-parent</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>javamemories</name>
|
<name>javamemories-parent</name>
|
||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
|
<!-- 继承 Spring Boot 官方父依赖 -->
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<!-- Spring Boot 3最新稳定版,可在官网确认最新版本 -->
|
|
||||||
<version>3.2.3</version>
|
<version>3.2.3</version>
|
||||||
<relativePath/>
|
<relativePath/>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
<!-- 统一版本变量(新增 spring-boot.version 兜底) -->
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<!-- Spring Boot 3 必须用 JDK 17+,否则编译报错 -->
|
|
||||||
<java.version>22</java.version>
|
<java.version>22</java.version>
|
||||||
|
<spring-cloud.version>2023.0.1</spring-cloud.version>
|
||||||
|
<spring-cloud-alibaba.version>2023.0.1.0</spring-cloud-alibaba.version>
|
||||||
|
<mybatis-spring-boot.version>3.0.3</mybatis-spring-boot.version>
|
||||||
|
<!-- 核心新增:显式定义 Spring Boot 版本(和 parent 版本一致) -->
|
||||||
|
<spring-boot.version>3.2.3</spring-boot.version>
|
||||||
|
<!-- 新增 MySQL 驱动版本(避免版本未知) -->
|
||||||
|
<mysql.version>8.0.33</mysql.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<!-- 依赖管理(子模块继承版本,仅管理不引入) -->
|
||||||
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- Spring Cloud 核心版本管理 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>spring-cloud-dependencies</artifactId>
|
||||||
<version>3.8.1</version>
|
<version>${spring-cloud.version}</version>
|
||||||
<scope>test</scope>
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- Spring Cloud Alibaba 版本管理 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||||
|
<version>${spring-cloud-alibaba.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<!-- MyBatis 版本管理 -->
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<!-- 2. MySQL 驱动(适配 Spring Boot 3,运行时依赖) -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-j</artifactId>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</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>
|
<dependency>
|
||||||
<groupId>org.mybatis.spring.boot</groupId>
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
<version>3.0.3</version>
|
<version>${mybatis-spring-boot.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- MySQL 驱动(显式绑定版本) -->
|
||||||
</dependencies>
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
<build>
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
<!-- 必须指定最终生成的 JAR 包名称(可选,但便于识别) -->
|
<version>${mysql.version}</version>
|
||||||
<finalName>javamemories</finalName>
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
<plugins>
|
<!-- Spring Boot Web(显式绑定版本,解决 unknown 问题) -->
|
||||||
<!-- 核心:Spring Boot 打包插件(必须配置,否则无主清单) -->
|
<dependency>
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
<version>3.2.3</version> <!-- 和你的 Spring Boot 版本一致 -->
|
<version>${spring-boot.version}</version>
|
||||||
<executions>
|
</dependency>
|
||||||
<!-- 必须添加这个 execution,否则插件不会生效 -->
|
<!-- Spring Boot Redis(显式绑定版本) -->
|
||||||
<execution>
|
<dependency>
|
||||||
<goals>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<goal>repackage</goal> <!-- 重新打包为可执行 JAR -->
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
</goals>
|
<version>${spring-boot.version}</version>
|
||||||
</execution>
|
</dependency>
|
||||||
</executions>
|
<!-- Spring Boot 测试(显式绑定版本) -->
|
||||||
<!-- 可选:手动指定启动类(防止插件找不到) -->
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<version>${spring-boot.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<!-- 子模块声明 -->
|
||||||
|
<modules>
|
||||||
|
<module>javamemories-common</module>
|
||||||
|
<module>user-service</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<!-- 编译插件(确保 Java 版本兼容) -->
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.11.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<mainClass>cn.mayiming.App</mainClass> <!-- 替换为你的实际启动类全限定名 -->
|
<source>${java.version}</source>
|
||||||
|
<target>${java.version}</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|||||||
35
user-service/pom.xml
Normal file
35
user-service/pom.xml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>cn.mayiming</groupId>
|
||||||
|
<artifactId>javamemories-parent</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>user-service</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>user-service</name>
|
||||||
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- 核心:Spring Boot Web 依赖(版本由父工程继承) -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 测试依赖:适配 Spring Boot 3 的 JUnit 5(替换老旧的 JUnit 3.8.1) -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
17
user-service/src/main/java/cn/mayiming/App.java
Normal file
17
user-service/src/main/java/cn/mayiming/App.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package cn.mayiming;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hello world!
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
public class App
|
||||||
|
{
|
||||||
|
public static void main( String[] args )
|
||||||
|
{
|
||||||
|
SpringApplication.run(App.class, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package cn.mayiming.Controller.Redis;
|
||||||
|
|
||||||
|
public class RedisParam {
|
||||||
|
private String key;
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
// 必须加无参构造器(JSON解析需要)
|
||||||
|
public RedisParam() {}
|
||||||
|
|
||||||
|
// GET/SET方法(必须加,否则JSON解析不到值)
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKey(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package cn.mayiming.Controller.Redis;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class Redistest {
|
||||||
|
@Autowired
|
||||||
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
|
@PostMapping("/redis/put")
|
||||||
|
public String put(@RequestBody RedisParam param) {
|
||||||
|
String key = param.getKey();
|
||||||
|
stringRedisTemplate.opsForValue().set(key, "123", 10, TimeUnit.MINUTES);
|
||||||
|
String redisValue = stringRedisTemplate.opsForValue().get(key);
|
||||||
|
return "Redis写入成功!key=" + key + ",value=" + redisValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package cn.mayiming.Controller.UserCon;
|
||||||
|
|
||||||
|
public class UserBody {
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String username;
|
||||||
|
public String password;
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package cn.mayiming.Controller.UserCon;
|
||||||
|
|
||||||
|
import cn.mayiming.Mapper.UserMapper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserMapper userMapper;
|
||||||
|
|
||||||
|
@PostMapping("/login")
|
||||||
|
public Map<String, Object> login(@RequestBody UserBody user) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
try {
|
||||||
|
String dbPassword = userMapper.getPasswordByUsername(user.getUsername());
|
||||||
|
String username = user.getUsername();
|
||||||
|
String password = user.getPassword();
|
||||||
|
// 3. 编写 SQL 查询数据库中的用户密码
|
||||||
|
// 用 ? 占位符,防止 SQL 注入(必须!)
|
||||||
|
|
||||||
|
// 4. 验证密码(实际项目要加密对比,这里简单演示)
|
||||||
|
if (password != null && password.equals(dbPassword)) {
|
||||||
|
result.put("code", 200);
|
||||||
|
result.put("msg", "登录成功");
|
||||||
|
result.put("data", username);
|
||||||
|
} else {
|
||||||
|
result.put("code", 400);
|
||||||
|
result.put("msg", "密码错误");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 捕获“用户不存在”等异常
|
||||||
|
result.put("code", 404);
|
||||||
|
result.put("msg", "用户名不存在或登录失败");
|
||||||
|
result.put("error", e.getMessage());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
package cn.mayiming.Mapper;
|
||||||
|
import cn.mayiming.Controller.UserCon.UserBody;
|
||||||
|
import org.apache.ibatis.annotations.*;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface UserMapper {
|
||||||
|
@Select("SELECT password FROM user WHERE username = #{username}")
|
||||||
|
String getPasswordByUsername(String username);
|
||||||
|
/**
|
||||||
|
* 根据ID查询用户(单条查询)
|
||||||
|
* @param id 用户ID
|
||||||
|
* @return 完整用户信息
|
||||||
|
*/
|
||||||
|
@Select("SELECT id, username, password, nickname, create_time AS createTime FROM user WHERE id = #{id}")
|
||||||
|
UserBody getUserById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户名查询完整用户信息(登录/校验用)
|
||||||
|
* @param username 用户名
|
||||||
|
* @return 完整用户信息
|
||||||
|
*/
|
||||||
|
@Select("SELECT id, username, password, nickname, create_time AS createTime FROM user WHERE username = #{username}")
|
||||||
|
UserBody getUserByUsername(String username);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有用户(分页建议用 MyBatis-Plus,这里先实现全量)
|
||||||
|
* @return 用户列表
|
||||||
|
*/
|
||||||
|
@Select("SELECT id, username, password, nickname, create_time AS createTime FROM user")
|
||||||
|
List<UserBody> listAllUsers();
|
||||||
|
|
||||||
|
// ==================== 增 ====================
|
||||||
|
/**
|
||||||
|
* 新增用户(自增ID)
|
||||||
|
* @param user 用户实体
|
||||||
|
* @return 影响行数(1=成功,0=失败)
|
||||||
|
*/
|
||||||
|
@Insert("INSERT INTO user (username, password, nickname, create_time) VALUES (#{username}, #{password}, #{nickname}, #{createTime})")
|
||||||
|
@Options(useGeneratedKeys = true, keyProperty = "id") // 自动返回自增的ID到user对象的id字段
|
||||||
|
int insertUser(UserBody user);
|
||||||
|
|
||||||
|
// ==================== 改 ====================
|
||||||
|
/**
|
||||||
|
* 根据ID修改用户昵称
|
||||||
|
* @param id 用户ID
|
||||||
|
* @param nickname 新昵称
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
@Update("UPDATE user SET nickname = #{nickname} WHERE id = #{id}")
|
||||||
|
int updateNicknameById(@Param("id") Long id, @Param("nickname") String nickname);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户名修改密码
|
||||||
|
* @param username 用户名
|
||||||
|
* @param newPassword 新密码
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
@Update("UPDATE user SET password = #{newPassword} WHERE username = #{username}")
|
||||||
|
int updatePasswordByUsername(@Param("username") String username, @Param("newPassword") String password);
|
||||||
|
|
||||||
|
// ==================== 删 ====================
|
||||||
|
/**
|
||||||
|
* 根据ID删除用户
|
||||||
|
* @param id 用户ID
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
@Delete("DELETE FROM user WHERE id = #{id}")
|
||||||
|
int deleteUserById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户名删除用户
|
||||||
|
* @param username 用户名
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
@Delete("DELETE FROM user WHERE username = #{username}")
|
||||||
|
int deleteUserByUsername(String username);
|
||||||
|
}
|
||||||
24
user-service/src/main/resources/application.yml
Normal file
24
user-service/src/main/resources/application.yml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
server:
|
||||||
|
port: 9091
|
||||||
|
spring:
|
||||||
|
data:
|
||||||
|
redis:
|
||||||
|
port: 6379
|
||||||
|
password: ""
|
||||||
|
database: 0
|
||||||
|
timeout: 10000
|
||||||
|
datasource:
|
||||||
|
# 连接 URL(关键:test_db 是你要连接的数据库名,需提前创建)
|
||||||
|
url: jdbc:mysql://rm-f8z6oc5a03331500p8o.mysql.rds.aliyuncs.com:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||||
|
# 数据库用户名
|
||||||
|
username: root
|
||||||
|
# 数据库密码(替换为你的 MySQL 密码)
|
||||||
|
password: Root123456
|
||||||
|
# 驱动类名(MySQL 8.x 用这个,5.x 改为 com.mysql.jdbc.Driver)
|
||||||
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
# 连接池配置(可选,提升性能)
|
||||||
|
hikari:
|
||||||
|
maximum-pool-size: 10 # 最大连接数
|
||||||
|
minimum-idle: 2 # 最小空闲连接数
|
||||||
|
idle-timeout: 60000 # 空闲连接超时时间(毫秒)
|
||||||
|
connection-timeout: 30000 # 连接超时时间(毫秒)
|
||||||
38
user-service/src/test/java/cn/mayiming/AppTest.java
Normal file
38
user-service/src/test/java/cn/mayiming/AppTest.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package cn.mayiming;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for simple App.
|
||||||
|
*/
|
||||||
|
public class AppTest
|
||||||
|
extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create the test case
|
||||||
|
*
|
||||||
|
* @param testName name of the test case
|
||||||
|
*/
|
||||||
|
public AppTest( String testName )
|
||||||
|
{
|
||||||
|
super( testName );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the suite of tests being tested
|
||||||
|
*/
|
||||||
|
public static Test suite()
|
||||||
|
{
|
||||||
|
return new TestSuite( AppTest.class );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rigourous Test :-)
|
||||||
|
*/
|
||||||
|
public void testApp()
|
||||||
|
{
|
||||||
|
assertTrue( true );
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user