基础版本完成
This commit is contained in:
		
							
								
								
									
										33
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
			
		||||
HELP.md
 | 
			
		||||
target/
 | 
			
		||||
!.mvn/wrapper/maven-wrapper.jar
 | 
			
		||||
!**/src/main/**/target/
 | 
			
		||||
!**/src/test/**/target/
 | 
			
		||||
 | 
			
		||||
### STS ###
 | 
			
		||||
.apt_generated
 | 
			
		||||
.classpath
 | 
			
		||||
.factorypath
 | 
			
		||||
.project
 | 
			
		||||
.settings
 | 
			
		||||
.springBeans
 | 
			
		||||
.sts4-cache
 | 
			
		||||
 | 
			
		||||
### IntelliJ IDEA ###
 | 
			
		||||
.idea
 | 
			
		||||
*.iws
 | 
			
		||||
*.iml
 | 
			
		||||
*.ipr
 | 
			
		||||
 | 
			
		||||
### NetBeans ###
 | 
			
		||||
/nbproject/private/
 | 
			
		||||
/nbbuild/
 | 
			
		||||
/dist/
 | 
			
		||||
/nbdist/
 | 
			
		||||
/.nb-gradle/
 | 
			
		||||
build/
 | 
			
		||||
!**/src/main/**/build/
 | 
			
		||||
!**/src/test/**/build/
 | 
			
		||||
 | 
			
		||||
### VS Code ###
 | 
			
		||||
.vscode/
 | 
			
		||||
							
								
								
									
										37
									
								
								book-service/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								book-service/pom.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
			
		||||
<?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>book-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>
 | 
			
		||||
							
								
								
									
										19
									
								
								book-service/src/main/java/com/test/BookApplication.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								book-service/src/main/java/com/test/BookApplication.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
package com.test;
 | 
			
		||||
 | 
			
		||||
import com.apple.eawt.Application;
 | 
			
		||||
import org.springframework.boot.SpringApplication;
 | 
			
		||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: BookApplication
 | 
			
		||||
 * Package: com.test
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/8/14 16:23
 | 
			
		||||
 */
 | 
			
		||||
@SpringBootApplication
 | 
			
		||||
public class BookApplication {
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        SpringApplication.run(BookApplication.class,args);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,28 @@
 | 
			
		||||
package com.test.controller;
 | 
			
		||||
 | 
			
		||||
import com.test.service.BookService;
 | 
			
		||||
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;
 | 
			
		||||
import com.test.entity.Book;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: BookController
 | 
			
		||||
 * Package: com.test.controller
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/8/14 17:11
 | 
			
		||||
 */
 | 
			
		||||
@RestController
 | 
			
		||||
public class BookController {
 | 
			
		||||
 | 
			
		||||
    @Resource
 | 
			
		||||
    BookService service;
 | 
			
		||||
 | 
			
		||||
    @RequestMapping("/book/{bid}")
 | 
			
