Kauj ruam mus integrate rau lub caij nplooj hlav MVC thiab AngularJS

Spring and AngularJS

Kauj ruam mus integrate rau lub caij nplooj hlav MVC thiab AngularJS

Txheej txheem cej luam

Thaum lawv ua ke Caij nplooj ntoos hlav MVC thiab AngularJS yog ib lub haib tshaj plaws ua ke los tsim web-raws li cov ntaub ntawv. Qhov no yog tshwj xeeb tshaj yog siv nyob rau hauv lub tsev dynamic apps los yog Kev Siv Nyiaj Nplooj Ntawv. Ib nta xws li modularity, qhib tau qhov twg los, yooj thiab coupling yog ib hom ntawm ob tus neeg tau kev pab thiab muab rau neeg noj. Lawv kuj yog lub luag hauj lwm los ua daim ntawv thov kom khiav tsis glitches. Muaj ob peb txoj kev sib tw uas yog hais nyob rau hauv tsab xov xwm no tab sis uas tsis txo qhov zoo pab los ntawm qhov ob frameworks.








Lub caij nplooj ntoos hlav MVC?

Lub caij nplooj ntoos hla Qauv saib xws li (MVC) Yog ib lub framework uas facilitates txoj kev loj hlob ntawm cov ntaub ntawv uas muaj website. Thaum muaj lwm frameworks thiab, Lub caij nplooj ntoos hlav MVC tus uniqueness yog nws yooj ywm thiab modularity. Thaum nws ua hauj lwm ua ke los ua ib daim ntawv thov web, Txhua tus tivthaiv yuav kho tau kom tus neeg sab nraud thiab xoob ntxoov nyoos. Qhov no txhais tau tias txhua tus tivthaiv no hloov thiab tau nrog txhua yam uas koj xaiv nqa tuaj rau hauv. Tab sis yog muaj peb hom logic — muab tshuaj logic, lag luam logic, thiab UI logic – nyob rau hauv lub framework, tag nrho yog ywj siab thiab loosely ob peb. Lub ntsiab ntawm lub caij nplooj ntoos hlav MVC muaj piav hauv qab no:

  • Qauv: Daim ntawv thov encapsulates daim ntawv thov thiab feem ntau daim ntawv thov cov ntaub ntawv sau npe rau daim ntawv thov kev pab cuam dawb Java Object (POJ NIAM).
  • Saib: Tus saib tivthaiv renders tus qauv cov ntaub ntawv thiab vim li ntawd, Nws generates HTML tso zis. Tus neeg tau browser feem ntau yuav ua tau txoj kev thiab txhais tau cov lus HTML generated los ntawm tus saib tivthaiv.
  • Xws li: Tus tswj tau cov neeg siv thov lossis cov lus tsis txaus siab, Txheej txheem tib yam thiab kis nws mus rau tus saib tivthaiv rau rendering.









What is Angular JS?

Tus AngularJS yog ib qhib qhov chaw qhib, pem hauv ntej-kawg JavaScript framework uas tso cai rau pem hauv ntej xaus developers siv JavaScript ntxiv rau lawv webpages.

Tsim lub Single Page 3 (SPA) Lawm ib tug yooj yim ua hauj lwm rau pem hauv ntej-kawg developers rau ntau yam. AngularJS, Tsim raws li ib qhib qhov twg qhib pem hauv ntej-kawg daim ntawv thov framework los ntawm Google aims daws kom daws tau tej teeb meem muag los ntawm cov pem hauv ntej-kawg developers. AngularJS tso cai rau ob txoj kev loj hlob thiab kev kuaj ntawm SPAS thiab muab ib lub framework rau tus qauv kawm-tus qauv-saib-tus tswj hwm (MVC) thiab qauv–saib qauv saib qauv (MVMV) architectures, As well as components uas feem ntau yog siv nyob rau hauv cov ntaub ntawv nplua nuj Internet.

AngularJS Lawm ib yam khoom nrov thiab twb siv ntau lub koom haum xws li NBC, Wolfram Alpha, Chaw ntiav pw, Walgreens, Khiav thiab ABC News. Raws li qhov chaw, AngularJS nyob saum toj kawg nkaus 100 Feem ntau starred los yog nyiam tej yaam num rau GitHub.

Yuav tsum saib – Lub khau raj video tutorials



Integration Principles

