SlideShare ist ein Scribd-Unternehmen logo
1 von 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.

Weitere ähnliche Inhalte

Was ist angesagt?

Catalog display
Catalog displayCatalog display
Catalog display
Jason Noble
 
Rails engines
Rails enginesRails engines
Rails engines
Josh Schramm
 
Introduction To Asp.Net Ajax
Introduction To Asp.Net AjaxIntroduction To Asp.Net Ajax
Introduction To Asp.Net Ajax
Jeff Blankenburg
 
Quality Code With Cucumber Presentation
Quality Code With Cucumber PresentationQuality Code With Cucumber Presentation
Quality Code With Cucumber Presentation
railsconf
 

Was ist angesagt? (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
 

Ähnlich wie Java spring mysql without hibernate(2) (1)

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
Faina Fridman
 
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
SaziaRahman
 

Ähnlich wie 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...
 

KĂźrzlich hochgeladen

Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
amitlee9823
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
Sheetaleventcompany
 
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
lizamodels9
 
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Sheetaleventcompany
 
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Anamikakaur10
 
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service NoidaCall Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
dlhescort
 

KĂźrzlich hochgeladen (20)

Famous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st CenturyFamous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st Century
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptx
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 MonthsSEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
 
Business Model Canvas (BMC)- A new venture concept
Business Model Canvas (BMC)-  A new venture conceptBusiness Model Canvas (BMC)-  A new venture concept
Business Model Canvas (BMC)- A new venture concept
 
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
 
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort ServiceMalegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
 
Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024
 
Falcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to ProsperityFalcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to Prosperity
 
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
PHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation FinalPHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation Final
 
Falcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in indiaFalcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in india
 
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
 
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
 
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
 
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLBAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
 
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service NoidaCall Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
 
Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investors
 

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.