SlideShare una empresa de Scribd logo
1 de 39
Java Spring MVC using
MySQL
What are we building?
• A MVC webapplikation for CRUD operations
Webapp CRUD operations
What we need to create this app
• MySql Database
• Spring Initializr to set up the Spring webapp
Create account and database at
https://remotemysql.com/
• Create tables in phpmyadmin
• https://www.liquidweb.com/kb/creating-tables-in-a-database-with-
phpmyadmin/
NB-Springboot-Plugins for netbeans 11/12
• http://plugins.netbeans.org/plugin/67888/nb-springboot
• https://github.com/AlexFalappa/nb-springboot/wiki/Quick-Tour
• https://www.techgalery.com/2019/01/how-to-create-spring-boot-
project-using.html
From meny Tools/
plugins
Spring initializr
• Got to https://start.spring.io/
• Add these dependencies so we can create a spring web app and database connection
rename
Move the download zip file to more suitable
folder
Open netbeans import the zip file
• Import the saved zip file in netbeans File->import->from zip
• Will be a new project.
Intro Spring creating Controllers and Views
1. Any incoming request that comes to the web
application will be sent to Front Controller (a
Dispatcher Servlet)
2. Front Controller decides to which (Controller) it has to
hand over the request, based on the request headers.
3. Controller that took the request, processes the
request, by sending it to suitable service class.
4. After all processing is done, Controller receives the
model from the Service or Data Access layer.
5. Controller sends the model to the Front Controller
6. Dispatcher servlet finds the view template, using view
resolver and send the model to it.
7. Using View template and the model a view page is
build and sent back to the Front Controller.
8. Front controller sends the constructed view page to
the browser to render it for the user requested.
Create package for our controllers and then
add a CarControllerMysql
• Create an controllers package
• Name it controllers
• Add new java Controller class in that package
• Name it CarControllerMysql
To see this Controller class
you need the plugin for
NB-springboot installed
The auto genereted code for the new
TestController class
Run the web app,
you get an error about databases
Run the app, this is where the main method is
Need to add database properties to fix the
error
• Open application.properties. Then add these properties, but use your
credentials that you got from for remotemysql.com
Stop and run the webapp again and it works
Run the app, this is where the main method is
Surf to localhost:8080/
Surf to localhost:8080
• You get this error because we haven’t mapped a Controller to handle
this request,
• But we have the CarControllerMysql how can we use that
But we have the CarControllerMysql
• How can we use it? It handle the request for a ”/url”
It handle the request for ”/url” try this
localhost:8080/url
Same error?? Why? We need a view
The problem is the view
We should have a mustche view that contains html to be
shown when we surf to this request localhost:8080/url
Create a mustache view under templates
Use .mustache as file type
Add html to the urlview.mustache
Change in the CarControllerMysql
Change here to match the new urlview.
No need for .mustache as file type here
Stop and run the app again
• surf to localhost:8080/url se how the urlview.msutcha is presente
Shows the urlview.mustache
How to use the Model to set data to be
shown in view
• After all these changes stop and run the app again.
Change to this.
We will use the key ”attribute”
in the urlview to show the text ”Hello world value”
We have the controller, the model and the
view
urlview.mustache
Using request parameters in url
localhost:8080/url?name=Stina
Manage the request parameter name
Set attribute key ”yourname” and it’s value, to show the name in th
Urlview using the attribute key ”yourname”
Create requestaparameter
Using @PathVariable in url
localhost:8080/url/20
Set attribute key and value, to show in urlview
Manage PathVariables
Set defaultValue
For requestparameter
Create PathVariable id in url, using {id}
Stop and run the app
• Test the url using pathvariable and pathvariable+requestparameter
Funkar inte
Using arrays
• Create new @RequestMapping
method
• Create new view,
linksview.mustache
Use dot to get string
element
Start loop
End loop
Stop and run the app again, surf to
localhost:8080/url/links
Use Lists
Create List
and add cars
Use key attribute cars in linksview
Create loop to show id regnr of cars in the list
Stop and run the app again, surf to
localhost:8080/url/links
Our cars
Example slideshow
Create Controller - SlideShowController
Surf to localhost:8080/slideshow
you’re redirect to slideshow/next
Show the view
Set model data to be shown in the view
counter and picture
SlideShowController continue
Set model data to be shwon in the view
Decreament counter to show prev picture from array.
And check it’s bounds, we don’t won’t to have a
ArrayIndexOutOfBounds Exception
Show the view
Create View- slideshow.mustache
picture and counter was sett as model
data in the controller
Form handling
Create Controller –FormController.java
Handles the Posted data
from the form
Shows the form
Show view
Contains posted data;
name of form gui
components
and it’s filled in values
Create a view to show form
-userform.mustache
action=Which postmapping in controller
that handles the posted form data
name attribute is used in
the RequestParam in Controller to get
data from the is particular textfield
userform.mustache- cont
Submit the form to the controller
,which url or postmapping is state in
forms action attribute; action=”/formhandling”
View that show the posted form data-
userformhandling.mustache
Using the keys that where set in the controller based on
posted requestparam from the form.