Seem no tham txog tus thawj xibfwb los yog kev ntawm lub koom haum ntawm lub caij nplooj ntoos hlav MVC nrog AngularS. Ua ntej yuav pib, Nws yuav tsum tau to taub tias lub cwj pwm ntawm lub caij nplooj ntoos hlav MVC thiab AngularJS txawv tab sis yog cov hom phiaj yog tib yam. Thaum Caij nplooj ntoos hlav MVC yuav muab ib lub framework uas ua haujlwm rau cov neeg ua hauj lwm uas muaj daim ntawv thov website, Tus AngularJS yuav tau ua haujlwm rau tus neeg tau kev pab los yog xaus rau hauv daim ntawv thov. Lub ntsiab txhooj tseem ceeb yog:

· Modularity pom zoo

Ob lub caij nplooj ntoos hlav MVC thiab AngularJS yog tsim rau lub hauv paus ntawm modularity uas txhais tau hais tias ib tug neeg modules yog loosely kaj siab lug thiab hloov tau. Txawm li cas los, Qhov no yuav tsum tau khaws tias thaum lub module yog muab kho los sis hloov rau hauv tus neeg tau txais kev pab los sis raug xaus, Lwm yam compatible uas muaj qhov hloov, Lwm tus nws yuav loj cuam tshuam txog cov ntaub ntawv txaus. Li ntawd, software architects thiab designers yuav tsum tau vigilant thiab ceev faj txog modular compatibility.

· Cov lus qhia ntws

Cov ntaub ntawv txaus qhia yog tseem ceeb heev rau cov qauv ntawm tus neeg tau txais kev pab raws li lub compatibility ntawm MVC frameworks ntawm ob lub caij nplooj ntoos hlav MVC thiab AngularJS. Tsis muaj compatibility yuav ua rau yuam kev thiab tus neeg siv kev yuav disastrous.

· Cov ntaub ntawv qhia txog kev them nyiaj yug

Cov architecture thiab tsim ntawm ob lub pab pawg neeg thiab cov neeg tau txais kev pab yuav tsum txhawb cov ntaub ntawv tib hom thiab rau ntawd, Ob lub caij nplooj ntoos hlav MVC nrog AngularJS frameworks yuav tsum tau compatible uas ntau yam ntaub ntawv. Tsis tas li ntawd xwb, Raws li cov ntaub ntawv tshiab types ntxiv rau lub kaw lus, Lub compatibility yuav tsum tau upward mobile.







Lub caij nplooj ntoos hlav MVC nrog Angular JS (Chaws)

Ntu no, Peb yuav tsim ib daim ntawv thov integrating MVC thiab AngularJS. Tus thawj tivthaiv yog ib daim ntawv teev cov ntaub ntawv piav hauv qab no.

Qhia 1: Tej ntaub ntawv qauv ua daim ntawv teev npe

[chaws]

pob.com.techalpine.spring.controller;

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

import.springframework.http.HtpStatus;

import.springframework.stereotype.Stereotype.Controller;

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

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

import.springframework.web.bind.annotation.responseBody;

import.springframework.web.bind.annotation.responseStatus;

@Controller

Pej xeem hoob kawm springDemoController {

@Autowired EmpDetails empDetails;

@RequestMapping(tus nqi =”/txhab txiag”,

Txoj kev yees duab =RequestMethod.GET,zaub pob xeeb xeebtxwv.{“daim ntawv thov/xml”, “daim ntawv thov/json”})

@ResponseStatus(HttpStatus.OK)

pej xeem @ResponseBody

EmpDetails lawm() {

EmpDetails empDetails = EmpDetails tshiab();

empDetails.setUserName(“demouser”);

empDetails.setEmail(“demouser@gmail.com”);

rov qab mus empDetails;

}

}

[/chaws]

Tom qab no yog ib hoob kawm poJO rau cov neeg ua hauj lwm paub meej. Nws yuav muaj setter thiab tau txais txoj kev.

Qhia 2: Qauv PoJO (Neeg ua hauj lwm paub meej)

[chaws]

pob.com.techalpine.spring.controller;

Chaw nres nkoj javax.xml bind.XmlAttribute;

Import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement

Pej xeem hoob kawm EmpDetails {

qhov kauj ruam ntiav;

ntiav stringing email;

@XmlAttribute

Pej xeem stringing tauEmpName() {

rov qab mus empName;

}

pej xeem void setEmpName(Txoj hlua empName) {

qhov no.empName = empName = empName;

}

@XmlAttribute

Pej xeem string tauEmail() {

rov qab los email;

}

pej xeem void setEmailId(Txoj hlua email) {

no.email = email = email;

}

}

[/chaws]

Tam sim no tus thib peb tivthaiv yog ib dispatcher servlet xml ntawv uas muaj tag nrho cov mappings.

Qhia 3: Dispatcher phaj

[chaws]

<?xml version =”1.0″ encoding =”UTF-8″?>

<taum xmlns =”http://www.springframework.org/schema/beans”

