Lawv muaj daim ntawv koj siv cov AngularJS thiab dhia tej ntaub ntawv JPA?

AngularJS and Spring data JPA

Ua koj daim ntawv thov los ntawm kev siv AngularJS thiab caij nplooj ntoos hlav JPA

Txheej txheem cej luam

Koj yuav tsim ib lub website npaum website uas muaj cov AngularJS thiab qhov AngularJS thiab qhov AngularJS thiab cov Caij nplooj ntoos hlav ntaub JPA. Txhua tus tivthaiv muaj ib lub luag hauj lwm luag hauj lwm ua si. Thaum cov AngularJ acts ua tus nplua nuj client, pab kom lawv muaj kev npaum thiab dynamic Kev Siv Nyiaj Nplooj Ntawv (SPA) uas txo load rau servers thiab muaj smarter nplooj ntawv refreshes, Lub caij nplooj ntoos hlav JPA pub teev tseg ib txheej smart database uas tso cai rau tus neeg thov kom sai thiab tau txais cov ntaub ntawv thov.








What is Angular JS?

Tus AngularJS yog ib qhib-qhov chaw thiab JavaScript-raws li lub tsev dynamic daim ntaub ntawv. AngularJS yog muab thiab tswj los ntawm Google. AngularJS txo qhov kev siv zog yuav tsum tau tsim ib zaug xwb (SPA). Nws muab ib lub framework uas txo kom txhob muaj dag zog sau ntawv. Lub ntsiab nta ntawm AngularJS yog:

  • Tus Qauv-saib-xws li (MVC) framework pub koj phua lub lag luam logic txheej, txheej, thiab nthuav qhia rau kem cais ces koj yuav ua hauj lwm rau txhua seem ib lub zuj zus. Cov khaubncaws sab nraud povtseg nrog sib.
  • Tsis muaj ntaub ntawv tseem ceeb binding dag zog yuav tsum tau. Koj tsis tas sau tshwj xeeb code rau hauv cov ntaub ntawv rau HTML, AngularJS ua rau koj.
  • Txij thaum lub AngularJS yog ib lub moj khaum framework, Nws muab ntau yam kev pab cuam uas koj yuav siv tau los ua. ua tau zoo DOM cuab yeej, koj yuav tau sau ntawv ntau JavaScript code. Tab sis nrog AngularJS, Koj tsis tas yuav ua li ntawd vim nws muab cov snippets.

Lub caij nplooj ntoos hlav JPA?

Tag nrho cov ntaub ntawv enterprise yuav tsum tau nrog cov ntaub ntawv database rau tom khw thiab retrieve ntaub ntawv. Txawm li cas los, Interacting nrog database lawm yeej tsis tau du vim:

  • Dhau boilerplate chaws yuav tsum tau sau yooj yim queries thiab ua tau paingation uas yog ib tug khib nyiab.
  • Software developers siv proprietary framework los interact nrog cov ntaub ntawv bases uas tsis yog ib tug seamless transaction.
  • Relational cov qauv uas siv rau databases muaj ntaub ntawv sib tw rau developers.

Lub caij nplooj ntoos hlav JPA yuav database tus database thiab cov ntaub ntawv retrieval teeb meem los ntawm kev muab ib cov ntaub ntawv txheej txheem. Ntawm tus tsim tawm foupective, Txhua yam uas yuav tsum tau ua yog sau cov repository interfaces, Nrog rau kev lis kev cai nrhiav thiab tas yog ua los ntawm lub caij nplooj ntoos hlav Ntaub ntawv JPA. Lub ntsiab nta ntawm lub caij nplooj ntoos hlav JPA yog: kev them nyiaj yug rau lub caij nplooj ntoos hlav thiab JPA kuas repositories; pob tshab auditing ntawm hoob kawm; kev them nyiaj yug, dynamic query tiav thiab yuav integrate cov ntaub ntawv raug cai saib.








Yuav tsum nyeem – Nthuav cov khoom rau lub caij nplooj ntoos hlav moj khaum

Txheej Xwm Txheej Txheem

Qhov tseem ceeb vim li cas thaum lawv tseem AngularJS thiab lub caij nplooj ntoos hlav JPA yuav tsum najnpawb JPA yuav tsum hais hauv qab no.

  • Ntawm tus fouptive ntawm cov neeg siv kev kawm txawj, Ib tug seamless pem hauv ntej-xaus los sis tus neeg tau txais kev pab yog tsim nyog. Cov neeg yuav tsum tau ntseeg nkaws siv lub database, Xa queries thiab retrieve cov lus teb nyob rau hauv ib daim ntawv kom paub. Tus sai txheej txheem tiav lawm, Qhov zoo tshaj plaws yog rau cov neeg siv kev kawm txawj. Lub caij nplooj ntoos hlav JPA enables pab kom muaj ib tug ceev thiab smooth transaction.
  • Txij thaum lub AngularJS yog ib tug framework uas, tag nrho cov chav nyob yuav muab cais, Nws yuav interact zoo nrog lub database txheej txheem nrog kev pab los ntawm lub caij nplooj ntoos hlav JPOA, lawv paving qhov uas rau ib smooth query thiab teb lawv.