Más contenido relacionado

La actualidad más candente

How to build Client Side Applications with WordPress and WP-API | #wcmia
How to build Client Side Applications with WordPress and WP-API | #wcmiaHow to build Client Side Applications with WordPress and WP-API | #wcmia
How to build Client Side Applications with WordPress and WP-API | #wcmiaRoy Sivan
 
Building WordPress Client Side Applications with WP and WP-API - #wcmia
Building WordPress Client Side Applications with WP and WP-API - #wcmiaBuilding WordPress Client Side Applications with WP and WP-API - #wcmia
Building WordPress Client Side Applications with WP and WP-API - #wcmiaRoy Sivan
 
Integrate to retrieve data microsoft azure
Integrate to retrieve data microsoft azureIntegrate to retrieve data microsoft azure
Integrate to retrieve data microsoft azureSon Nguyen
 
DevJam 2019 - Building an ALEC Time Engine
DevJam 2019 - Building an ALEC Time EngineDevJam 2019 - Building an ALEC Time Engine
DevJam 2019 - Building an ALEC Time EngineRonny Trommer
 
Ajax control asp.net
Ajax control asp.netAjax control asp.net
Ajax control asp.netSireesh K
 
Intro to Rails Give Camp Atlanta
Intro to Rails Give Camp AtlantaIntro to Rails Give Camp Atlanta
Intro to Rails Give Camp AtlantaJason Noble
 
Introduccion app engine con python
Introduccion app engine con pythonIntroduccion app engine con python
Introduccion app engine con pythonsserrano44
 
Markdown tutorial how to add markdown to rails app using redcarpet and codera...
Markdown tutorial how to add markdown to rails app using redcarpet and codera...Markdown tutorial how to add markdown to rails app using redcarpet and codera...
Markdown tutorial how to add markdown to rails app using redcarpet and codera...Katy Slemon
 
Ruby on rails3 - introduction to rails
Ruby on rails3 - introduction to railsRuby on rails3 - introduction to rails
Ruby on rails3 - introduction to railsEmad Elsaid
 
Quick Way to work with Models and Alloy in Appcelerator Titanium
Quick Way to work with Models and Alloy in Appcelerator TitaniumQuick Way to work with Models and Alloy in Appcelerator Titanium
Quick Way to work with Models and Alloy in Appcelerator TitaniumAaron Saunders
 
Introduction To Asp.Net Ajax
Introduction To Asp.Net AjaxIntroduction To Asp.Net Ajax
Introduction To Asp.Net AjaxJeff Blankenburg
 
One does not simply "Upgrade to Rails 3"
One does not simply "Upgrade to Rails 3"One does not simply "Upgrade to Rails 3"
One does not simply "Upgrade to Rails 3"testflyjets
 
Deploy with maven
Deploy with mavenDeploy with maven
Deploy with mavenSon Nguyen
 
RBC Mod 1: Making a New Rails App
RBC Mod 1: Making a New Rails AppRBC Mod 1: Making a New Rails App
RBC Mod 1: Making a New Rails Appameedahc
 
Active Admin
Active AdminActive Admin
Active AdminGreg Bell
 
Quality Code With Cucumber Presentation
Quality Code With Cucumber PresentationQuality Code With Cucumber Presentation
Quality Code With Cucumber Presentationrailsconf
 

