springboot实战—BMI体脂计算器-客户端
1.用angular新建一个bmi2工程客户端
具体步骤:https://blog.csdn.net/hyh17808770899/article/details/105641632
2.用JetBrains WebStorm打开该项目
具体步骤:https://blog.csdn.net/hyh17808770899/article/details/105645198
3.替换tslint.json文件
将tslint.json文件里面的代码全部换成如下代码:
{"parserOptions": {"ecmaVersion": 6,"sourceType": "module","ecmaFeatures": {"jsx": true}},"env": {"browser": true,"node": true,"commonjs": true,"meteor": true,"mongo": true,"jquery": true,"amd": true},"globals": {},"rules": {"comma-dangle": [2, "never"],"no-cond-assign": [2],"no-constant-condition": [2],"no-control-regex": [2],"no-debugger": [2],"no-dupe-args": [2],"no-dupe-keys": [2],"no-duplicate-case": [2],"no-empty-character-class": [2],"no-empty": [2],"no-ex-assign": [2],"no-extra-boolean-cast": [2],"no-func-assign": [2],"no-inner-declarations": [2],"no-invalid-regexp": [2],"no-irregular-whitespace": [2],"no-negated-in-lhs": [2],"no-obj-calls": [2],"no-regex-spaces": [2],"no-sparse-arrays": [2],"no-unexpected-multiline": [2],"no-unreachable": [2],"use-isnan": [2],"no-octal": [2],"no-empty-pattern": [2],"no-multi-spaces": [2],"no-unused-labels": [1],"no-void": [2],"semi": [2, "always"],"quotes": [2, "single"],"strict": [2, "safe"],"dot-location": [2, "property"],"no-label-var": [2],"no-shadow-restricted-names": [2],"no-undef": [2],"init-declarations": [2, "always"],"no-catch-shadow": [2],"no-delete-var": [2],"constructor-super": [1],"no-const-assign": [2],"no-dupe-class-members": [2],"no-new-symbol": [2],"no-this-before-super": [2],"no-class-assign": [2]}
}
4.现在才正式开始
打开IDEA,运行BMI的服务端
用Postman测试:
一切正常的话,开始在WebStorm里面的src/app目录里的app.component.html
文件内添加代码:
<h1>BMI计算器</h1><label>身高:</label>
<input type="text"><br><label>体重:</label>
<input type="text"><br><button>计算</button>
Terminal终端运行:ng serve
浏览器查看效果:
(1)app.module.ts文件中的imports: []添加路由FormsModule
(2)src/app目录中添加文件夹vo,vo中新建TypeScript file文件,命名BMIForm
添加代码:
export class BMIForm{public sg:number;public tz:number;
}
(3)app.component.ts文件中的export class AppComponent {}
添加:
bmiform:BMIForm;constructor(){this.bmiform=new BMIForm();}
(4)修改app.component.html
文件
<h1>BMI计算器</h1><label>身高:</label>
<input type="text" [(ngModel)]="bmiform.sg"><br><label>体重:</label>
<input type="text" [(ngModel)]="bmiform.tz"><br><button>计算</button><div><br>你的身高是: {{ bmiform.sg }}<br>你的体重是: {{ bmiform.tz }}
</div>
(5)浏览器刷新一下看看效果
(6)vo目录下新建TypeScript file文件,命名ResultVo
添加代码:
export class ResultVo{public value:number;public state:string;public suggest:string;
}
(7)app.component.ts文件中的export class AppComponent {}
添加:
resultvo:ResultVo;
constructor(){}中添加:
this.resultvo=new ResultVo();
5.连接客户端
(1)创建service
Terminal终端Ctrl+C终止运行,使用命令创建service
ng g service service/bmi
(2)app.module.ts文件中的imports: []添加路由HttpClientModule
(3)新建的service服务中bmi.service.ts文件中添加代码,使其访问服务端:
import { Injectable } from '@angular/core';
import {BMIForm} from '../vo/BMIForm';
import {HttpClient} from '@angular/common/http';@Injectable({providedIn: 'root'
})
export class BmiService {constructor(private http:HttpClient) { }private getBMIValueUrl="http://localhost:8080/getBMIValue";getBMIValue(bmiform:BMIForm){return this.http.post(this.getBMIValueUrl,bmiform).toPromise();}
}
6.添加计算结果
(1)app.component.ts
添加代码:
getBMIValue(){console.log("身高"+this.bmiform.sg+"体重"+this.bmiform.tz);}
(2)app.component.html
中为Button添加点击事件(click)="getBMIValue()"
<button (click)="getBMIValue()" >计算</button>
(3)ng serve
命令运行,打开浏览器的开发者工具查看
(4)app.component.ts
的constructor()中添加代码:private bmiservice:BmiService
constructor(private bmiservice:BmiService){this.bmiform=new BMIForm();this.resultvo=new ResultVo();}
getBMIValue(){}中添加代码
this.bmiservice.getBMIValue(this.bmiform).then((data:any)=>{console.dir(data);})
(5)在服务端(IDEA)中的PublicAction.java文件中开头的@RestController
下一行添加代码@CrossOrigin
,然后重新运行Main
(6)浏览器刷新一下,测试结果
(7)app.component.ts
文件里面getBMIValue(){}
中的console.dir(data);
改为this.resultvo=data;
(8)app.component.html
文件添加代码
<div>
<p>你的BMI值是: {{resultvo.value}}</p>
<p>你的BMI结果: {{resultvo.state}}</p>
<p>你的BMI建议: {{resultvo.suggest}}</p>
</div>
(9)再次刷新浏览器,查看结果
7.添加图片
(1)src/assets目录下新建images文件夹,将需要的图片放入其中
(2)app.component.ts文件中的export class AppComponent {}
添加:
imgeurl:string;
(3)app.component.ts文件中添加:
getPic(){switch (this.resultvo.state){case "偏瘦":this.imgeurl="/assets/images/thin.jpg";break;case "正常":this.imgeurl="/assets/images/normal.jpg";break;case "微胖":this.imgeurl="/assets/images/babyfat.jpg";break;case "肥胖":this.imgeurl="/assets/images/fat.jpg";break;}}
(4)app.component.ts
文件里面getBMIValue(){}
中添加调用
this.getPic();
(5)app.component.html
文件添加代码用于显示图片
<img src="{{imgeurl}}" width="400px" height="400px"/>
(6)刷新浏览器查看效果
完成了,哇哈哈
springboot实战—BMI体脂计算器-客户端相关推荐
- springboot实战—BMI体脂计算器-服务器端
BMI计算器的最终效果: 哈哈,土不拉几的,还是下面的好看: BMI值計算公式: BMI = 体重(公斤) / 身高2(公尺2) 1.新建bmi工程服务端 具体步骤:https://blog.csdn ...
- Android之BMI体脂计算器
Android之BMI体脂计算器 MainActivity package com.example.graceto.shiyan3;import android.content.Intent; imp ...
- java基础题:使用if嵌套编写简易体脂计算器
public static void main(String[] args) {Scanner input = new Scanner(System.in);System.out.print(&quo ...
- bmi系统模块设计java_BMI体脂计算器 app源码
该实例较为简单,可供参考. [实例截图] [核心代码] package com.example.administrator.bmii; import android.content.Intent; i ...
- 用计算机算出用不用减肥,体脂率计算器有什么用
我们在健身房进行体检的时候,都会有一个项目叫做体脂率,现在网上也有很多体脂率计算器,只要输入自己的身高和体重就可以自动计算出体内的体脂率.体脂率是有一个标准的偏瘦和偏胖,都会有相关的体脂率值范围.很多 ...
- Springboot实战:Springboot+Netty优雅的创建websocket客户端 (附源码下载)
Springboot-cli 开发脚手架系列 Netty系列:Springboot+Netty优雅的创建websocket客户端 (附源码下载) 文章目录 Springboot-cli 开发脚手架系列 ...
- 云麦体脂秤华为体脂秤_华为、小米和有品体脂秤哪个品牌好?三款智能体脂秤横评结果排行...
如今生活水平的提高,也让更多人开始关注健康问题.由于大部分时间都忙于工作,本身就运动少.体重超标等等.如果长期得不到控制的话,会造成日后脂性肝炎.肝纤维化.肝癌,想想都可怕,在意识到这样的严重性,不得 ...
- 怎么用计算机测出来体脂,如何简单测算出自己的体脂率?
原标题:如何简单测算出自己的体脂率? 想了解自己是否肥胖,必须从掌握你的体脂率(BFR,Body Fat Ratio)开始,它是了解身体脂肪含量的一个重要指数. 什么是"体脂率"? ...
- wifi卡慢延迟高_健康生活好助手:华为智能体脂秤 WiFi 版 体验评测
点击右上角关注我们,每天给您带来最新最潮的科技资讯,让您足不出户也知道科技圈大事! 为了让自己严格执行减肥计划,一台体脂秤是肯定少不了的,只有时刻记住那个沉重的数字,管住嘴.迈开腿才会有动力. 不过随 ...
最新文章
- 44种模型、1200种子网,RobustART评测CNN、Transformer、MLP-Mixer谁最鲁棒?
- 如何获取微信openId
- python3 乱序函数 shuffle 简介
- LNMP安装目录及配置文件位置
- Mysql日期差函数,Mysql选择两个日期字段相差大于或小于一定时间
- python3利用smtplib通过qq邮箱发送邮件
- Tomcat 总体结构
- Linux 之目录 -鸟哥的Linux私房菜
- 4.RabbitMQ Linux安装
- C#面向对象名词比较
- @property and @synthesize区别
- linux c++ 实现http请求
- 机器学习—XGboost的原理、工程实现与优缺点
- MySQL的约束、事务、字符串、日期、数学相关及其他补充
- 特殊Office Communicator 2007 R2 Outlook集成错误
- ★★★HEU_KMS_Activator_v7.5 (附详细说明文档)
- 随机数生成器Random类
- table总结insertRow、deleteRow 学习
- 华为云服务器最新信息,查询云主机信息
- IEEE浮点数尾数向偶舍入-四舍六入五成双