Mus kom ze

Feem ntau, Cov nram qab no yuav tsum tau noj thaum lub tsev muaj ntawv pov thawj nrog AngularJS thiab lub caij nplooj ntoos hlav Data JPA.

  • Txhais peb tes num ua ntej. Nyob rau hauv cov qauv, koj yuav tsum txhais tag nrho cov folders, subfolders, dependencies thiab cov chaw muab kev pab, xijpeem nyob rau hauv cov ntsiab lus teb ntawm peb tes num.
  • Txhais tias cov parameters los yog configuration hauv lub POM.xml xml. Feem ntau cov neeg, Qhov peb tes num POM yuav feem ntau inherit ntawm lub caij nplooj ntoos hlav-starter-starter-starter.
  • Txhais lub caij nplooj ntoos hlav Boot class. Lub caij nplooj ntoos hlav Boott muaj lub caij nplooj ntoos hlav Spring() txujci.
  • JPA configuration. Nyob rau hauv cov kauj ruam no, Koj yuav tau teem caij mus rau tom qab cov repositories: Lub caij nplooj ntoos hlav @EnableJpaRepositories; Caij nplooj ntoos hlav Ntawv DataceProperties; thiab caij nplooj ntoos hlav DataceSBuilder.



Pitfalls thiab cov kev txwv

Thaum lawv tseem AngularJS thiab caij nplooj ntoos hlav JPA no zoo kawg thiab kev sib tham thiab database sib tham tiam sis tsuas yog tej txoj kev sib tw no tswj zoo. Txawm li cas los, Tus AngularJS yog ib MVC framework thiab tag nrho nws cov chav nyob zajlus — lag luam logic, txheej, thiab nthuav qhia tseeb – yuav muab cais rau hauv cov khej (logical logical). Tab sis yog qhov no muab ntau yooj ywm, Nws kuj tsim tau teeb meem compatibility nrog lub database txheej txheem tsim nrog lub caij nplooj ntoos hlav Ntaub Ntawv JPA. Piv txwv, txheejtxheem yuav tsis ua hauj lwm, yog hloov los yog hloov nrog tus database txheej. Li ntawd, Nws tseem tias thaum twg yog thaum twg muaj tej kev hloov nyob rau hauv AngularJS MVC framework, Lub compatibility nrog lub database txheej txheem yog cia siab.

Kawm lub thawv ntim khau raj – Yees duab tutorials

Lub tsev daim ntawv thov (Chaws)

Ntu no, Peb yuav ua kom lawv muaj ib daim ntawv thov muaj AngularJS, Caij nplooj ntoos hlav thiab JPA. Nws yuav ua tau ib lub khau raj nplaim hlau khau ntaub ntawv.

Ua ntej, Peb yuav xyuas cov pom.xml file. Nyob rau hauv daim ntawv no, Peb yuav muaj dependencies rau lub caij nplooj ntoos hlav, MySQL, hlais.

Qhia 1: Qauv xauj tsev.xml

[chaws]

<quav dej caws>

<groupId>org.springframework.boot</groupId>

<artifactId>caij nplooj ntoos hlav-starter-jpa</artifactId>

</quav dej caws>

<quav dej caws>

<groupId>org.springframework.boot</groupId>

<artifactId>caij nplooj ntoos hlav-starter-starter</artifactId>

</quav dej caws>

<quav dej caws>

<groupId>org.springframework.boot</groupId>

<artifactId>caij nplooj ntoos hlav-starter-tomcat</artifactId>

<tau>npaj</tau>

</quav dej caws>

<quav dej caws>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

<tau>khiav</tau>

</quav dej caws>

[/chaws]

Tam sim no, Peb yuav xyuas cov qauv kawm ntawv qauv. Qhov no yog cov qauv kawm ntawv mapped nrog lub rooj nyob rau hauv cov database. Table column npe yuav tsum mapped nrog cov chaw uas siv annotations. Cov qauv kawm ntawv yuav tsum tau siv Serializable interface.








Qhia 2: Neeg ua hauj lwm qauv

[chaws]

pob.com.techalpine.spring.piv txwv

chaw nres nkoj java.i.Serializable;

import javax.persistence.Column;

chaw nres nkoj javax.persistence.Entence;

import javax.persistence.Generatedue;

import javax.persistence.Generation.Generation;

tseem ceeb javax.persistence.Id;