La actualidad más candente (20)

How to build Client Side Applications with WordPress and WP-API | #wcmia
How to build Client Side Applications with WordPress and WP-API | #wcmiaHow to build Client Side Applications with WordPress and WP-API | #wcmia
How to build Client Side Applications with WordPress and WP-API | #wcmia
 
Building WordPress Client Side Applications with WP and WP-API - #wcmia
Building WordPress Client Side Applications with WP and WP-API - #wcmiaBuilding WordPress Client Side Applications with WP and WP-API - #wcmia
Building WordPress Client Side Applications with WP and WP-API - #wcmia
 
Integrate to retrieve data microsoft azure
Integrate to retrieve data microsoft azureIntegrate to retrieve data microsoft azure
Integrate to retrieve data microsoft azure
 
DevJam 2019 - Building an ALEC Time Engine
DevJam 2019 - Building an ALEC Time EngineDevJam 2019 - Building an ALEC Time Engine
DevJam 2019 - Building an ALEC Time Engine
 
Ajax control asp.net
Ajax control asp.netAjax control asp.net
Ajax control asp.net
 
Intro to Rails Give Camp Atlanta
Intro to Rails Give Camp AtlantaIntro to Rails Give Camp Atlanta
Intro to Rails Give Camp Atlanta
 
Introduccion app engine con python
Introduccion app engine con pythonIntroduccion app engine con python
Introduccion app engine con python
 
Markdown tutorial how to add markdown to rails app using redcarpet and codera...
Markdown tutorial how to add markdown to rails app using redcarpet and codera...Markdown tutorial how to add markdown to rails app using redcarpet and codera...
Markdown tutorial how to add markdown to rails app using redcarpet and codera...
 
Rails engine
Rails engineRails engine
Rails engine
 
Catalog display
Catalog displayCatalog display
Catalog display
 
Ruby on rails3 - introduction to rails
Ruby on rails3 - introduction to railsRuby on rails3 - introduction to rails
Ruby on rails3 - introduction to rails
 
Rails engines
Rails enginesRails engines
Rails engines
 
Quick Way to work with Models and Alloy in Appcelerator Titanium
Quick Way to work with Models and Alloy in Appcelerator TitaniumQuick Way to work with Models and Alloy in Appcelerator Titanium
Quick Way to work with Models and Alloy in Appcelerator Titanium
 
Introduction To Asp.Net Ajax
Introduction To Asp.Net AjaxIntroduction To Asp.Net Ajax
Introduction To Asp.Net Ajax
 
One does not simply "Upgrade to Rails 3"
One does not simply "Upgrade to Rails 3"One does not simply "Upgrade to Rails 3"
One does not simply "Upgrade to Rails 3"
 
Deploy with maven
Deploy with mavenDeploy with maven
Deploy with maven
 
Ember components
Ember componentsEmber components
Ember components
 
RBC Mod 1: Making a New Rails App
RBC Mod 1: Making a New Rails AppRBC Mod 1: Making a New Rails App
RBC Mod 1: Making a New Rails App
 
Active Admin
Active AdminActive Admin
Active Admin
 
Quality Code With Cucumber Presentation
Quality Code With Cucumber PresentationQuality Code With Cucumber Presentation
Quality Code With Cucumber Presentation
 

Similar a Java spring mysql without hibernate(2) (1)

ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introductionTomi Juhola
 
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIsCustom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIsAkhil Mittal
 
How to develop a gateway service using code based implementation
How to develop a gateway service using code based implementationHow to develop a gateway service using code based implementation
How to develop a gateway service using code based implementationnitin2517
 
Adding User Management to Node.js
Adding User Management to Node.jsAdding User Management to Node.js
Adding User Management to Node.jsDev_Events
 
Azure Functions Real World Examples
Azure Functions Real World Examples Azure Functions Real World Examples
Azure Functions Real World Examples Yochay Kiriaty
 
Ruby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter BootstrapRuby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter BootstrapMarcio Marinho
 
03 asp.net session04
03 asp.net session0403 asp.net session04
03 asp.net session04Vivek chan
 
