Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Master Springboot. My lecture 😉

  1. how to find or delete one value or relaled if normal code use loop for list value by loop use duplicate check but new pactice is predicate by predicate is filter not loop for find value

##Exam code loop

       for ( Iterator<User> userIterator = users.iterator(); userIterator.hasNext();){
              User user = userIterator.next();
              if(user.getId() == id){
                   userIterator.remove();
                   break;
              }
          }

predicate

Predicate<?super User> predicate = user -> user.getId() == id;
users.removeIf(predicate);            
  1. UX in response api to user by if user create api by return Response http status and location path in header.
    @PostMapping("/user")
    public ResponseEntity<User> saveUser(@RequestBody User user){
        userDAO.saveUser(user);
        URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(user.getId()).toUri();
        return ResponseEntity.created(location).build();
    }

api document

springdoc-openapi Dependency

<dependency>
   <groupId>org.springdoc</groupId>
   <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
   <version>2.0.0</version>
</dependency>

when install re maven and open url

http://localhost:8080/swagger-ui/index.html

if employee need format data default is json but if need xml mush add depedency

<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
  <version>2.0.0</version>
</dependency>

and add parameter

image

hateoas (HAL Hyper Application Language)

hateoas is config identify link api for ux give easy understand
	<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-hateoas</artifactId>
		</dependency>

Exam code

    @GetMapping(path = "user/hateoas/{id}")
    public EntityModel<User> userEntityModelPerson1(@PathVariable int id) {
        EntityModel entityModel = EntityModel.of( userDAO.findOneUser(id));
        WebMvcLinkBuilder linkFindAllUser = WebMvcLinkBuilder.linkTo(WebMvcLinkBuilder.methodOn(this.getClass()).findALlUser());
        WebMvcLinkBuilder linkHelloBean = WebMvcLinkBuilder.linkTo(WebMvcLinkBuilder.methodOn(this.getClass()).HelloBean());
        WebMvcLinkBuilder linkDeleteMyUser = WebMvcLinkBuilder.linkTo(WebMvcLinkBuilder.methodOn(this.getClass()).deleteUser(id));

        entityModel.add( linkFindAllUser.withRel("all-user").withTitle("title all users") , linkHelloBean.withRel("hello-bean") , linkDeleteMyUser.withRel("delete-user").withTitle("delete user") );
        return entityModel;
    }

image

Filtering have 2 type is staic and dynamic filtering

static filterinig is config output json ? so static filtering use json ignore (level attribute) and json ignore property (level class)

  • json property is rename key name of the coloum.

image image image

Dynamic filter (Json filter)

  • Mapping json by use service is parameter
  • Filter provider config by key json filter and filter json parameter
  • Filter provider have 3 type is filter out except , serialize except and serialize all image image

Monitor API by actuator (http://localhost:8080/actuator)

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>

if want unlock all api insert my code in application.property

management.endpoints.web.exposure.include=*  

image

Hal Explorer

  • it is UI of API by easy using and same swagger but easy more that swagger
  • but explorer use for see link if use hateoas config link for user understance that what can use api ? Solution install Hal Explorer
<dependency>
			<groupId>org.springframework.data</groupId>
			<artifactId>spring-data-rest-hal-explorer</artifactId>
		</dependency>

link http://localhost:8080/explorer/index.html#

image

spring boot basic security

when run program will be login interface give username and password

<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-security</artifactId>
		</dependency>

if not config in application property

  • default username is user
  • default password is terminal

image

but if config in application property

spring.security.user.name= admin
spring.security.user.password= admin
  • user and password is that config in application property.

image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages