随笔分类 -  Java

摘要:Assumption: Run the testing code only if when the condition is match, otherwise, test will be ignored @Test void runTestIf() { System.out.print("Curre 阅读全文
posted @ 2022-08-04 18:28 Zhentiw 阅读(22) 评论(0) 推荐(0) 编辑
摘要:Basic Query public interface BookRepository extends CrudRepository<Book, Long> { @Query("SELECT b from Book b WHERE b.available = true") List<Book> fi 阅读全文
posted @ 2022-05-20 15:59 Zhentiw 阅读(125) 评论(0) 推荐(0) 编辑
摘要:Entity: Employee.java package com.skillsoft.springdatajpa.model; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import java 阅读全文
posted @ 2022-05-19 03:05 Zhentiw 阅读(48) 评论(0) 推荐(0) 编辑
摘要:Stream<Employee> emps = ... TreeSet<Employee> tree = emps.collect( Collectors.toCollection( () -> new TreeSet<Employee>( Comparator.comparingInt(Emplo 阅读全文
posted @ 2021-01-22 20:17 Zhentiw 阅读(137) 评论(0) 推荐(0) 编辑
摘要:To void: forEach, forEachOrdered, peek stream.peek(System.out::println) // print without termination .filter(n -> n > 0) .distinct() .limit(10) .forEa 阅读全文
posted @ 2021-01-21 03:19 Zhentiw 阅读(78) 评论(0) 推荐(0) 编辑
摘要:Sream<Employee> emps = ...; emps.sorted( Comparator.comparingInt(Employee::getSalary) .reversed() ).limit(10) .map(Employee::getName) .forEachOrdered( 阅读全文
posted @ 2021-01-18 22:43 Zhentiw 阅读(416) 评论(0) 推荐(0) 编辑
摘要:Why need to use @ResponseEntity, first let's see what problem we might have when we don't use it. @RestController public class ProductsRestController 阅读全文
posted @ 2021-01-15 21:38 Zhentiw 阅读(86) 评论(0) 推荐(0) 编辑
摘要:Interceptor jump in before controller. So request may not reach controller if Pre-process is not ok. Demo: package com.test.hplus.interceptors; import 阅读全文
posted @ 2021-01-15 19:56 Zhentiw 阅读(94) 评论(0) 推荐(0) 编辑
摘要:@ControllerAdvice public class DefaultAttributeController { // apply default value @ModelAttribute("newuser") public User getDefaultUser() { return ne 阅读全文
posted @ 2021-01-13 19:40 Zhentiw 阅读(116) 评论(0) 推荐(0) 编辑
摘要:Create file: // this apply to all the controllers @ControllerAdvice public class ApplicationExceptionHandler { @ExceptionHandler(ApplicationException. 阅读全文
posted @ 2021-01-13 19:36 Zhentiw 阅读(74) 评论(0) 推荐(0) 编辑
摘要:Controller: @Controller public class LoginController { private UserRepository userRepository; @PostMapping("/login") public String login(@ModelAttribu 阅读全文
posted @ 2021-01-13 01:18 Zhentiw 阅读(56) 评论(0) 推荐(0) 编辑
摘要:If you need to convert a deep nested object struture, you cannot just use @InitBinder, you need to build a custom convertor: Exp: conver city prop in 阅读全文
posted @ 2021-01-13 00:54 Zhentiw 阅读(110) 评论(0) 推荐(0) 编辑
摘要:For example, from the client, it send date as string to BE. But BE requires date to be a Date instead of String. Controller: .. @Autowired private Use 阅读全文
posted @ 2021-01-13 00:39 Zhentiw 阅读(86) 评论(0) 推荐(0) 编辑
摘要:User entity: import javax.validation.constraints.*; @Entity public class User { @Id private int id; @Size(min = 6, message = "Username cannot be less 阅读全文
posted @ 2021-01-12 20:54 Zhentiw 阅读(76) 评论(0) 推荐(0) 编辑
摘要:@Repository public interface ProductRepository extends CrudRepository<Product, Integer> { @Query("select p from Product p where p.name like %:name%") 阅读全文
posted @ 2021-01-12 15:49 Zhentiw 阅读(147) 评论(0) 推荐(0) 编辑
摘要:Set<Book> lib = ... lib.stream() .flatMap(book -> book.getWords().stream()) .distinct() .forEach(System.out::println); 阅读全文
posted @ 2021-01-07 03:22 Zhentiw 阅读(105) 评论(0) 推荐(0) 编辑
摘要:Entity: package com.frankmoley.security.app.auth; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Generated 阅读全文
posted @ 2021-01-06 02:42 Zhentiw 阅读(113) 评论(0) 推荐(0) 编辑
摘要:Code to improve: final Collection<DiscussionTopics> topics = s.getTopics(); final boolean anyTopics = topics != null && !topics.isEmpty(); Change to: 阅读全文
posted @ 2021-01-05 17:05 Zhentiw 阅读(55) 评论(0) 推荐(0) 编辑
摘要:Module defined what can be used inside the module package and what outside world can use inside our module. module-info.java /* * To change this licen 阅读全文
posted @ 2021-01-04 02:44 Zhentiw 阅读(92) 评论(0) 推荐(0) 编辑
摘要:public class Code { public static void main(String[] args) { IntStreams.range(1,4) .forEach(System.out::println); // 1 2 3 Arrays.stream(new int[] {1, 阅读全文
posted @ 2020-12-30 03:47 Zhentiw 阅读(73) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示