使用angular4和asp.net core 2 web api做個練習項目(二), 這部分都是angular

上一篇:?http://www.cnblogs.com/cgzl/p/7755801.html

完成client.service.ts:

import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { ErrorHandler } from '@angular/core';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';import { Client } from '../models/Client';@Injectable()
export class ClientService {private url = 'http://localhost:5001/api/client';private headers = new Headers({ 'Content-Type': 'application/json' });constructor(private http: Http) { }getAll(): Observable<Client[]> {return this.http.get(this.url).map(response => response.json() as Client[]);}getOne(id: number): Observable<Client> {return this.http.get(`${this.url}/${id}`).map(response => response.json() as Client);}create(client: Client) {return this.http.post(this.url, JSON.stringify(client), { headers: this.headers }).map(response => response.json()).catch(this.handleError);}update(client: Client) {return this.http.patch(`${this.url}/${client.id}`, JSON.stringify(client), { headers: this.headers }).map(response => response.json()).catch(this.handleError);}delete(id: number) {return this.http.delete(`${this.url}/${id}`).map(response => response.json()).catch(this.handleError);}private handleError(error: Response) {if (error.status === 400) {return Observable.throw('Bad Request');}if (error.status === 404) {return Observable.throw('Not Found');}return Observable.throw('Error Occurred');}
}

我個人比較喜歡 observable的方式而不是promise.

然后再Client.Component里面, 注入ClientService, 在NgOnInit里面調用查詢方法:

import { Component, OnInit } from '@angular/core';
import { ClientService } from '../../services/client.service';
import { Client } from '../../models/Client';@Component({selector: 'app-clients',templateUrl: './clients.component.html',styleUrls: ['./clients.component.css']
})
export class ClientsComponent implements OnInit {public clients: Client[];constructor(private service: ClientService) { }ngOnInit() {this.service.getAll().subscribe(clients => {this.clients = clients;console.log(this.clients);});}
}

然后修改Client.Component.html:

<table class="table table-striped" *ngIf="clients?.length > 0; else noClients"><thead class="thead-dark"><tr><th>ID</th><th>Name</th><th>Email</th><th>Balance</th><th></th></tr></thead><tbody><tr *ngFor="let client of clients"><td>{{client.id}}</td><td>{{client.firstName + ' ' + client.lastName}}</td><td>{{client.email}}</td><td>{{client.balance}}</td><td><a href="" class="btn btn-secondary btn-sm">明細</a></td></tr></tbody>
</table>
<ng-template #noClients><hr><h5>系統中沒有客戶..</h5>
</ng-template>

然后把client.component放在dashboard中:

dashboard.component.html:

<app-clients></app-clients>

然后看看瀏覽器:

我這里還沒有數據, 如果有數據的話, 將會顯示一個table, header是黑色的.

使用font-awesome

npm install font-awesome --save

然后打開.angular-cli.json:

      "styles": ["styles.css","../node_modules/bootstrap/dist/css/bootstrap.css","../node_modules/font-awesome/css/font-awesome.css"],"scripts": ["../node_modules/jquery/dist/jquery.js","../node_modules/tether/dist/js/tether.js","../node_modules/bootstrap/dist/js/bootstrap.bundle.js"]

重新運行ng serve

修改 client.component.html的明細按鈕:

<td><a href="" class="btn btn-secondary btn-sm"><i class="fa fa-arrow-circle-o-right"></i> 明細</a></td>

然后還是使用swagger添加兩條數據吧: http://localhost:5001/swagger, 現在的效果:

添加一個總計:

import { Component, OnInit } from '@angular/core';
import { ClientService } from '../../services/client.service';
import { Client } from '../../models/Client';@Component({selector: 'app-clients',templateUrl: './clients.component.html',styleUrls: ['./clients.component.css']
})
export class ClientsComponent implements OnInit {public clients: Client[];public total: number;constructor(private service: ClientService) { }ngOnInit() {this.service.getAll().subscribe(clients => {this.clients = clients;this.getTotal();});}getTotal() {this.total = this.clients.reduce((previous, current) => previous + current.balance, 0);}
}

html:

