基础版本完成

This commit is contained in:
2023-08-14 22:45:38 +08:00
commit 6c3b4925cf
28 changed files with 689 additions and 0 deletions

35
user-service/pom.xml Normal file
View 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>

View 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);
}
}

View File

@@ -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);
}
}

View 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);
}

View 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);
}

View File

@@ -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);
}
}

View 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