Skip to content

Instantly share code, notes, and snippets.

$(function () {
const url = location.protocol + '//' + location.host + location.pathname;
$('.sortable>th').on('click', function () {
const sort = $(this).data('sort');
if (!location.search) {
if ($(this).hasClass('sortedASC')) {
window.location.href = url + '?sort=' + sort + ',' + 'DESC';
.sortedASC:after {
cursor: pointer;
opacity: 0.8;
content: '\25B2';
}
.sortedDESC:after {
cursor: pointer;
opacity: 0.8;
content: '\25BC';
}
@Service
public class PagingAndSortingService {
public String[] setSortInfoArray(Page<?> page) {
final String [] sortInfoArray = page.getSort().toString().split(":");
return Arrays.stream(sortInfoArray).map(String::trim).toArray(String[]::new);
}
public String getSortClassName(final String [] sortInfoArray,
final String propertyName) {
<thead>
<!-- sortInfoArray[0] = sorting property (e.g: project.customer),
sortInfoArray[1] = sorting direction (asc/desc) -->
<tr class="sortable"
th:with="sortInfoArray = ${@pagingAndSortingService.setSortInfoArray(workLogs)}">
<th data-sort="id"
th:classappend="${@pagingAndSortingService.getSortClassName(sortInfoArray, 'id')}">
Id
</th>
<th data-sort="employee"
@Repository
public interface WorkLogRepository extends PagingAndSortingRepository<WorkLog, Long> {
@Override
Page<WorkLog> findAll(Pageable pageable);
}
@Controller
@AllArgsConstructor
@RequestMapping("/work-logs")
public class WorkLogController {
private final WorkLogService workLogService;
@GetMapping
public String index(Model model, Pageable pageable){
model.addAttribute("workLogs", workLogService.getWorkLogs(pageable));
@suleymancan
suleymancan / JAXRS_Part02_servicedefaultValue_CarResourceDefaultValue.java
Created June 15, 2018 00:39
github/suleymancan->repositories: tutorials/WebService/JAXRS_Part02/src/service.defaultValue
/**
*
*/
package service.defaultValue;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
@suleymancan
suleymancan / JAXRS_Part02_servicebeanParam_ProductResourceBeanParam.java
Created June 15, 2018 00:27
github/suleymancan->repositories: tutorials/WebService/JAXRS_Part02/src/service.beanParam
/**
*
*/
package service.beanParam;
import javax.ws.rs.BeanParam;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
/**
@suleymancan
suleymancan / JAXRS_Part02_servicebeanParam_Product.java
Created June 15, 2018 00:27
github/suleymancan->repositories: tutorials/WebService/JAXRS_Part02/src/service.beanParam
/**
*
*/
package service.beanParam;
import javax.ws.rs.MatrixParam;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
/**
@suleymancan
suleymancan / JAXRS_Part02_servicecookieParam_UserResourceCookieParam.java
Created June 15, 2018 00:05
github/suleymancan->repositories: tutorials/WebService/JAXRS_Part02/src/service.cookieParam
/**
*
*/
package service.cookieParam;
import javax.ws.rs.CookieParam;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;