Spring Boot s1
Spring Boot s1
It consists of Views. i.e., contains all the This layer is the It is responsible for
the front-end part of the business logic. It equivalent of the performing the CRUD
application, consists of services Repository interface. operations.
is the equivalent of the classes. It is We write database This layer is simply the
Controller class. The responsible for queries inside this actual database that you
Controller class handles validation and interface. decide to use to build
all the incoming REST authorization. Is the only layer that your application
API requests (GET, communicates with the
POST, PUT, DELETE, Business layer and the
PATCH) from the Client. Database layer.
Architecture (SPRING BOOT WORKFLOW)
1.The Client makes an HTTP request.
Une fois on a choisie les deux dépendances (spring dev tools && spring web) pour
démarrer notre premier projet on fait download pour enregistrer le projet qui va être
importer par la suite par un IDE
Building First Application
1. Apres avoir installe jdk:
1. Cliquer sur bouton droit sur poste de travail / propriété /paramètre avancé de système/ variable
d’environement/ path (modifier) /ajouter le chemein de jdk (c:/program/java/jdk11,3) /selectionner et
ok
2. Allant sur sts window/ preference
3. Chercher « installed jre »
4. Vous trouvez par defaut
5. Cliquer et supprimer
6. Cliquer sur add
7. Standar vm
8. On chercher ou il existe notre JDK
9, (selection de dossier)
sélectionner la case à cocher
10, apply and close
Building First Application
Cliquer de nouveau sur préférences:
Chercher installed jre / execution envirment
Choisir le version de jdk
Building First Application
</properties>
Et par la suite (bouton droit sur le projet/ maven /update project /selection de projet/ cocher la case « force
update ….»
Some settings Application.properties
server.port=8081
spring.datasource.url=jdbc:mysql://localhost:3306/dbgestionusers?
useUnicode=yes&useJDBCCompliantTimezoneShift=true&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
Example: Add user
Test controller
@RestController
public class TestController {
@RestController
//@RequestMapping(value = "/test", method = RequestMethod.GET)
public class UserController {
//@GetMapping("/{param}/{lastName}")
/*public String helloWorld(@PathVariable String param, @PathVariable
@Autowired
String lastName)
UserService userServ;
{
@PostMapping("/addUser")
return "Bonjour"+"---"+param+ "----"+lastName;
public User addUser(@RequestBody User u)
}*/
{
@GetMapping("/test")
return userServ.addUser(u);
public String helloWorld()
}
{
}
return "Bonjour !!! i'am here !!!";
}
User controller }
Example: Add user
Implement user service interface
@Service
public class UserService implements IUserService {
user service interface @Autowired
UserRepository userRep;
public interface IUserService {
@Override
public User addUser(User u) {
public User addUser (User u);
// TODO Auto-generated method stub
}
return userRep.save(u);
}
}
User Repository
public interface UserRepository extends CrudRepository<User, Long>
{ }
Diagramme de classe