基础版本完成
This commit is contained in:
35
user-service/pom.xml
Normal file
35
user-service/pom.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>SpringCloudStudy</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>user-service</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</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>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>commons</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
18
user-service/src/main/java/com/test/UserApplication.java
Normal file
18
user-service/src/main/java/com/test/UserApplication.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.test;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* ClassName: UserApplication
|
||||
* Package: com.test
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/8/14 16:26
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class UserApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(UserApplication.class, args);
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.test.controller;
|
||||
|
||||
import com.test.entity.User;
|
||||
import com.test.service.UserService;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* ClassName: UserController
|
||||
* Package: com.test.controller
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/8/14 17:08
|
||||
*/
|
||||
@RestController
|
||||
public class UserController {
|
||||
|
||||
@Resource
|
||||
UserService service;
|
||||
|
||||
//这里以RESTFul风格为例
|
||||
@RequestMapping("/user/{uid}")
|
||||
public User findUserById(@PathVariable("uid") int uid) {
|
||||
return service.getUserById(uid);
|
||||
}
|
||||
}
|
18
user-service/src/main/java/com/test/mapper/UserMapper.java
Normal file
18
user-service/src/main/java/com/test/mapper/UserMapper.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.test.mapper;
|
||||
|
||||
import com.test.entity.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* ClassName: UserMapper
|
||||
* Package: com.test.mapper
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/8/14 17:04
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
@Select("select * from DB_USER where uid = #{uid}")
|
||||
User getUserById(int uid);
|
||||
}
|
14
user-service/src/main/java/com/test/service/UserService.java
Normal file
14
user-service/src/main/java/com/test/service/UserService.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.test.service;
|
||||
|
||||
import com.test.entity.User;
|
||||
|
||||
/**
|
||||
* ClassName: UserService
|
||||
* Package: com.test.service
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/8/14 17:05
|
||||
*/
|
||||
public interface UserService {
|
||||
User getUserById(int uid);
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
package com.test.service.impl;
|
||||
|
||||
import com.test.entity.User;
|
||||
import com.test.mapper.UserMapper;
|
||||
import com.test.service.UserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* ClassName: UserServiceImpl
|
||||
* Package: com.test.service.impl
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/8/14 17:07
|
||||
*/
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
@Resource
|
||||
UserMapper mapper;
|
||||
|
||||
@Override
|
||||
public User getUserById(int uid) {
|
||||
return mapper.getUserById(uid);
|
||||
}
|
||||
}
|
8
user-service/src/main/resources/application.yml
Normal file
8
user-service/src/main/resources/application.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
server:
|
||||
port: 8101
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://43.143.164.194:3306/mac
|
||||
username: mac
|
||||
password: mactest
|
Reference in New Issue
Block a user