Skip to content

Instantly share code, notes, and snippets.

@krams915
krams915 / UserController.java
Created December 12, 2012 14:37
Spring Thymeleaf UserController snippet
@Controller
@RequestMapping("/users")
public class UserController {
@RequestMapping
public String getUsersPage(ModelMap model) {
Pageable pageRequest = new PageRequest(0, 10);
Page<User> users = repository.findAll(pageRequest);
model.addAttribute("users", UserMapper.map(users));
model.addAttribute("commanduser", new UserDto());
@krams915
krams915 / users.html
Created December 12, 2012 14:29
Spring Thymeleaf users.html snippet
<form action="#" th:action="@{/users/create}" th:object="${commanduser}" method="post">
....
<tr>
<td><input type="text" hidden="hidden" th:field="*{id}"/>
<input type="text" th:field="*{firstName}"/></td>
<td><input type="text" th:field="*{lastName}"/></td>
<td><input type="text" th:field="*{username}"/></td>
<td><select th:field="*{role}">
<option th:each="role : ${allRoles}" th:value="${role}"
th:text="#{${'user.role.' + role}}">Access Type 1</option>
@krams915
krams915 / UserDto.java
Created December 12, 2012 14:25
Spring Thymeleaf UserDto.java
package org.krams.response;
import java.io.Serializable;
public class UserDto implements Serializable {
private Long id;
private String firstName;
private String lastName;
private String username;
@krams915
krams915 / spring-servlet.xml
Created December 10, 2012 14:36
Spring Social spring-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd">
@krams915
krams915 / spring-data.xml
Created December 10, 2012 14:35
Spring Social spring-data.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
@krams915
krams915 / applicationContext.xml
Created December 10, 2012 14:34
Spring Social applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
@krams915
krams915 / web.xml
Created December 10, 2012 14:33
Spring Social web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Spring Social Tutorial</display-name>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
@krams915
krams915 / RepositoryBasedUserDetailsService.java
Created December 10, 2012 03:46
Spring Social RepositoryBasedUserDetailsService.java
package org.krams.service;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.krams.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
@krams915
krams915 / UserService.java
Created December 10, 2012 03:45
Spring Social UserService.java
package org.krams.service;
import org.krams.domain.User;
import org.krams.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional
@krams915
krams915 / UserDto.java
Created December 10, 2012 03:45
Spring Social UserDto.java
package org.krams.response;
import java.io.Serializable;
public class UserDto implements Serializable {
private static final long serialVersionUID = -5488702255320352709L;
private Long id;
private String firstName;
private String lastName;