Definito il nostro modello User, vogliamo creare alcuni servizi su di esso. In particolare vogliamo dare la possibilità al sistema di creare nuovi utenti, eliminarli, aggiornarli e prelevarli tutti in una lista.
Per fare questo creeremo un’interfaccia UserService.java.
[codebox 1]
L’interfaccia sarà poi implementata dalla classe UserServiceImpl.java
[codebox 2]
Adesso creiamo una classe SampleAction richiamata da struts in modo da scrivere un minimo di logica di business.
In questo tutorial verrà spiegato come sviluppare una semplice web application utilizzando tecnologie come maven, jpa2, struts2, spring e mysql.
Ambiente di lavoro:
MySQL Server
Eclipse + da “Eclipse Market Place” “Maven Integration for Eclipse”
JDK 1.7
Creazione tabella mysql:
Prima di iniziare tutto il lavoro creiamo una tabella che chiameremo user
[codebox 1]
Creazione di un nuovo progetto Maven su Eclipse:
– creiamo un nuovo progetto “maven” su eclipse
– impostiamo maven-archetypes-webapp
– impostiamo grupId e artifactId come in figura
Struttura progetto e configurazione pom.xml
Una volta generato il progetto maven, Eclipse ci propone tutto il progetto come in figura
Il prossimo passo sarà quello di configurare il file pom.xml in modo da personalizzare il building e includere le tecnologie che ci interessano.
In particolare includiamo le dipendenze per: struts2, spring, mysql connector, servlet e jsp, hibernate, log4j e junit.
Dopo di che impostiamo anche il <build> in modo da utilizzare alcuni plugin tra cui il web server jetty.
POM.XML
[codebox 2]
Manage Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Sempre attivo
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.