Skip to content

Instantly share code, notes, and snippets.

View ntxinh's full-sized avatar
💭
❤️ .NET & JavaScript

Xinh Nguyen ntxinh

💭
❤️ .NET & JavaScript
View GitHub Profile
@ntxinh
ntxinh / CandidateProfileRepository.java
Last active February 2, 2018 03:51
Creating Queries Using the JPQL (Java Persistence Query Language)
package repository;
@Repository
public interface CandidateProfileRepository
extends BaseRepository<CandidateProfile, Long>, CandidateProfileRepositoryCustom {
}
@ntxinh
ntxinh / filter.java
Last active February 3, 2018 03:58
Java 8 - Stream
// filter(), findAny() and orElse()
Item item = items.stream()
.filter(item -> Objects.equals(item.getId(), itemId))
.findAny()
.orElse(null);
// findFirst
Optional<Item> itemOpt = items.stream()
.filter(item -> Objects.equals(item.getId(), itemId))
.findFirst();
// Java 9
private static final Map<String, String> test = Map.of("a", "b", "c", "d");
private static final Map<String, String> test2 = Map.ofEntries(
entry("a", "b"),
entry("c", "d")
);
// Java 8
HashMap<String, String> h = new HashMap<String, String>() {{
put("a","b");
@ntxinh
ntxinh / string.java
Created February 3, 2018 03:11
Java - String
import org.apache.commons.lang3.StringUtils;
String a = null;
System.out.println(StringUtils.defaultString(a));
@ntxinh
ntxinh / hql.java
Created February 3, 2018 03:20
Java - HQL
// Inverse boolean value
SELECT (ca.deleteFlag=false)
@ntxinh
ntxinh / application.yml
Created February 3, 2018 03:49
Spring boot Send Mail
spring:
mail:
default-encoding: UTF-8
host: localhost
username: anyname
password: anypassword
port: 2525
properties:
mail:
smtp:
@ntxinh
ntxinh / Logging.java
Last active February 3, 2018 04:02
Java - Logging
// 1 Param
LOGGER.log(Level.INFO, "Hello {0}", "World"});
// Many params
LOGGER.log(Level.INFO, "Hello {0} {1}", new Object[] {"World", "!"});
@ntxinh
ntxinh / List.java
Last active February 3, 2018 04:08
Java - Collection
Collections.singletonList(object)
Collections.emptyList() == new ArrayList<>()
@ntxinh
ntxinh / ResponseEntity.java
Created February 3, 2018 04:02
Java - Spring MVC
return ResponseEntity.badRequest().body(response);
return ResponseEntity.ok(response);
@ntxinh
ntxinh / index.jsp
Created February 3, 2018 04:03
Java - Apache titles
<tiles:importAttribute name="stage"/>
<tiles:importAttribute name="qualified"/>
<tiles:importAttribute name="candidates"/>
<c:out value="${stage}" />
<c:out value="${qualified}" />