		||||
    Book findBookById(@PathVariable("bid") int bid){
 | 
			
		||||
        return service.getBookById(bid);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										20
									
								
								book-service/src/main/java/com/test/mapper/BookMapper.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								book-service/src/main/java/com/test/mapper/BookMapper.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
package com.test.mapper;
 | 
			
		||||
 | 
			
		||||
import org.apache.ibatis.annotations.Mapper;
 | 
			
		||||
import org.apache.ibatis.annotations.Select;
 | 
			
		||||
 | 
			
		||||
import com.test.entity.Book;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: BookMapper
 | 
			
		||||
 * Package: com.test.mapper
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/8/14 17:02
 | 
			
		||||
 */
 | 
			
		||||
@Mapper
 | 
			
		||||
public interface BookMapper {
 | 
			
		||||
 | 
			
		||||
    @Select("select * from DB_BOOK where bid = #{bid}")
 | 
			
		||||
    Book getBookById(int bid);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										14
									
								
								book-service/src/main/java/com/test/service/BookService.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								book-service/src/main/java/com/test/service/BookService.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
package com.test.service;
 | 
			
		||||
 | 
			
		||||
import com.test.entity.Book;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: BookService
 | 
			
		||||
 * Package: com.test.service
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/8/14 17:03
 | 
			
		||||
 */
 | 
			
		||||
public interface BookService {
 | 
			
		||||
    Book getBookById(int bid);
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,27 @@
 | 
			
		||||
package com.test.service.impl;
 | 
			
		||||
 | 
			
		||||
import com.test.mapper.BookMapper;
 | 
			
		||||
import com.test.service.BookService;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Resource;
 | 
			
		||||
import com.test.entity.Book;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: BookServiceImpl
 | 
			
		||||
 * Package: com.test.service.impl
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/8/14 17:09
 | 
			
		||||
 */
 | 
			
		||||
@Service
 | 
			
		||||
public class BookServiceImpl implements BookService {
 | 
			
		||||
 | 
			
		||||
    @Resource
 | 
			
		||||
    BookMapper mapper;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Book getBookById(int bid) {
 | 
			
		||||
        return mapper.getBookById(bid);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										8
									
								
								book-service/src/main/resources/application.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								book-service/src/main/resources/application.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
server:
 | 
			
		||||
  port: 8201
 | 
			
		||||
spring:
 | 
			
		||||
  datasource:
 | 
			
		||||
    driver-class-name: com.mysql.cj.jdbc.Driver
 | 
			
		||||
    url: jdbc:mysql://43.143.164.194:3306/mac
 | 
			
		||||
    username: mac
 | 
			
		||||
    password: mactest
 | 
			
		||||
							
								
								
									
										41
									
								
								borrow-service/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								borrow-service/pom.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,41 @@
 | 
			
		||||
<?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>borrow-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>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.example</groupId>
 | 
			
		||||
            <artifactId>commons</artifactId>
 | 
			
		||||
            <version>0.0.1-SNAPSHOT</version>
 | 
			
		||||
            <scope>compile</scope>
 | 
			
		||||
        </dependency>
 | 
			
		||||
    </dependencies>
 | 
			
		||||
</project>
 | 
			
		||||
							
								
								
									
										18
									
								
								borrow-service/src/main/java/com/test/BorrowApplication.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								borrow-service/src/main/java/com/test/BorrowApplication.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
package com.test;
 | 
			
		||||
 | 
			
		||||
import org.springframework.boot.SpringApplication;
 | 
			
		||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: BorrowApplication
 | 
			
		||||
 * Package: com.test
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/8/14 16:25
 | 
			
		||||
 */
 | 
			
		||||
@SpringBootApplication
 | 
			
		||||
public class BorrowApplication {
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        SpringApplication.run(BorrowApplication.class, args);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,29 @@
 | 
			
		||||
package com.test.controller;
 | 
			
		||||
 | 
			
		||||
import com.test.entity.UserBorrowDetail;
 | 
			
		||||
import com.test.service.BorrowService;
 | 
			
		||||
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: BorrowController
 | 
			
		||||
 * Package: com.test.controller
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/8/14 21:30
 | 
			
		||||
 */
 | 
			
		||||
@RestController
 | 
			
		||||
public class BorrowController {
 | 
			
		||||
 | 
			
		||||
    @Resource
 | 
			
		||||
    BorrowService service;
 | 
			
		||||
 | 
			
		||||
    @RequestMapping("/borrow/{uid}")
 | 
			
		||||
    UserBorrowDetail findUserBorrows(@PathVariable("uid") int uid){
 | 
			
		||||
        return service.getUserBorrowDetailByUid(uid);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,20 @@
 | 
			
		||||
package com.test.entity;
 | 
			
		||||
 | 
			
		||||
import lombok.AllArgsConstructor;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: com.test.entity.UserBorrowDetail
 | 
			
		||||
 * Package: PACKAGE_NAME
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/8/14 21:22
 | 
			
		||||
 */
 | 
			
		||||
@Data
 | 
			
		||||
@AllArgsConstructor
 | 
			
		||||
public class UserBorrowDetail {
 | 
			
		||||
    User user;
 | 
			
		||||
    List<Book> bookList;
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,26 @@
 | 
			
		||||
package com.test.mapper;
 | 
			
		||||
 | 
			
		||||
import com.test.entity.Borrow;
 | 
			
		||||
import org.apache.ibatis.annotations.Mapper;
 | 
			
		||||
import org.apache.ibatis.annotations.Select;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: BorrowMapper
 | 
			
		||||
 * Package: com.test.mapper
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/8/14 17:04
 | 
			
		||||
 */
 | 
			
		||||
@Mapper
 | 
			
		||||
public interface BorrowMapper {
 | 
			
		||||
    @Select("select * from DB_BORROW where uid = #{uid}")
 | 
			
		||||
    List<Borrow> getBorrowsByUid(int uid);
 | 
			
		||||
 | 
			
		||||
    @Select("select * from DB_BORROW where bid = #{bid}")
 | 
			
		||||
    List<Borrow> getBorrowsByBid(int bid);
 | 
			
		||||
 | 
			
		||||
    @Select("select * from DB_BORROW where bid = #{bid} and uid = #{uid}")
 | 
			
		||||
    Borrow getBorrow(int uid, int bid);
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,16 @@
 | 
			
		||||
package com.test.service;
 | 
			
		||||
 | 
			
		||||
import com.test.entity.User;
 | 
			
		||||
import com.test.entity.UserBorrowDetail;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: BorrowService
 | 
			
		||||
 * Package: com.test.service
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/8/14 17:04
 | 
			
		||||
 */
 | 
			
		||||
public interface BorrowService {
 | 
			
		||||
 | 
			
		||||
    UserBorrowDetail getUserBorrowDetailByUid(int uid);
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,43 @@
 | 
			
		||||
package com.test.service.impl;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import com.test.entity.Book;
 | 
			
		||||
import com.test.entity.Borrow;
 | 
			
		||||
import com.test.entity.User;
 | 
			
		||||
import com.test.entity.UserBorrowDetail;
 | 
			
		||||
import com.test.mapper.BorrowMapper;
 | 
			
		||||
import com.test.service.BorrowService;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import org.springframework.web.client.RestTemplate;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Resource;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: BorrowServiceImpl
 | 
			
		||||
 * Package: com.test.service.impl
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/8/14 21:25
 | 
			
		||||
 */
 | 
			
		||||
@Service
 | 
			
		||||
public class BorrowServiceImpl implements BorrowService {
 | 
			
		||||
 | 
			
		||||
    @Resource
 | 
			
		||||
    BorrowMapper mapper;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public UserBorrowDetail getUserBorrowDetailByUid(int uid) {
 | 
			
		||||
        List<Borrow> borrow = mapper.getBorrowsByUid(uid);
 | 
			
		||||
        //RestTemplate支持多种方式的远程调用
 | 
			
		||||
        RestTemplate template = new RestTemplate();
 | 
			
		||||
        //这里通过调用getForObject来请求其他服务,并将结果自动进行封装
 | 
			
		||||
        //获取User信息
 | 
			
		||||
        User user = template.getForObject("http://localhost:8101/user/" + uid, User.class);
 | 
			
		||||
        //获取每一本书的详细信息
 | 
			
		||||
        List<Book> bookList = borrow.stream().map(b -> template.getForObject("http://localhost:8201/book/" + b.getBid(), Book.class)).collect(Collectors.toList());
 | 
			
		||||
        return new UserBorrowDetail(user, bookList);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										8
									
								
								borrow-service/src/main/resources/application.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								borrow-service/src/main/resources/application.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
server:
 | 
			
		||||
  port: 8301
 | 
			
		||||
spring:
 | 
			
		||||
  datasource:
 | 
			
		||||
    driver-class-name: com.mysql.cj.jdbc.Driver
 | 
			
		||||
    url: jdbc:mysql://43.143.164.194:3306/mac
 | 
			
		||||
    username: mac
 | 
			
		||||
    password: mactest
 | 
			
		||||
							
								
								
									
										21
									
								
								commons/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								commons/pom.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
<?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>commons</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>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
							
								
								
									
										17
									
								
								commons/src/main/java/com/test/entity/Book.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								commons/src/main/java/com/test/entity/Book.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
package com.test.entity;
 | 
			
		||||
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: Book
 | 
			
		||||
 * Package: com.test.entity
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/8/14 21:17
 | 
			
		||||
 */
 | 
			
		||||
@Data
 | 
			
		||||
public class Book {
 | 
			
		||||
    int bid;
 | 
			
		||||
    String title;
 | 
			
		||||
    String des;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										17
									
								
								commons/src/main/java/com/test/entity/Borrow.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								commons/src/main/java/com/test/entity/Borrow.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
package com.test.entity;
 | 
			
		||||
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: Borrow
 | 
			
		||||
 * Package: com.test.entity
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/8/14 17:01
 | 
			
		||||
 */
 | 
			
		||||
@Data
 | 
			
		||||
public class Borrow {
 | 
			
		||||
    int id;
 | 
			
		||||
    int uid;
 | 
			
		||||
    int bid;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										31
									
								
								commons/src/main/java/com/test/entity/User.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								commons/src/main/java/com/test/entity/User.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
			
		||||
package com.test.entity;
 | 
			
		||||
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: User
 | 
			
		||||
 * Package: com.test.entity
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/8/14 17:01
 | 
			
		||||
 */
 | 
			
		||||
@Data
 | 
			
		||||
public class User {
 | 
			
		||||
    int uid;
 | 
			
		||||
    String name;
 | 
			
		||||
    String sex;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * ClassName: Book
 | 
			
		||||
     * Package: com.test.entity
 | 
			
		||||
     *
 | 
			
		||||
     * @author yovinchen
 | 
			
		||||
     * @Create 2023/8/14 17:01
 | 
			
		||||
     */
 | 
			
		||||
    @Data
 | 
			
		||||
    public static class Book {
 | 
			
		||||
        int bid;
 | 
			
		||||
        String title;
 | 
			
		||||
        String desc;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										67
									
								
								pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								pom.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,67 @@
 | 
			
		||||
<?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.7.14</version>
 | 
			
		||||
        <relativePath/> <!-- lookup parent from repository -->
 | 
			
		||||
    </parent>
 | 
			
		||||
    <groupId>com.example</groupId>
 | 
			
		||||
    <artifactId>SpringCloudStudy</artifactId>
 | 
			
		||||
    <version>0.0.1-SNAPSHOT</version>
 | 
			
		||||
    <packaging>pom</packaging>
 | 
			
		||||
    <name>SpringCloudStudy</name>
 | 
			
		||||
    <description>SpringCloudStudy</description>
 | 
			
		||||
    <modules>
 | 
			
		||||
        <module>user-service</module>
 | 
			
		||||
        <module>borrow-service</module>
 | 
			
		||||
        <module>book-service</module>
 | 
			
		||||
        <module>commons</module>
 | 
			
		||||
    </modules>
 | 
			
		||||
    <properties>
 | 
			
		||||
        <java.version>1.8</java.version>
 | 
			
		||||
    </properties>
 | 
			
		||||
    <dependencies>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.springframework.boot</groupId>
 | 
			
		||||
            <artifactId>spring-boot-starter</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.springframework.boot</groupId>
 | 
			
		||||
            <artifactId>spring-boot-starter-test</artifactId>
 | 
			
		||||
            <scope>test</scope>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.projectlombok</groupId>
 | 
			
		||||
            <artifactId>lombok</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.mysql</groupId>
 | 
			
		||||
            <artifactId>mysql-connector-j</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
    </dependencies>
 | 
			
		||||
    <dependencyManagement>
 | 
			
		||||
        <dependencies>
 | 
			
		||||
            <dependency>
 | 
			
		||||
                <groupId>org.mybatis.spring.boot</groupId>
 | 
			
		||||
                <artifactId>mybatis-spring-boot-starter</artifactId>
 | 
			
		||||
                <version>2.2.0</version>
 | 
			
		||||
            </dependency>
 | 
			
		||||
        </dependencies>
 | 
			
		||||
    </dependencyManagement>
 | 
			
		||||
    <build>
 | 
			
		||||
        <plugins>
 | 
			
		||||
            <plugin>
 | 
			
		||||
                <groupId>org.springframework.boot</groupId>
 | 
			
		||||
                <artifactId>spring-boot-maven-plugin</artifactId>
 | 
			
		||||
            </plugin>
 | 
			
		||||
        </plugins>
 | 
			
		||||
    </build>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
							
								
								
									
										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