-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"> | ||
<parent> | ||
<artifactId>cloud-demo</artifactId> | ||
<groupId>cn.itcast.demo</groupId> | ||
<version>1.0</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>order-service</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
</dependency> | ||
<!--mybatis--> | ||
<dependency> | ||
<groupId>org.mybatis.spring.boot</groupId> | ||
<artifactId>mybatis-spring-boot-starter</artifactId> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package cn.itcast.order; | ||
|
||
import org.mybatis.spring.annotation.MapperScan; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@MapperScan("cn.itcast.order.mapper") | ||
@SpringBootApplication | ||
public class OrderApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(OrderApplication.class, args); | ||
} | ||
|
||
@Bean | ||
public RestTemplate getRestTemplate () { | ||
return new RestTemplate(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cn.itcast.order.mapper; | ||
|
||
import cn.itcast.order.pojo.Order; | ||
import org.apache.ibatis.annotations.Select; | ||
|
||
public interface OrderMapper { | ||
|
||
@Select("select * from tb_order where id = #{id}") | ||
Order findById(Long id); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cn.itcast.order.pojo; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class Order { | ||
private Long id; | ||
private Long price; | ||
private String name; | ||
private Integer num; | ||
private Long userId; | ||
private User user; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cn.itcast.order.pojo; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class User { | ||
private Long id; | ||
private String username; | ||
private String address; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package cn.itcast.order.service; | ||
|
||
import cn.itcast.order.mapper.OrderMapper; | ||
import cn.itcast.order.pojo.Order; | ||
import cn.itcast.order.pojo.User; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Service | ||
public class OrderService { | ||
|
||
@Autowired | ||
private OrderMapper orderMapper; | ||
|
||
@Autowired | ||
private RestTemplate restTemplate; | ||
|
||
public Order queryOrderById(Long orderId) { | ||
// 1.查询订单 | ||
Order order = orderMapper.findById(orderId); | ||
String url = "http://localhost:8081/user/" + order.getUserId(); | ||
User user = restTemplate.getForObject(url, User.class); | ||
order.setUser(user); | ||
// 4.返回 | ||
return order; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cn.itcast.order.web; | ||
|
||
import cn.itcast.order.pojo.Order; | ||
import cn.itcast.order.service.OrderService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("order") | ||
public class OrderController { | ||
|
||
@Autowired | ||
private OrderService orderService; | ||
|
||
@GetMapping("{orderId}") | ||
public Order queryOrderByUserId(@PathVariable("orderId") Long orderId) { | ||
// 根据id查询订单并返回 | ||
return orderService.queryOrderById(orderId); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
server: | ||
port: 8080 | ||
spring: | ||
datasource: | ||
url: jdbc:mysql://localhost:3306/cloud_order?useSSL=false | ||
username: root | ||
password: 1234 | ||
driver-class-name: com.mysql.jdbc.Driver | ||
mybatis: | ||
type-aliases-package: cn.itcast.user.pojo | ||
configuration: | ||
map-underscore-to-camel-case: true | ||
logging: | ||
level: | ||
cn.itcast: debug | ||
pattern: | ||
dateformat: MM-dd HH:mm:ss:SSS |