Skip to content

Instantly share code, notes, and snippets.

View joshlong's full-sized avatar
🍃
i'm on Twitter @starbuxman

Josh Long joshlong

🍃
i'm on Twitter @starbuxman
View GitHub Profile
package org.springsource.examples.spring31.web.config;
// ...
@Configuration
@EnableWebMvc
@ComponentScan(basePackageClasses = { ViewController.class, CustomerService.class })
public class WebMvcConfiguration extends WebMvcConfigurerAdapter {
@Bean
public ViewResolver getViewResolver() {
package org.springsource.examples.spring31.web;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@joshlong
joshlong / gist:5067566
Last active December 14, 2015 09:49
WebMvcConfiguration with resource handling, default servlet and view controllers
package org.springsource.examples.spring31.web.config;
// ...
@Configuration
@EnableWebMvc
@ComponentScan(basePackageClasses = {ViewController.class, CustomerService.class})
public class WebMvcConfiguration extends WebMvcConfigurerAdapter {
// ...
package org.springsource.examples.spring31.web.config;
// ...
@Configuration
@EnableWebMvc
@ComponentScan(basePackageClasses = {ViewController.class, CustomerService.class})
public class WebMvcConfiguration extends WebMvcConfigurerAdapter {
// ...
package org.springsource.examples.spring31.web.config;
// ...
@Configuration
@EnableWebMvc
@ComponentScan(basePackageClasses = {ViewController.class, CustomerService.class})
public class WebMvcConfiguration extends WebMvcConfigurerAdapter {
// ...
@joshlong
joshlong / gist:5114444
Created March 8, 2013 05:40
signin form jsp taglib imports
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
@joshlong
joshlong / gist:5114560
Created March 8, 2013 06:15
sign in attempt model attribute
@ModelAttribute
public SignInAttempt signInAttempt(@RequestParam String username, @RequestParam String password) {
return new SignInAttempt(username, password);
}
@joshlong
joshlong / gist:5114686
Created March 8, 2013 06:54
crm/signin.html GET
@RequestMapping(method = RequestMethod.GET)
public String showSignInPage() {
return SIGNIN;
}
@joshlong
joshlong / gist:5114717
Created March 8, 2013 07:05
@Email @notempty private String username;
@Email
@NotEmpty
private String username;
@joshlong
joshlong / gist:5114830
Created March 8, 2013 07:42
sigin form post
@RequestMapping(method = RequestMethod.POST)
public String signin(@ModelAttribute @Valid SignInAttempt signInAttempt, BindingResult result, Model model) throws Throwable {
if (!result.hasErrors()) {
User user = this.userService.login(signInAttempt.getUsername(), signInAttempt.getPassword());
if (user != null) {
model.addAttribute(USER_OBJECT_KEY, user);
return "redirect:/crm/profile.html";
} else {
result.reject("login.invalid", "The email and password did not match any known records. Please attempt your signin again.");