<div class="row"><div class="col-md-6"><h2><i class="fa fa-users">客戶</i></h2></div><div class="col-md-6"><h5 class="pull-right text-muted">總計: {{total | currency:"USD":true}}</h5></div>
</div>
<table class="table table-striped" *ngIf="clients?.length > 0; else noClients"><thead class="thead-dark"><tr><th>ID</th><th>Name</th><th>Email</th><th>Balance</th><th></th></tr></thead><tbody><tr *ngFor="let client of clients"><td>{{client.id}}</td><td>{{client.firstName + ' ' + client.lastName}}</td><td>{{client.email}}</td><td>{{client.balance}}</td><td><a href="" class="btn btn-secondary btn-sm"><i class="fa fa-arrow-circle-o-right"></i> 明細</a></td></tr></tbody>
</table>
<ng-template #noClients><hr><h5>系統中沒有客戶..</h5>
</ng-template>

Sidebar 側邊欄

打開sidebar.component.html:

<a routerLink="/add-client" href="#" class="btn btn-success btn-block"><i class="fa fa-plus"></i>添加新客戶</a>

然后再dashboard中添加sidebar:

<div class="row"><div class="col-md-10"><app-clients></app-clients></div><div class="col-md-2"><app-sidebar></app-sidebar></div>
</div>

添加在了右邊. 效果如圖:

然后需要在app.module.ts里面添加路由:

const appRoutes: Routes = [{ path: '', component: DashboardComponent },{ path: 'register', component: RegisterComponent },{ path: 'login', component: LoginComponent },{ path: 'add-client', component: AddClientComponent }
];

Add-Client 添加客戶的表單:

打開add-client.component.html:

<div class="row"><div class="col-md-6"><a routerLink="/" href="#" class="btn btn-link"><i class="fa fa-arrow-circle-o-left"></i> 回到Dashboard </a></div><div class="col-md-6"></div>
</div><div class="card"><div class="card-header">Add Client</div><div class="card-body"><form #f="ngForm" (ngSubmit)="onSubmit(f)"><div class="form-group"><label for="firstName"></label><input type="text" class="form-control" [(ngModel)]="client.firstName"name="firstName"#clientFirstName="ngModel"minlength="2"required><div *ngIf="clientFirstName.errors.required && clientFirstName.touched" class="alter alert-danger">名字是必填的</div><div *ngIf="clientFirstName.errors.minlength && clientFirstName.touched" class="alter alert-danger">名字最少是兩個字</div></div></form></div>
</div>

現在表單里面添加一個字段, 然后在app.module里面添加FormsModule:

import { FormsModule } from '@angular/forms';imports: [BrowserModule,RouterModule.forRoot(appRoutes),HttpModule,
    FormsModule],

現在應該是這個樣子:

然后把表單都完成 add-client.component.html:

<div class="row"><div class="col-md-6"><a routerLink="/" href="#" class="btn btn-link"><i class="fa fa-arrow-circle-o-left"></i> 回到Dashboard </a></div><div class="col-md-6"></div>
</div><div class="card"><div class="card-header">添加客戶</div><div class="card-body"><form #f="ngForm" (ngSubmit)="onSubmit(f)" novalidate><div class="form-group"><label for="firstName"></label><input type="text" class="form-control" [(ngModel)]="client.firstName" name="firstName" #clientFirstName="ngModel" minlength="2"required><div *ngIf="clientFirstName.touched && clientFirstName.invalid"><div *ngIf="clientFirstName.errors.required" class="alert alert-danger">名字是必填的</div><div *ngIf="clientFirstName.errors.minlength" class="alert alert-danger">名字最少是兩個字</div></div></div><div class="form-group"><label for="lastName"></label><input type="text" class="form-control" [(ngModel)]="client.lastName" name="lastName" #clientLastName="ngModel" minlength="2"required><div *ngIf="clientLastName.touched && clientLastName.invalid"><div *ngIf="clientLastName.errors.required" class="alert alert-danger">姓是必填的</div><div *ngIf="clientLastName.errors.minlength" class="alert alert-danger">姓最少是兩個字</div></div></div><div class="form-group"><label for="email">Email</label><input type="email" class="form-control" [(ngModel)]="client.email" name="email" #clientEmail="ngModel" required><div *ngIf="clientEmail.touched && clientEmail.invalid"><div *ngIf="clientEmail.errors.required" class="alert alert-danger">Email是必填的</div></div></div><div class="form-group"><label for="phone">聯系電話</label><input type="text" class="form-control" [(ngModel)]="client.phone" name="phone" #clientPhone="ngModel" minlength="10"><div *ngIf="clientPhone.touched && clientPhone.invalid"><div *ngIf="clientPhone.errors.minlength" class="alert alert-danger">電話最少是10位</div></div></div><div class="form-group"><label for="balance">余額</label><input type="number" class="form-control" [(ngModel)]="client.balance" name="balance" #clientBalance="ngModel" [disabled]="disableBalanceOnAdd"></div><input type="submit" class="btn btn-primary btn-block" value="提交"></form></div>
</div>

