自学实前后端践项目3 Spring Cloud微服务 2
创建服务提供者menu
数据库文件设计资料
-- MySQL dump 10.13 Distrib 8.0.11, for macos10.13 (x86_64)
--
-- Host: 127.0.0.1 Database: orderingsystem
-- ------------------------------------------------------
-- Server version 8.0.11
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
SET NAMES utf8mb4 ;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `t_admin`
--
DROP TABLE IF EXISTS `t_admin`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
SET character_set_client = utf8mb4 ;
CREATE TABLE `t_admin` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(11) DEFAULT NULL,
`password` varchar(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `t_admin`
--
LOCK TABLES `t_admin` WRITE;
/*!40000 ALTER TABLE `t_admin` DISABLE KEYS */;
INSERT INTO `t_admin` VALUES (1,'admin1','123123');
/*!40000 ALTER TABLE `t_admin` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `t_menu`
--
DROP TABLE IF EXISTS `t_menu`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
SET character_set_client = utf8mb4 ;
CREATE TABLE `t_menu` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(11) DEFAULT NULL,
`price` double DEFAULT NULL,
`flavor` varchar(11) DEFAULT NULL,
`tid` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `tid` (`tid`),
CONSTRAINT `t_menu_ibfk_1` FOREIGN KEY (`tid`) REFERENCES `t_type` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `t_menu`
--
LOCK TABLES `t_menu` WRITE;
/*!40000 ALTER TABLE `t_menu` DISABLE KEYS */;
INSERT INTO `t_menu` VALUES (1,'香酥鸡',39,'五香',1),(2,'烧椒扣肉',46,'微辣',1),(3,'栗子三杯鸡',56,'五香',1),(4,'毛血旺',50,'麻辣',1),(5,'菠菜拌粉丝',22,'五香',2),(6,'凉拌豆腐皮',19,'微辣',2),(7,'酱牛肉',36,'麻辣',2),(8,'鱼头豆腐汤',32,'五香',3),(9,'瘦肉鸡蛋白菜汤',30,'五香',3),(10,'西葫芦虾仁蒸饺',26,'五香',4),(11,'蛋炒饭',18,'五香',4),(12,'酥粒椰蓉面包',12,'香甜',5);
/*!40000 ALTER TABLE `t_menu` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `t_order`
--
DROP TABLE IF EXISTS `t_order`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
SET character_set_client = utf8mb4 ;
CREATE TABLE `t_order` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uid` int(11) DEFAULT NULL,
`mid` int(11) DEFAULT NULL,
`aid` int(11) DEFAULT NULL,
`date` date DEFAULT NULL,
`state` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `uid` (`uid`),
KEY `mid` (`mid`),
KEY `aid` (`aid`),
CONSTRAINT `t_order_ibfk_1` FOREIGN KEY (`uid`) REFERENCES `t_user` (`id`),
CONSTRAINT `t_order_ibfk_2` FOREIGN KEY (`mid`) REFERENCES `t_menu` (`id`),
CONSTRAINT `t_order_ibfk_3` FOREIGN KEY (`aid`) REFERENCES `t_admin` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `t_order`
--
LOCK TABLES `t_order` WRITE;
/*!40000 ALTER TABLE `t_order` DISABLE KEYS */;
INSERT INTO `t_order` VALUES (1,1,7,1,'2019-02-06',1),(2,1,2,1,'2019-02-06',1),(5,1,5,1,'2019-02-06',1),(6,1,9,1,'2019-02-06',1),(10,1,10,1,'2019-02-06',1),(11,1,10,NULL,'2019-02-06',0),(12,1,10,1,'2019-02-06',1),(14,1,6,1,'2019-02-06',1),(16,1,10,1,'2019-02-06',1),(19,1,7,1,'2019-02-07',1),(26,2,8,NULL,'2019-02-08',0),(27,2,12,NULL,'2019-02-08',0);
/*!40000 ALTER TABLE `t_order` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `t_type`
--
DROP TABLE IF EXISTS `t_type`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
SET character_set_client = utf8mb4 ;
CREATE TABLE `t_type` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `t_type`
--
LOCK TABLES `t_type` WRITE;
/*!40000 ALTER TABLE `t_type` DISABLE KEYS */;
INSERT INTO `t_type` VALUES (1,'热菜'),(2,'凉菜'),(3,'汤羹'),(4,'主食'),(5,'烘焙');
/*!40000 ALTER TABLE `t_type` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `t_user`
--
DROP TABLE IF EXISTS `t_user`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
SET character_set_client = utf8mb4 ;
CREATE TABLE `t_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(11) DEFAULT NULL,
`password` varchar(11) DEFAULT NULL,
`nickname` varchar(11) DEFAULT NULL,
`gender` varchar(2) DEFAULT NULL,
`telephone` varchar(20) DEFAULT NULL,
`registerdate` date DEFAULT NULL,
`address` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `t_user`
--
LOCK TABLES `t_user` WRITE;
/*!40000 ALTER TABLE `t_user` DISABLE KEYS */;
INSERT INTO `t_user` VALUES (1,'zhangsan','123123','张三','男','13576765678','2019-02-03','科技路'),(2,'lisi','123123','李四','女','18678987676','2019-02-03','科技路');
/*!40000 ALTER TABLE `t_user` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-02-12 16:02:37
创建menu并实现
pom.xml中编写相关依赖
<dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId><version>2.0.2.RELEASE</version></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>1.3.1</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.27</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-config</artifactId><version>2.0.2.RELEASE</version></dependency> </dependencies>
创建bootstrap.yml
先在shared里面创建
server:port: 8020 spring:application:name: menudatasource:name: orderingsystemurl: jdbc:mysql://localhost:3306/orderingsystem?useUnicode=true&characterEncoding=UTF-8username: rootpassword: rooteureka:client:service-url:defaultZone: http://localhost:8761/eureka/instance:prefer-ip-address: true
spring:application:name: menuprofiles:active: devcloud:config:uri: http://localhost:8762fail-fast: true
创建Handler启动类并测试
MenuApplication
package com.redhat;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication @MapperScan("com.redhat.repository")//自动扫描 public class MenuApplication {public static void main(String[] args) {SpringApplication.run(MenuApplication.class,args);} }
package com.redhat.controller;import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;@RestController @RequestMapping("/menu") public class MenuHandler {@Value("${server.port}")private String port;@GetMapping("/index")public String index(){return "menu的端口"+this.port;} } 最后和上面一样启动测试
8020显示成功
访问mean中获得数据表示成功
新建实体类menu
package com.redhat.entity;import lombok.Data;@Data public class Menu {private long id;private String name;private double price;private String flavor; } 创建MenuRepository接口
package com.redhat.repository;import com.redhat.entity.Menu;import java.util.List;public interface MenuRepository {public List<Menu>findAll();public int count();public Menu findById(long id);public void save(Menu menu);public void update(Menu menu);public void deleteById(long id); }
resources 路径下创建mapping文件夹,存放Mapper.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.redhat.repository.MenuRepository"><select id="findAll" resultType="com.redhat.entity.Menu">select*from t_menu limit #{param1},#{param2}</select><select id="count" resultType="int">select count(*) from t_menu;</select><insert id="save" parameterType="com.redhat.entity.Menu">insert into t_menu(name,price,flavor,tid) values(#{name},#{price},#{flavor},#{type.id})</insert><select id="findById" resultType="com.redhat.entity.Menu">select id mid,name mname,price,flavor,tid from t_menu where id = #{id}</select><update id="update" parameterType="com.redhat.entity.Menu">update t_menu set name = #{name},price = #{price},flavor = #{flavor},tid = #{type.id} where id = #{id}</update><delete id="deleteById" parameterType="long">delete from t_menu where id = #{id}</delete> </mapper>
创建menu MenuHandler
package com.redhat.controller;import com.redhat.entity.Menu; import com.redhat.repository.MenuRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; 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;import java.util.List;@RestController @RequestMapping("/menu") public class MenuHandler {@Value("${server.port}")private String port;@Autowiredprivate MenuRepository menuRepository;@GetMapping("/index")public String index(){return "menu的端口"+this.port;}@GetMapping("/findAll/{index}/{limit}")public List<Menu> findAll(@PathVariable("index") int index,@PathVariable("limit") int limit){return menuRepository.findAll(index, limit);} }在menu-dev.yml文件中加入最后两行
server:port: 8020 spring:application:name: menudatasource:name: orderingsystemurl: jdbc:mysql://localhost:3306/orderingsystem?useUnicode=true&characterEncoding=UTF-8username: rootpassword: 123456eureka:client:service-url:defaultZone: http://localhost:8761/eureka/instance:prefer-ip-address: true mybatis:mapper-locations: classpath:/mapping/*.xmltype-aliases-package: com.redhat.entity
重新启动管理层和menu层进行测试
查询0-10的所有菜品
自学实前后端践项目3 Spring Cloud微服务 2相关推荐
- 自学实前后端践项目3 Spring Cloud微服务 8
九.后台管理系统 1.前面基本上的功能都已经实现了,最后就行优化和界面管理! 1)过滤器接口实现直接访问主页面的时候需要先登录的功能 在client里面创建filter创建UserFilter 类然后 ...
- 自学实前后端践项目3 Spring Cloud微服务 6
六.服务消费者整合user 先添加两个前端: 链接:https://pan.baidu.com/s/1phn9ejGF_21Gp-WGJ9qsCA 提取码:ul6d 在User下创建封装VO pac ...
- 自学实前后端践项目3 Spring Cloud微服务 3
二.服务消费者整合menu 创建新的文件夹 创建服务消费者依赖 <dependencies><dependency><groupId>org.springframe ...
- 自学实前后端践项目2 phone Store 1
phone Store 基于移动端的手机 基于Spring Boot +Vue 前端技术栈 Vue+Vant UI +less 相关插件安装 npm i vant -S npm i axios -S ...
- 自学实前后端践项目4 MMall商城 1
一.开发环境 1.JDK8以上+Spring Boot 2.3.0+Thymeleaf+MyBatis Plus3.3.1+MySQL8.0+ 2.部署:Linux,,(阿里云 腾讯云)JDK8+,M ...
- 从天气项目看Spring Cloud微服务治理
网上搜集的资源,个人感觉还行,分享了 从天气项目看Spring Cloud微服务治理 网盘地址:https://pan.baidu.com/s/1ggn5uld 密码: n6bn 备用地址(腾讯微云) ...
- Servlet+MyBatis项目转Spring Cloud微服务,多数据源配置修改建议
一.项目需求 在开发过程中,由于技术的不断迭代,为了提高开发效率,需要对原有项目的架构做出相应的调整. 二.存在的问题 为了不影响项目进度,架构调整初期只是把项目做了简单的maven管理,引入spri ...
- Spring Cloud 微服务项目操作实战流程(完结)
Spring Cloud入门项目操作实战流程 Day01~02 〇.Service - 业务服务结构 商品服务 item service,端口 8001 用户服务 user service,端口 81 ...
- Java之 Spring Cloud 微服务的 SpringCloud Config 配置中心(第四个阶段)【二】【SpringBoot项目实现商品服务器端调用】
SpringCloud学习目录点击跳转对应的文章 Java之 Spring Cloud 微服务搭建(第一个阶段)[一][SpringBoot项目实现商品服务器端是调用] Java之 Spring Cl ...
最新文章
- 条件随机场 (CRF) 分词序列谈之一(转)
- [React Router v4] Conditionally Render a Route with the Switch Component
- 利用锁分析器进行线程竞争检测
- 从事 Java 20 年最终却败给了 Python,哭了!
- 华为6p连接计算机设置在哪里设置密码,华为路由器和华为手机如何不用密码连接...
- 左边导航条动态增加或缩短高度以及放大缩小问题的解决方法
- Fdfs环境搭建及整合Java
- vue中组件的父子关系
- 计算机标点符号怎么切换,标点符号转换键是什么?
- php+chmod+r,从今往后,谁再告诉你Linux上chmod -R 777解决权限,果断绝交
- Kali Linux实战:如何一下看出Windows计算机是否开启445危险端口?是否存在永恒之蓝漏洞?
- android开发面试题!微信小程序趋势及前景,社招面试心得
- eclipse官方下载32位和64位的具体步骤
- windows如何创建计划任务并在窗口界面隐藏运行
- 算法:URL短地址压缩算法-短网址映射。
- Idea中GsonFormat插件安装
- 以太坊学习路线——(二、下)以太坊编程接口:web3.js
- java编一个漏斗_java – 漏斗分析计算,你如何计算漏斗?
- ubuntu中把软件放在桌面
- 【若依(ruoyi)】summernote富文本编辑器的使用