import javax.persistence.Table;

@Entity

@Table(lub npe = “neeg ua hauj lwm”)

Pej xeem huab hwm cov neeg ua hauj lwm siv Serializable {

Lwm yam static zaum kawg serialversuID = -30089732434346L;

@Id

@GeneratedValue(yaam tswv yim = Tiam sis Generation.AUTO)

ntev;

@Column(lub npe = “firstname”)

ntiav firstName;

@Column(lub npe = “lastname”)

Qhov kawg nkaus dhau lub xeem;

neeg ua hauj lwm rau pej xeem(Txoj hlua thawj zaug, Txoj hlua dhau lub xeem) {

Lub npe no. xub pib = thawj lub npe;

no lub xeem = lastName;

}

Pej xeem ntev() {

rov qab los;

}

pej xeem zais cia(ntev) {

this.id = id;

}

Pej xeem string tauFirstName() {

rov qab los ua ntej;

}

Pej xeem void setFirstName(Txoj hlua thawj zaug) {

Lub npe no. xub pib = thawj lub npe;

}

Pej xeem stringing tauLastName() {

rov qab los xeem;

}

Pej xeem void setLastName(Txoj hlua dhau lub xeem) {

no lub xeem = lastName;

}

@Override

Pej xeem stringing torsting() {

daim ntawv xa rov qab tuaj.)(“Neeg ua hauj lwm[ntshai, Lub npe hluav taws xob='s', Xeem Lub xeem%'s']”, daim, firstName, lastName);

}

}

[/chaws]

Tam sim no, Peb yuav ua ib tug qauv ntau hoob kawm, yog cov lus teb. Lub hom phiaj ntawm hoob kawm no yog tuav cov ntaub ntawv teb cov ntaub ntawv.

Qhia 3: Teb cov ntaub ntawv qauv kawm

[chaws]

pob.com.techalpine.spring.piv txwv

Pej xeem hoob kawm teb {

txoj cai ntiav;

kheej kheej kheej;

Pej xeem Teb() {

}

Pej xeem Teb(txoj cai, Kwvyees li) {

qhov no... raws li txoj cai = raws li txoj cai;

qhov no... cov ntaub ntawv no = cov ntaub ntawv;

}

Pej xeem txoj hlua rau pej xeem() {

txheej xwm rov qab;

}

pej xeem tsis txhob setStatus(txoj cai) {

qhov no... raws li txoj cai = raws li txoj cai;

}

Cov pej xeem Objecta() {

cov ntaub ntawv rov qab;

}

pej xeem tsis txhob setData(Kwvyees li) {

qhov no... cov ntaub ntawv no = cov ntaub ntawv;

}

}

[/chaws]

Tom qab tsim cov qauv kawm, Peb yuav tau tsim ib repository hoob kawm.








Qhia 4: Hoobkas repository chav kawm ntawv

[chaws]

pob.com.techalpine.spring.piv txwv

ntshuam java.util.List;

import.springframework.cov ntaub ntawv.CrudRepository;

Import.com techalpine.spring.piv txwv.Employee;

pej xeem interface EmployeRepository extends CrudRepository<neeg muas zaub, Ntev> {

Iterable<neeg muas zaub> nrhiav tau();

}

[/chaws]

Tam sim no, Peb yuav tau tsim ib qho controller class li qhia hauv qab no. Ntawm no peb yuav xyuas txuag thiab retrieval ib feem ntawm cov neeg ua hauj lwm cov ntaub ntawv.

Qhia 5: Hoob Kawm Qauv

[chaws]

pob.com.techalpine.spring.piv txwv

ntshuam java.util.List;

import.springframework.taum... annotation.annotation.Autowired;

import.springframework.web.bind.annotation.PathVariable;

import.springframework.web.bind.annotation.RequestBody;

ntshuam org.springframework.web.bind.annotation.RequestMapping;

import.springframework.web.bind.annotation.RequestMethod;

import.springframework.web.bind.annotation.Requestparam;

ntshuam org.springframework.web.bind.annotation.RestController;

Import.com techalpine.spring.piv txwv.responseata;

Import.com techalpine.spring.piv txwv.Employee;

Import.com techalpine.spring.piv txwv.EmployeRepository;

@RestController

Pej xeem kawm ntawv cov neeg ua hauj lwm {

@Autowired

Tus neeg ua hauj lwm cov ntaubntawv;

@RequestMapping(tus nqi = “/neeg ua hauj lwm”, hom RequestMethod.POST)

pej xeem tsis txhob ncej Neeg Ua Hauj Lwm(@RequestBody neeg ua hauj lwm) {

ntxeev siab...(neeg ua hauj lwm tshiab(neeg ua hauj lwm.getFirstName(), Neeg ua hauj lwm.getLastName()));

}

@RequestMapping(“/nrhiav tau”)

Pej xeem teb nrhiav() {

Iterable<Neeg ua hauj lwm> Neeg ua hauj lwm = repository.nrhiav();

Rov qab teb tshiab(“Ua li cas”, neeg ua hauj lwm);

}

}