294151805 end-to-end-o data-service-sapui5-application
294151805 end-to-end-o data-service-sapui5-application294151805 end-to-end-o data-service-sapui5-application
294151805 end-to-end-o data-service-sapui5-applicationFaina Fridman
 
AngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIAngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIEric Wise
 
Lecture 4_Laravel Controller and Data Pass-Route.pptx
Lecture 4_Laravel Controller and Data Pass-Route.pptxLecture 4_Laravel Controller and Data Pass-Route.pptx
Lecture 4_Laravel Controller and Data Pass-Route.pptxSaziaRahman
 
Web driver selenium simplified
Web driver selenium simplifiedWeb driver selenium simplified
Web driver selenium simplifiedVikas Singh
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCMaarten Balliauw
 
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
E2E testing Single Page Apps and APIs with Cucumber.js and PuppeteerE2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
E2E testing Single Page Apps and APIs with Cucumber.js and PuppeteerPaul Jensen
 
Ruby on rails integration testing with minitest and capybara
Ruby on rails integration testing with minitest and capybaraRuby on rails integration testing with minitest and capybara
Ruby on rails integration testing with minitest and capybaraAndolasoft Inc
 
JS Fest 2019. Minko Gechev. Building Fast Angular Applications by Default
JS Fest 2019. Minko Gechev. Building Fast Angular Applications by DefaultJS Fest 2019. Minko Gechev. Building Fast Angular Applications by Default
JS Fest 2019. Minko Gechev. Building Fast Angular Applications by DefaultJSFestUA
 
CTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCCTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCBarry Gervin
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteorSapna Upreti
 
Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To MvcVolkan Uzun
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...Paul Jensen
 

Similar a Java spring mysql without hibernate(2) (1) (20)

ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introduction
 
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIsCustom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
 
How to develop a gateway service using code based implementation
How to develop a gateway service using code based implementationHow to develop a gateway service using code based implementation
How to develop a gateway service using code based implementation
 
Adding User Management to Node.js
Adding User Management to Node.jsAdding User Management to Node.js
Adding User Management to Node.js
 
Azure Functions Real World Examples
Azure Functions Real World Examples Azure Functions Real World Examples
Azure Functions Real World Examples
 
Ruby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter BootstrapRuby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter Bootstrap
 
03 asp.net session04
03 asp.net session0403 asp.net session04
03 asp.net session04
 
294151805 end-to-end-o data-service-sapui5-application
294151805 end-to-end-o data-service-sapui5-application294151805 end-to-end-o data-service-sapui5-application
294151805 end-to-end-o data-service-sapui5-application
 
AngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIAngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPI
 
Lecture 4_Laravel Controller and Data Pass-Route.pptx
Lecture 4_Laravel Controller and Data Pass-Route.pptxLecture 4_Laravel Controller and Data Pass-Route.pptx
Lecture 4_Laravel Controller and Data Pass-Route.pptx
 
Web driver selenium simplified
Web driver selenium simplifiedWeb driver selenium simplified
Web driver selenium simplified
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
Dancing with websocket
Dancing with websocketDancing with websocket
Dancing with websocket
 
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
E2E testing Single Page Apps and APIs with Cucumber.js and PuppeteerE2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
 
Ruby on rails integration testing with minitest and capybara
Ruby on rails integration testing with minitest and capybaraRuby on rails integration testing with minitest and capybara
Ruby on rails integration testing with minitest and capybara
 
JS Fest 2019. Minko Gechev. Building Fast Angular Applications by Default
JS Fest 2019. Minko Gechev. Building Fast Angular Applications by DefaultJS Fest 2019. Minko Gechev. Building Fast Angular Applications by Default
JS Fest 2019. Minko Gechev. Building Fast Angular Applications by Default
 
CTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCCTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVC
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteor
 
Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To Mvc
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
 

Último

NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdfNewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdfKhaled Al Awadi
 
Buy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy Verified Accounts
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCRashishs7044
 
