使用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 '@...

上一篇: 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() {
    // 获取ID
    this.id = this.route.snapshot.params['id'];
    // 获取Client
    this.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() {
    // 获取ID
    this.id = this.route.snapshot.params['id'];
    // 获取Client
    this.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.

下面是我的关于ASP.NET Core Web API相关技术的公众号--草根专栏:

目录
相关文章
|
2天前
|
JavaScript 前端开发 数据安全/隐私保护
Web开发者必看:手把手教你如何轻松播放m3u8流地址,解锁视频播放新技能,让你的项目更上一层楼!
【10月更文挑战第23天】随着互联网技术的发展,m3u8格式因良好的兼容性和高压缩率被广泛用于网络流媒体传输。本文介绍如何在Web端播放m3u8流地址,包括引入视频播放器(如Video.js)、创建播放器容器、初始化播放器及播放m3u8流的具体步骤。此外,还涉及处理加密m3u8流的示例。
7 1
|
10天前
|
JSON 搜索推荐 API
Python的web框架有哪些?小项目比较推荐哪个?
【10月更文挑战第15天】Python的web框架有哪些?小项目比较推荐哪个?
28 1
|
25天前
|
前端开发 JavaScript API
惊呆了!学会AJAX与Fetch API,你的Python Web项目瞬间高大上!
在Web开发领域,AJAX与Fetch API是提升交互体验的关键技术。AJAX(Asynchronous JavaScript and XML)作为异步通信的先驱,通过XMLHttpRequest对象实现了局部页面更新,提升了应用流畅度。Fetch API则以更现代、简洁的方式处理HTTP请求,基于Promises提供了丰富的功能。当与Python Web框架(如Django、Flask)结合时,这两者能显著增强应用的响应速度和用户体验,使项目更加高效、高大上。
45 2
|
17天前
|
监控 Java Maven
springboot学习二:springboot 初创建 web 项目、修改banner、热部署插件、切换运行环境、springboot参数配置,打包项目并测试成功
这篇文章介绍了如何快速创建Spring Boot项目,包括项目的初始化、结构、打包部署、修改启动Banner、热部署、环境切换和参数配置等基础操作。
71 0
|
2月前
|
缓存 JavaScript 前端开发
Angular 应用打包和部署
Angular 应用打包和部署
166 58
|
8天前
|
缓存 监控 JavaScript
Angular 应用打包和部署
【10月更文挑战第16天】Angular 应用的打包和部署是一个综合性的过程,需要考虑多个方面的因素。通过合理的打包和部署策略,可以确保应用在生产环境中稳定运行,并为用户提供良好的体验。你需要根据实际情况选择合适的部署方式,并不断优化和改进部署流程,以适应业务的发展和变化。
|
3月前
|
应用服务中间件 Java Maven
掌控视图的力量!深入解析 JSF 视图管理,揭秘视图生命周期的秘密,让你的应用更高效!
【8月更文挑战第31天】JavaServer Faces (JSF) 是一种强大的框架,用于管理 Web 应用程序的视图。本文通过具体案例介绍 JSF 视图管理的基础知识,包括创建、管理和销毁视图的过程。首先,在 Eclipse 中创建一个新 JSF 项目,并配置 Maven 依赖。接着,在 `WEB-INF` 目录下配置 `web.xml` 文件,设置 JSF servlet。
49 0
|
3月前
|
Java Spring
🔥JSF 与 Spring 强强联手:打造高效、灵活的 Web 应用新标杆!💪 你还不知道吗?
【8月更文挑战第31天】JavaServer Faces(JSF)与 Spring 框架是常用的 Java Web 技术。本文介绍如何整合两者,发挥各自优势,构建高效灵活的 Web 应用。首先通过 `web.xml` 和 `ContextLoaderListener` 配置 Spring 上下文,在 `applicationContext.xml` 定义 Bean。接着使用 `@Autowired` 将 Spring 管理的 Bean 注入到 JSF 管理的 Bean 中。
57 0
|
3月前
|
开发者 Java 开发框架
JSF与EJB,打造企业级应用的神器!让你的Web应用更加稳定、高效!
【8月更文挑战第31天】在现代企业级应用开发中,JSF(JavaServer Faces)与EJB(Enterprise JavaBeans)是两大核心技术。JSF作为一款基于Java的Web应用框架,以其丰富的UI组件和表单处理功能著称;EJB则专注于提供分布式事务处理及远程调用等企业级服务。两者的结合为企业应用带来了高效便捷的开发模式。下文将通过一个简单的示例展示如何利用JSF进行用户信息的输入与保存,并借助EJB实现相关业务逻辑。尽管这一组合具有明显优势,但在实际应用中还需考虑其局限性并作出合理选择。
51 0
|
3月前
|
开发者 安全 SQL
JSF安全卫士:打造铜墙铁壁,抵御Web攻击的钢铁防线!
【8月更文挑战第31天】在构建Web应用时,安全性至关重要。JavaServer Faces (JSF)作为流行的Java Web框架,需防范如XSS、CSRF及SQL注入等攻击。本文详细介绍了如何在JSF应用中实施安全措施,包括严格验证用户输入、使用安全编码实践、实施内容安全策略(CSP)及使用CSRF tokens等。通过示例代码和最佳实践,帮助开发者构建更安全的应用,保护用户数据和系统资源。
50 0