xmlns:mvc=”http://www.springframework.org/schema/mvc”

xmlns:ntsiab lus teb=”http://www.springframework.org/schema/context”

xmlns:xsi =”http://www.w3.org/2001/XMLSchema-instance”

xsi:schemaLocation =”http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd”>

<ntsiab lus teb:pheej ywj pheej-scan base-pob=”com.com techalpine.caij nplooj ntoos hlav.spring.controller” />

<taum daim id =”empdetails” hoob =”com.com techalpine.spring.controller.EmpDetails”/>

<muv:annotation-uas tau tsav content-negotiation-manager=”tus saib xyuas”/>

<taum daim id =”tus saib xyuas”

hoob =”org.springframework.web.accept.accept.ContentNegotiationFacterFactoryBean”>

<lub npe ntawm tus kheej =”favorpathExtension” tus nqi =”tseeb”/>

<lub npe ntawm tus kheej =”las mees” tus nqi =”tseeb” />

<lub npe ntawm tus kheej =”defaultcontentype” tus nqi =”ntawv nyeem/html” />

<lub npe ntawm tus kheej =”siv Yudais” tus nqi =”tsis tseeb”/>

<lub npe ntawm tus kheej =”mediatypes”>

<daim ntawv qhia>

<nkag teb chaws=”html” tus nqi =”ntawv nyeem/html” />

<nkag teb chaws=”rison” tus nqi =”daim ntawv thov/json” />

<nkag teb chaws=”xml” tus nqi =”daim ntawv thov/xml” />

</daim ntawv qhia>

</khoom>

</taum>

<taum daim id =”jspViewResolver”

hoob =”org.springframework.web servlet.view.InternalRescewewolver”>

<lub npe ntawm tus kheej =”ua ntej” tus nqi =”/WEB-INF/jsp/jsp/” />

<lub npe ntawm tus kheej =”suffix” tus nqi =”.jsp” />

</taum>

</taum>

[/chaws]

Qhov no yog cov pem hauv ntej kawg tivthaiv uas yog ib nplooj AngularJS.

Qhia 4: Qauv AngularJS nplooj ntawv

[chaws]

<!doctype html>

<html ng-app>

<lub taub hau>

<npe>Demo Application siv lub caij nplooj ntoos hlav MVC & tsomkwm</npe>

<tsab ntawv src =”https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js”></tsab ntawv>

<tsab ntawv>

Muaj nuj nqi HelloAngular($tau, $http) {

$http.wisconsin.gov(ntxeev siab://localhost:8080/SpringExamples/springcontent.json').

tav(muaj nuj nqi(cov ntaub ntawv) {

$tau.emp.emp = cov ntaub ntawv;

});

}

</tsab ntawv>

</lub taub hau>

<lub cev>

<cov tshuaj ng-controller=”Nyob zoo”>

<h2>Caij nplooj ntoos hlav MVC thiab AngularS Demo</h2>

<p>Tus neeg ua hauj lwm lub npe : {{emp.username}}</p>

<p>EMail Id : {{emp.email}}</p>

</div>

</lub cev>

</html>

[/chaws]

Tam sim no khiav cov nplooj ntawv hauv browser. Tom qab no yuav muab tso zis.

Caij nplooj ntoos hlav MVC thiab AngularS Demo

Tus neeg ua hauj lwm lub npe: demouser

EMail Id: demouser@gmail.com

Cov kev txwv thiab teeb meem

Lub ntsiab kev sib tw los thaum lub koom haum no tasked nrog lub luag hauj lwm ntawm tswj ob tus neeg thiab muab kev pab. Ob lub caij nplooj ntoos hlav MVC thiab AngularJS yog versatile components thiab muaj peev xwm txais ntau yam modules. Tam sim no, Nws yog ib tug loj loj sib tw kom nrhiav thiab tuav components thiab versions software thiab logical chav kom tus neeg tau thiab muab kev pab sib tham sib seamlessly. Feem ntau, thaum twg ntau yam pauv loj los sis hloov tshiab, Nws yuav tsis yooj yim kom paub tseeb tias tus tshiab tivthaiv yog compatible.

Koj yuav tau xav nyeem ntawv – Nthuav cov khoom rau lub caij nplooj ntoos hlav moj khaum







Xaus

Txoj kev sib tw notwithstanding, Ua ke nrog ntawm ob lub frameworks tseem muab txoj kev zoo tshaj los tsim lub web apps. Ntawm tus foupective ntawm software developers, Cov ntaub ntawv qhib daim ntaub ntawv qhib yog ib qho irresistible proposition li yog cov ntseg zog-packed nta.
 


============================================= ============================================== 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