随笔分类 - Java
摘要:public class Code { public static void main(String[] args) { Arrays.asList("red", "green", "blue") .stream() .sorted() .findFirst() .ifPresent(System.
阅读全文
摘要:public class Code { public static void main(String[] args) { List<String> names = Arrays.asList("Paul", "Jane", "Sam", "Michaela"); // Way to sort pri
阅读全文
摘要:Testing JWT proteceted endpoint: /** * HTTP POST /tours/{tourId}/ratings */ @Test public void createTourRating() throws Exception { restTemplate.excha
阅读全文
摘要:Provider: package com.example.ec.security; import com.example.ec.domain.Role; import io.jsonwebtoken.*; import org.springframework.beans.factory.annot
阅读全文
摘要:package com.example.ec.security; import com.example.ec.repo.RoleRepository; import org.springframework.beans.factory.annotation.Autowired; import org.
阅读全文
摘要:Controller: @RestController @RequestMapping(path = "/ratings") public class RatingController { private static final Logger LOGGER = LoggerFactory.getL
阅读全文
摘要:Service: package com.example.ec.service; import com.example.ec.domain.Tour; import com.example.ec.domain.TourRating; import com.example.ec.repo.TourRa
阅读全文
摘要:If one request failed, we want to keep database untouched as if the request never happen. Spring makes it easy to add: @Transactional To the method or
阅读全文
摘要:Repo: public interface CourseRepository extends CrudRepository<Course,Integer>{ Optional<Course> findByName(String name); @Query("Select new com.examp
阅读全文
摘要:@Test public void queryByExample() { System.out.println("\nFind the Department with the name 'Humanities' \n" + departmentRepository.findOne(Example.o
阅读全文
摘要:package com.example.university.repo; import com.example.university.domain.Staff; import org.springframework.data.domain.Page; import org.springframewo
阅读全文
摘要:package com.example.university.repo; import com.example.university.domain.Staff; import com.example.university.domain.Student; import com.example.univ
阅读全文
摘要:Entity: package com.example.university.domain; import javax.persistence.*; import java.util.ArrayList; import java.util.List; /** * JPA Entity represe
阅读全文
摘要:All features of CrudRepository plus: void flush(); saveAndFlush() delteInBatch() delteAllInBatch() package com.example.university.repo; import com.exa
阅读全文
摘要:domain/Course.java package com.example.university.domain; import javax.persistence.*; /** * JPA Entity for a Course offered at the University. * <p> *
阅读全文
摘要:@OneToMany: One Student To Many Courses. @JoinTable(name = "Enrollment"): Join Enrollment table. joinColumns: with use "student_id" to link Student an
阅读全文
摘要:Repo: package com.example.ec.repo; import com.example.ec.domain.TourRating; import com.example.ec.domain.TourRatingPk; import org.springframework.data
阅读全文
摘要:package com.example.ec.web; import com.example.ec.domain.Tour; import com.example.ec.domain.TourRating; import com.example.ec.domain.TourRatingPk; imp
阅读全文
摘要:Controller: package com.example.ec.web; import com.example.ec.domain.Tour; import com.example.ec.domain.TourRating; import com.example.ec.domain.TourR
阅读全文
摘要:In software, we come across many use cases when we need to have a composite primary key to define an entry in a table. Composite primary keys are keys
阅读全文