[/chaws]

Tom qab tsim tus tswj, Peb yuav tau saib hauv daim ntawv UI hauv daim ntawv thov. Ntawm no peb yuav tsim ib nplooj ntawv JSP nrog AngularJS tag nrho thiab tau neeg ua hauj lwm cov ntaub ntawv.

Qhia 6: Qauv JSP nplooj ntawv Nrog Angular JS tags

[chaws]

<%@ sab lus =”java” contentType =”ntawv nyeem/html; charset =ISO-8859-1″

pageEncoding =”ISO-8859-1″%>

<!DOCTYPE html PUBLIC “-//W3C / / DTD HTML 4.01 Hauv / / EN” “http://www.w3.org/TR/html4/loose.dtd”>

<html>

<lub taub hau>

<npe>Nqa khau raj thiab JPA piv txwv</npe>

<ua tau http-equiv=”Content-Type” ntsiab lus =”ntawv nyeem/html; charset =ISO-8859-1″>

<lub npe meta =”viewport” ntsiab lus =”dav = ntaus-dav, nplai-teev =1″ />

<tsab ntawv

scr = voj xyaw.”http://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular.min.js”></tsab ntawv>

<tsab ntawv src =”/js/angular.js”></tsab ntawv>

<txuas rel =”stylesheet”

href =”http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css” />

</lub taub hau>

<lub cev>

<hoob kawm=”thawv” ng-app=”app”>

<h1>AngularJS – Caij nplooj ntoos hlav JPA – DB</h1>

<hoob kawm=”Leej”>

<cov tshuaj ng-controller=”neeg txom nyem” hoob =”nyuj-md-3″>

<daim ntawv npe =”neeg ua hauj lwm” nas-submit=”xa mus rau()”>

<lo cim>Ua ntej tshaj plaws</lo cim>

<input yam =”ntawv nyeem” lub npe =”firstname” hoob =”daim ntawv- Tswj” ng-qauv =”firstname” />

<lo cim>Xeem</lo cim>

<input yam =”ntawv nyeem” lub npe =”lastname” hoob =”tswj” ng-qauv =”lastname” />

<khawm hom twg=”xa” hoob =”btn-btn-primary”>Xa</khawm>

</daim ntawv>

<p>{{postresmestessage}}</p>

</div>

</div>

<hoob kawm=”Leej”>

<cov tshuaj ng-controller=”neeg ua hauj lwm tau zoo” hoob =”nyuj-md-3″>

<hlau>Tag nrho cov neeg ua hauj lwm</hlau>

<khawm nkauj-click=”Cov Neeg Ua Haujlwm()”>Tau tag nrho cov neeg ua hauj lwm</khawm>

<div-show=”Cov neeg ua hauj lwm uas qhia tias tus neeg ua hauj lwm”>

<hoob kawm=”cov pab pawg neeg”>

<lig-rov qab ua li cas?”cov neeg ua hauj lwm rau cov neeg ua hauj lwm...”><hoob kawm=”cov pab pawg neeg-khoom”>

<muaj zog>Neeg ua hauj lwm {{$Performance Index}}</muaj zog><br />

Employ: {{employee.id}}<br />

Emp ua ntej lub npe: {{neeg ua hauj lwm.firstName}}<br />

Xeem Lub Npe: {{neeg ua hauj lwm.dhau lub xeem}}

</h4></nyiam>

</ul>

</div>

<p>{{Kev mob ntsws}}</p>

</div>

</div>

</div>

</lub cev>

</html>

[/chaws]

Qhov no yog cov nplooj ntawv JSP rau submitting cov ntaub ntawv thiab retrieve tag nrho cov neeg ua hauj lwm cov ntaub ntawv.

Yuav tsum saib – Caij nplooj ntoos hlav video tutorials








Xaus

Tus AngularJS thiab caij nplooj ntoos hlav JPA muaj ib tug zoo caij nyoog los tsim ib tug robust thiab dynamic web thov yog lub compatibility ntawm cov neeg lag luam thiab tus database tswj intelligently. Lub caij nplooj ntoos hlav JPA yog yooj yim rau siv thiab siv. Li ntawd, tus developers yuav tau siv nws yooj yim thiab persist lawv cov ntaub ntawv nyob rau hauv cov database.


============================================= ============================================== Yuav zoo TechAlpine phau ntawv rau Amazon
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric
error

Txaus siab rau qhov blog? Tshaj tawm lus thov :)

Follow by Email
LinkedIn
LinkedIn
Share