Call Girls in DELHI Cantt, ( Call Me )-8377877756-Female Escort- In Delhi / Ncr
Call Girls in DELHI Cantt, ( Call Me )-8377877756-Female Escort- In Delhi / NcrCall Girls in DELHI Cantt, ( Call Me )-8377877756-Female Escort- In Delhi / Ncr
Call Girls in DELHI Cantt, ( Call Me )-8377877756-Female Escort- In Delhi / Ncrdollysharma2066
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...ssuserf63bd7
 
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort ServiceCall US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Servicecallgirls2057
 
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...ShrutiBose4
 
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCRashishs7044
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Pereraictsugar
 
Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Kirill Klimov
 
Intro to BCG's Carbon Emissions Benchmark_vF.pdf
Intro to BCG's Carbon Emissions Benchmark_vF.pdfIntro to BCG's Carbon Emissions Benchmark_vF.pdf
Intro to BCG's Carbon Emissions Benchmark_vF.pdfpollardmorgan
 
Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Riya Pathan
 
Investment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy CheruiyotInvestment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy Cheruiyotictsugar
 
2024 Numerator Consumer Study of Cannabis Usage
2024 Numerator Consumer Study of Cannabis Usage2024 Numerator Consumer Study of Cannabis Usage
2024 Numerator Consumer Study of Cannabis UsageNeil Kimberley
 
Memorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMMemorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMVoces Mineras
 
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607dollysharma2066
 
8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCRashishs7044
 
MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?Olivia Kresic
 

Último (20)

NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdfNewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
 
Buy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail Accounts
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
 
Call Girls in DELHI Cantt, ( Call Me )-8377877756-Female Escort- In Delhi / Ncr
Call Girls in DELHI Cantt, ( Call Me )-8377877756-Female Escort- In Delhi / NcrCall Girls in DELHI Cantt, ( Call Me )-8377877756-Female Escort- In Delhi / Ncr
Call Girls in DELHI Cantt, ( Call Me )-8377877756-Female Escort- In Delhi / Ncr
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...
 
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort ServiceCall US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
 
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
 
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Perera
 
Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024
 
Intro to BCG's Carbon Emissions Benchmark_vF.pdf
Intro to BCG's Carbon Emissions Benchmark_vF.pdfIntro to BCG's Carbon Emissions Benchmark_vF.pdf
Intro to BCG's Carbon Emissions Benchmark_vF.pdf
 
Call Us ➥9319373153▻Call Girls In North Goa
Call Us ➥9319373153▻Call Girls In North GoaCall Us ➥9319373153▻Call Girls In North Goa
Call Us ➥9319373153▻Call Girls In North Goa
 
Enjoy ➥8448380779▻ Call Girls In Sector 18 Noida Escorts Delhi NCR
Enjoy ➥8448380779▻ Call Girls In Sector 18 Noida Escorts Delhi NCREnjoy ➥8448380779▻ Call Girls In Sector 18 Noida Escorts Delhi NCR
Enjoy ➥8448380779▻ Call Girls In Sector 18 Noida Escorts Delhi NCR
 
Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737
 
Investment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy CheruiyotInvestment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy Cheruiyot
 
2024 Numerator Consumer Study of Cannabis Usage
2024 Numerator Consumer Study of Cannabis Usage2024 Numerator Consumer Study of Cannabis Usage
2024 Numerator Consumer Study of Cannabis Usage
 
Memorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMMemorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQM
 
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
 
8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR
 
MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?
 

