Skip to content

Instantly share code, notes, and snippets.

@truongquoc
truongquoc / Mapper.java
Created January 10, 2024 15:57
mapper entity in java
package com.core.platform.mapper;
import com.core.platform.entity.EntityType;
import com.core.platform.model.Model;
public interface Mapper<TModel extends Model, TEntity extends EntityType> {
TEntity modelToEntity(TModel model);
TModel entityToModel(TEntity entity);
}
@truongquoc
truongquoc / lz-evaluate.java
Created October 17, 2023 11:30
stream API
public void lazyEvaluate() {
List<Integer> numbers = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
long count = numbers.stream()
.filter(n -> {
System.out.println("Filtering: " + n);
return n % 2 == 0;
})
.map(n -> {
System.out.println("Mapping: " + n);
@Test
public void test() {
List<String> words = Arrays.asList("apple", "banana", "cherry", "date", "elderberry");
// Declare a Stream that filters words starting with the letter 'a'
Stream<String> filteredWords = words.stream().peek(System.out::println).filter(word -> word.startsWith("a"));
filteredWords.forEach(System.out::println);
boolean isValidate = filteredWords.count() > 0;
@truongquoc
truongquoc / DataSourceConfiguration.java
Last active October 17, 2023 08:55
DataSourceConfiguration
package com.core.platform.config;
import org.springframework.boot.autoconfigure.flyway.FlywayProperties;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import java.util.HashMap;
@truongquoc
truongquoc / AuthService.java
Last active October 17, 2023 08:41
CustomBeanConfiguration
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
@Service
public class AuthService {
private final RestTemplate customRestTemplate;
@Autowired
public AuthService(RestTemplate customRestTemplate) {
@truongquoc
truongquoc / AuthController.java
Last active October 17, 2023 07:01
Injection dependency
package com.example.demo.controller;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class AuthController {