現在看起來是這樣:

再安裝一個庫:?npm install --save angular2-flash-messages

這個庫可以略微靈活的顯示提示信息.

npm install --save angular2-flash-messages

在app.module里面:

import { FlashMessagesModule } from 'angular2-flash-messages';imports: [BrowserModule,RouterModule.forRoot(appRoutes),HttpModule,FormsModule,
    FlashMessagesModule],

add-client.component.ts:

import { Component, OnInit } from '@angular/core';
import { FlashMessagesService } from 'angular2-flash-messages';
import { Router } from '@angular/router';
import { Client } from '../../models/Client';@Component({selector: 'app-add-client',templateUrl: './add-client.component.html',styleUrls: ['./add-client.component.css']
})
export class AddClientComponent implements OnInit {public client: Client = {id: 0,firstName: '',lastName: '',email: '',phone: '',balance: 0};public disableBalanceOnAdd = true;constructor(public flashMessagesService: FlashMessagesService,public router: Router) { }ngOnInit() {}onSubmit({ value, valid }: { value: Client, valid: boolean }) {if (!valid) {this.flashMessagesService.show('請正確輸入表單', { cssClass: 'alert alert-danger', timeout: 4000 });this.router.navigate(['/add-client']);} else {console.log('valid');}}
}

然后需要在某個地方放置flash messages, 打開app.component.html:

<app-navbar></app-navbar>
<div class="container"><flash-messages></flash-messages><router-outlet></router-outlet>
</div>

然后運行一下:

大約這個樣子.

然后修改提交, 注入clientService, 把數據新增到web api:

import { Component, OnInit } from '@angular/core';
import { FlashMessagesService } from 'angular2-flash-messages';
import { Router } from '@angular/router';
import { Client } from '../../models/Client';
import { ClientService } from '../../services/client.service';@Component({selector: 'app-add-client',templateUrl: './add-client.component.html',styleUrls: ['./add-client.component.css']
})
export class AddClientComponent implements OnInit {public client: Client = {id: 0,firstName: '',lastName: '',email: '',phone: '',balance: 0};public disableBalanceOnAdd = true;constructor(public flashMessagesService: FlashMessagesService,public router: Router,public clientService: ClientService) { }ngOnInit() {}onSubmit({ value, valid }: { value: Client, valid: boolean }) {if (this.disableBalanceOnAdd) {value.balance = 0;}if (!valid) {this.flashMessagesService.show('請正確輸入表單', { cssClass: 'alert alert-danger', timeout: 4000 });this.router.navigate(['/add-client']);} else {this.clientService.create(value).subscribe(client => {console.log(client);this.flashMessagesService.show('新客戶添加成功', { cssClass: 'alert alert-success', timeout: 4000 });this.router.navigate(['/']);});}}
}

可以運行試試. 應該是好用的.

Client Detail 客戶明細:

首先在app.module.ts里面添加路由:

const appRoutes: Routes = [{ path: '', component: DashboardComponent },{ path: 'register', component: RegisterComponent },{ path: 'login', component: LoginComponent },{ path: 'add-client', component: AddClientComponent },{ path: 'client/:id', component: ClientDetailsComponent }
];

然后在clients.componet.html修改:

      <td><a href="" [routerLink]="['/client', client.id]" class="btn btn-secondary btn-sm"><i class="fa fa-arrow-circle-o-right"></i> 明細</a></td>

修改client-detail.component.ts:

import { Component, OnInit } from '@angular/core';
import { ClientService } from '../../services/client.service';
import { FlashMessagesService } from 'angular2-flash-messages';
import { Router, ActivatedRoute, Params } from '@angular/router';
import { Client } from '../../models/Client';@Component({selector: 'app-client-details',templateUrl: './client-details.component.html',styleUrls: ['./client-details.component.css']
})
export class ClientDetailsComponent implements OnInit {id: string;client: Client;hasBalance = false;showBalanceUpdateInput = false;constructor(public clientService: ClientService,public router: Router,public route: ActivatedRoute,public flashMessagesService: FlashMessagesService) { }ngOnInit() {// 獲取IDthis.id = this.route.snapshot.params['id'];// 獲取Clientthis.clientService.getOne(+this.id).subscribe(client => {if (client.balance > 0) {this.hasBalance = true;}this.client = client;});}}

然后修改html:

<div class="row"><div class="col-md-6"><a routerLink="/" class="btn btn-link"><i class="fa fa-arrow-circle-o-left"></i> 回到Dashboard</a></div><div class="col-md-6"><div class="btn-group pull-right"><a [routerLink]="['/edit-client', id]" class="btn btn-secondary">編輯</a><button type="button" class="btn btn-danger" (click)="onDeleteClick()">刪除</button></div></div>
</div>
<hr>
<div class="card" *ngIf="client"><div class="card-header"><h3> {{client.firstName + ' ' + client.lastName}}</h3></div><div class="card-body"><div class="row"><div class="col-md-8"><h4>客戶ID: {{id}}</h4></div><div class="col-md-4"><h4 class="pull-right">余額:<span [class.text-danger]="!hasBalance" [class.text-success]="hasBalance">{{client.balance | currency: 'USD': true}}</span><small><a (click)="showBalanceUpdateInput = !showBalanceUpdateInput"><i class="fa fa-pencil"></i></a></small></h4><div class="clearfix"><form *ngIf="showBalanceUpdateInput" (submit)="updateBalance(id)" class="form-inline pull-right"><div class="form-group"><input type="number" class="form-control" name="balance" [(ngModel)]="client.balance"></div><button type="submit" class="btn btn-primary">更新</button></form></div></div></div><hr><ul class="list-group"><li class="list-group-item">Email: {{client.email}}</li><li class="list-group-item">聯系電話: {{client.phone}}</li></ul></div>
</div>

然后要做一個修改余額的動作, 這是個部分更新, 應該對應http patch.

目前client.service里沒有patch, 所以需要添加一個patch方法, 不過首先建立一個PatchModel.ts:.

export interface PatchModel {op: string;path: string;value: any;
}

client.service.ts:

import { PatchModel } from '../models/PatchModel';patch(id: number, patchs: PatchModel[]) {return this.http.patch(`${this.url}/${id}`, JSON.stringify(patchs), { headers: this.headers }).map(response => response.json()).catch(this.handleError);}

然后修改 client-detail.component.ts:

import { PatchModel } from '../../models/PatchModel';updateBalance(id: string) {// 更新客戶的余額this.clientService.patch(+id, [{ op: 'replace', path: '/balance', value: this.client.balance }]).subscribe(() => {this.showBalanceUpdateInput = false;this.flashMessagesService.show('更新余額成功', { cssClass: 'alert alert-success', timeout: 4000 });});}

運行一下, 應該好用:

刪除動作:

  onDeleteClick() {if (confirm('確定要刪除?')) {this.clientService.delete(+this.id).subscribe(() => {this.flashMessagesService.show('客戶刪除成功', { cssClass: 'alert alert-success', timeout: 4000 });this.router.navigate(['/']);});}}

應該好用, 刪除后跳轉到dashboard.

編輯客戶 Edit-Client

?先添加路由 app.module.ts:

const appRoutes: Routes = [{ path: '', component: DashboardComponent },{ path: 'register', component: RegisterComponent },{ path: 'login', component: LoginComponent },{ path: 'add-client', component: AddClientComponent },{ path: 'client/:id', component: ClientDetailsComponent },
  { path: 'edit-client/:id', component: EditClientComponent }
];

然后修改edit-client.component.html:

<div class="row"><div class="col-md-6"><a [routerLink]="['/client', id]" href="#" class="btn btn-link"><i class="fa fa-arrow-circle-o-left"></i> 回到客戶明細 </a></div><div class="col-md-6"></div></div><div class="card"><div class="card-header">編輯客戶</div><div class="card-body"><form #f="ngForm" (ngSubmit)="onSubmit(f)" *ngIf="client" novalidate><div class="form-group"><label for="firstName"></label><input type="text" class="form-control" [(ngModel)]="client.firstName" name="firstName" #clientFirstName="ngModel" minlength="2"required><div *ngIf="clientFirstName.touched && clientFirstName.invalid"><div *ngIf="clientFirstName.errors.required" class="alert alert-danger">名字是必填的</div><div *ngIf="clientFirstName.errors.minlength" class="alert alert-danger">名字最少是兩個字</div></div></div><div class="form-group"><label for="lastName"></label><input type="text" class="form-control" [(ngModel)]="client.lastName" name="lastName" #clientLastName="ngModel" minlength="2"required><div *ngIf="clientLastName.touched && clientLastName.invalid"><div *ngIf="clientLastName.errors.required" class="alert alert-danger">姓是必填的</div><div *ngIf="clientLastName.errors.minlength" class="alert alert-danger">姓最少是兩個字</div></div></div><div class="form-group"><label for="email">Email</label><input type="email" class="form-control" [(ngModel)]="client.email" name="email" #clientEmail="ngModel" required><div *ngIf="clientEmail.touched && clientEmail.invalid"><div *ngIf="clientEmail.errors.required" class="alert alert-danger">Email是必填的</div></div></div><div class="form-group"><label for="phone">聯系電話</label><input type="text" class="form-control" [(ngModel)]="client.phone" name="phone" #clientPhone="ngModel" minlength="10"><div *ngIf="clientPhone.touched && clientPhone.invalid"><div *ngIf="clientPhone.errors.minlength" class="alert alert-danger">電話最少是10位</div></div></div><div class="form-group"><label for="balance">余額</label><input type="number" class="form-control" [(ngModel)]="client.balance" name="balance" #clientBalance="ngModel" [disabled]="disableBalanceOnEdit"></div><input type="submit" class="btn btn-primary btn-block" value="提交"></form></div></div>

修改edit-client.component.ts:

import { Component, OnInit } from '@angular/core';
import { ClientService } from '../../services/client.service';
import { FlashMessagesService } from 'angular2-flash-messages';
import { Router, ActivatedRoute, Params } from '@angular/router';
import { Client } from '../../models/Client';@Component({selector: 'app-edit-client',templateUrl: './edit-client.component.html',styleUrls: ['./edit-client.component.css']
})
export class EditClientComponent implements OnInit {id: string;client: Client;disableBalanceOnEdit = true;constructor(public clientService: ClientService,public router: Router,public route: ActivatedRoute,public flashMessagesService: FlashMessagesService) { }ngOnInit() {// 獲取IDthis.id = this.route.snapshot.params['id'];// 獲取Clientthis.clientService.getOne(+this.id).subscribe(client => {this.client = client;});}onSubmit({ value, valid }: { value: Client, valid: boolean }) {if (!valid) {this.flashMessagesService.show('請正確輸入表單', { cssClass: 'alert alert-danger', timeout: 4000 });this.router.navigate(['/edit-client', this.id]);} else {this.clientService.update(+this.id, value).subscribe(client => {console.log(client);this.flashMessagesService.show('更新客戶成功', { cssClass: 'alert alert-success', timeout: 4000 });this.router.navigate(['/client', this.id]);});}}
}

client.service.ts需要修改一下, 之前的update方法寫的不正確也不符合規范:

  update(id: number, client: Client) {return this.http.put(`${this.url}/${id}`, JSON.stringify(client), { headers: this.headers }).map(response => response.json()).catch(this.handleError);}

然后運行, 好用.

先寫到這, 估計還得寫一篇, 下一篇文章里面要使用identity server 4了, implicit grant flow.

轉載于:https://www.cnblogs.com/cgzl/p/7763397.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/454168.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/454168.shtml
英文地址,請注明出處:http://en.pswp.cn/news/454168.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

leelen可視對講怎么接線_樓宇對講系統怎么布線 樓宇對講系統布線方式【介紹】...

隨著智能小區規模不斷增加&#xff0c;樓宇可視對講系統應用越來越廣泛&#xff0c;因而視頻信號的傳輸方式與布線設計顯得越來越重要。視頻信號與數據和音頻信號不同&#xff0c;可行的一種傳輸方式為視頻信號基帶傳輸&#xff0c;下面小編就簡要介紹一下這種傳輸方式和布線方…

路由匯總實例

5.2.2.2 路由匯總策略 之前提到過&#xff0c;在網絡管理員計劃好子網選擇并進行預期地路由匯總時&#xff0c;手動路由匯總工作能取得最佳效果。例如&#xff0c;之前的例子設定好了一個考慮周全的計劃&#xff0c;管理員只使用遠離Yosemite路由器并以10.2開頭的子網。這個規定…

《操作系統》OS學習(五):連續內存分配 內存碎片、動態分配、碎片整理、伙伴系統

內存碎片 在沒有其他方式輔助的情況下&#xff0c;我們分配給一個進程的內存是連續的。在分配時候我們需要有動態分配與碎片處理。如何理解呢&#xff1f;就是每個進程需要一塊內存&#xff0c;我們要選取合適的位置的內存分配給它。當有的進程先結束了內存還給操作系統&#…

GCC 中文手冊 - 摘自純C論壇

GCC Section: GNU Tools (1) Updated: 2003/12/05 Index Return to Main Contents NAME gcc,g-GNU工程的C和C編譯器(egcs-1.1.2) 總覽(SYNOPSIS) gcc[option|filename ]... g[option|filename ]... 警告(WARNING) 本手冊頁內容摘自GNU C編譯器的完整文檔,僅限于解釋選項的含義…

python如何實現支持中文

#codingutf-8print("我要python支持中文") 默認情況下&#xff0c;python是不支持中文的。 如果要實現python支持中文&#xff08;我是從python3.6開始學習的&#xff09;&#xff0c;只要在python文檔的開頭加入&#xff1a;“#codingutf-8"就可以了。轉載于:h…

世界之窗瀏覽器刪除文本框信息_文本框——Excel里的便利貼

工作表里面的單元格應該是足夠我們來記錄數據和信息了。但是文本框這個功能在工作表中還是存在&#xff0c;可以理解為便利貼功能。插入文本框1.點擊“插入”選項卡。2.然后點擊“文本框”。3.在下拉菜單里面&#xff0c;有兩種可供選擇&#xff1a;橫排文本框和垂直文本框。在…

RHEL 5服務篇—常用網絡配置命令

常用網絡配置命令 在“Linux系統管理”的文章中&#xff0c;大家已經學習了Linux系統的基本管理命令和技巧&#xff0c;為了進一步學習Linux網絡服務打下了良好的基礎。所以我作者以后將陸續推出Linux網絡服務的相關文章。希望大家能給與我大大的支持。 今天我們就來學習一下…

清華大學《操作系統》(六):非連續內存分配 段式、頁式、段頁式存儲管理

背景 連續內存分配給內存分配帶來了很多不便&#xff0c;可能所有空閑片區大小都無法滿足需求大小&#xff0c;這個分配就會失敗。基于這種現狀&#xff0c;就有了非連續內存分配的需求。非連續分配成功的幾率更高&#xff0c;但也面對更多的問題&#xff0c;比如分配時是不是…

python監控文件內容變化_Python監控文件內容變化

{"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],"search_count":[{"count_phone":4,"count":4}]},"card":[{"des":"阿里云文件存儲NAS是一個可共享訪問&#xf…

C語言第三次博客作業---單層循環結構

一、PTA實驗作業。 題目1 1.實驗代碼 int n,i; double height1,height2;//1為輸入身高&#xff0c;2為輸出身高。 char sex; //1<height1<3; //N<1; scanf("%d",&n); while(n--){getchar();scanf("%c%lf",&sex,&height1);switch(sex)…

函數和函數式編程

python的過程就是函數&#xff0c;因為解釋器會隱式地返回默認值None。 實際編程中大部分偏函數更接近過程&#xff0c;不顯示地返回任何東西。 當沒有顯示地返回元素或者如果返回None時&#xff0c;python會返回一個None。 * 元組 ** 字典 def子句的剩余部分包括了一個雖…

清華大學《操作系統》(七):虛擬存儲、覆蓋、交換

接下來幾節都是對虛擬存儲的講解。虛擬存儲是非連續存儲管理的擴展。通過將內存中的數據暫存到外存的方式&#xff0c;為進程提供更大的內存空間。虛擬存儲出現的主要原因是因為程序規模的增長速度遠遠大于存儲器容量的增長速度&#xff0c;導致內存空間不夠用。其實針對內存空…

遵義大數據中心項目工程概況_市委書記張新文到曹州云都大數據中心等項目現場調研建設情況...

4月25日&#xff0c;市委書記張新文到曹縣調研重點項目建設情況&#xff0c;研究推進措施。市委常委、秘書長任仲義參加活動。張新文首先來到曹州云都大數據中心項目建設現場&#xff0c;查看項目推進情況。曹州云都大數據中心&#xff0c;是涵蓋云計算區、研發辦公區、公寓生活…

linux 可執行文件的分析(gcc GUN BUILEIN)

1、GCC The History of GCC 1984年&#xff0c;Richard Stallman發起了自由軟件運動&#xff0c;GNU (Gnus Not Unix)項目應運而生&#xff0c;3年后&#xff0c;最初版的GCC橫空出世&#xff0c;成為第一款可移植、可優化、支持ANSI C的開源C編譯器。GCC最初的全名是GNU C Com…

Cassandra 的數據存儲結構——本質是SortedMapRowKey, SortedMapColumnKey, ColumnValue

Cassandra 的數據存儲結構 Cassandra 的數據模型是基于列族&#xff08;Column Family&#xff09;的四維或五維模型。它借鑒了 Amazon 的 Dynamo 和 Googles BigTable 的數據結構和功能特點&#xff0c;采用 Memtable 和 SSTable 的方式進行存儲。在 Cassandra 寫入數據之前&a…

清華大學《操作系統》(八):置換算法

功能&#xff1a;置換算法是指當出現缺頁異常時&#xff0c;需要調入新頁面而內存已滿時&#xff0c;置換算法選擇被置換的物理頁面。 設計目標&#xff1a; 盡可能減少頁面的調入調出次數&#xff1b;把未來不再訪問或短期內不訪問的頁面調出。 頁面鎖定&#xff1a; 了解具…

python email模塊詳解_python模塊之email: 電子郵件編碼解碼 (一、解碼郵件)

python自帶的email模塊是個很有意思的東西&#xff0c;它可以對郵件編碼解碼&#xff0c;用來處理郵件非常好用。處理郵件是一個很細致的工作&#xff0c;尤其是解碼郵件&#xff0c;因為它的格式變化太多了&#xff0c;下面先看看一個郵件的源文件&#xff1a;Received: from …

爛泥:通過vsphere給esxi添加本地硬盤

公司ESXi服務器的硬盤空間不夠使用&#xff0c;現在新加了一塊硬盤在ESxi服務器上。在服務器上添加完硬盤后&#xff0c;在Vsphere上是看不到新加硬盤的。 下面我們來通過虛擬機模擬該情況&#xff0c;先添加一塊硬盤。如下圖&#xff1a; 在Esxi添加完硬盤后&#xff0c;現在通…

清華大學《操作系統》(九):進程和線程

進程 定義&#xff1a; 進程是指一個具有一定獨立功能的程序在一個數據集合上的一次動態執行的過程。 組成&#xff1a; 代碼數據狀態寄存器&#xff08;正在運行的一個程序的所有狀態信息&#xff09;&#xff1a;CPU狀態CP0、指令指針IP通用寄存器&#xff1a;AX、BX、CX…

開始Flask項目

1.新建Flask項目。2.設置調試模式。3.理解Flask項目主程序。4.使用裝飾器&#xff0c;設置路徑與函數之間的關系。5.使用Flask中render_template&#xff0c;用不同的路徑&#xff0c;返回首頁、登錄員、注冊頁。6.用視圖函數反轉得到URL&#xff0c;{{url_for(‘login’)}}&am…