Java spring mysql without hibernate(2) (1)

  • 1. Java Spring MVC using MySQL
  • 2. What are we building? • A MVC webapplikation for CRUD operations
  • 4. What we need to create this app • MySql Database • Spring Initializr to set up the Spring webapp
  • 5. Create account and database at https://remotemysql.com/ • Create tables in phpmyadmin • https://www.liquidweb.com/kb/creating-tables-in-a-database-with- phpmyadmin/
  • 6. NB-Springboot-Plugins for netbeans 11/12 • http://plugins.netbeans.org/plugin/67888/nb-springboot • https://github.com/AlexFalappa/nb-springboot/wiki/Quick-Tour • https://www.techgalery.com/2019/01/how-to-create-spring-boot- project-using.html From meny Tools/ plugins
  • 7. Spring initializr • Got to https://start.spring.io/ • Add these dependencies so we can create a spring web app and database connection rename
  • 8. Move the download zip file to more suitable folder
  • 9. Open netbeans import the zip file • Import the saved zip file in netbeans File->import->from zip • Will be a new project.
  • 10. Intro Spring creating Controllers and Views 1. Any incoming request that comes to the web application will be sent to Front Controller (a Dispatcher Servlet) 2. Front Controller decides to which (Controller) it has to hand over the request, based on the request headers. 3. Controller that took the request, processes the request, by sending it to suitable service class. 4. After all processing is done, Controller receives the model from the Service or Data Access layer. 5. Controller sends the model to the Front Controller 6. Dispatcher servlet finds the view template, using view resolver and send the model to it. 7. Using View template and the model a view page is build and sent back to the Front Controller. 8. Front controller sends the constructed view page to the browser to render it for the user requested.
  • 11. Create package for our controllers and then add a CarControllerMysql • Create an controllers package • Name it controllers • Add new java Controller class in that package • Name it CarControllerMysql To see this Controller class you need the plugin for NB-springboot installed
  • 12. The auto genereted code for the new TestController class
  • 13. Run the web app, you get an error about databases Run the app, this is where the main method is
  • 14. Need to add database properties to fix the error • Open application.properties. Then add these properties, but use your credentials that you got from for remotemysql.com
  • 15. Stop and run the webapp again and it works Run the app, this is where the main method is Surf to localhost:8080/
  • 16. Surf to localhost:8080 • You get this error because we haven’t mapped a Controller to handle this request, • But we have the CarControllerMysql how can we use that
  • 17. But we have the CarControllerMysql • How can we use it? It handle the request for a ”/url” It handle the request for ”/url” try this localhost:8080/url Same error?? Why? We need a view
  • 18. The problem is the view We should have a mustche view that contains html to be shown when we surf to this request localhost:8080/url
  • 19. Create a mustache view under templates Use .mustache as file type
  • 20. Add html to the urlview.mustache Change in the CarControllerMysql Change here to match the new urlview. No need for .mustache as file type here
  • 21. Stop and run the app again • surf to localhost:8080/url se how the urlview.msutcha is presente Shows the urlview.mustache
  • 22. How to use the Model to set data to be shown in view • After all these changes stop and run the app again. Change to this. We will use the key ”attribute” in the urlview to show the text ”Hello world value”
  • 23. We have the controller, the model and the view urlview.mustache
  • 24. Using request parameters in url localhost:8080/url?name=Stina Manage the request parameter name Set attribute key ”yourname” and it’s value, to show the name in th Urlview using the attribute key ”yourname” Create requestaparameter
  • 25. Using @PathVariable in url localhost:8080/url/20 Set attribute key and value, to show in urlview Manage PathVariables Set defaultValue For requestparameter Create PathVariable id in url, using {id}
  • 26. Stop and run the app • Test the url using pathvariable and pathvariable+requestparameter Funkar inte
  • 27. Using arrays • Create new @RequestMapping method • Create new view, linksview.mustache Use dot to get string element Start loop End loop
  • 28. Stop and run the app again, surf to localhost:8080/url/links
  • 29. Use Lists Create List and add cars Use key attribute cars in linksview Create loop to show id regnr of cars in the list
  • 30. Stop and run the app again, surf to localhost:8080/url/links Our cars
  • 32. Create Controller - SlideShowController Surf to localhost:8080/slideshow you’re redirect to slideshow/next Show the view Set model data to be shown in the view counter and picture
  • 33. SlideShowController continue Set model data to be shwon in the view Decreament counter to show prev picture from array. And check it’s bounds, we don’t won’t to have a ArrayIndexOutOfBounds Exception Show the view
  • 34. Create View- slideshow.mustache picture and counter was sett as model data in the controller
  • 36. Create Controller –FormController.java Handles the Posted data from the form Shows the form Show view Contains posted data; name of form gui components and it’s filled in values
  • 37. Create a view to show form -userform.mustache action=Which postmapping in controller that handles the posted form data name attribute is used in the RequestParam in Controller to get data from the is particular textfield
  • 38. userform.mustache- cont Submit the form to the controller ,which url or postmapping is state in forms action attribute; action=”/formhandling”
  • 39. View that show the posted form data- userformhandling.mustache Using the keys that where set in the controller based on posted requestparam from the form.