Skip to content

Commit c2265d2

Browse files
committed
Simplify Spring's @RequestMapping for GET requests.
Automated with the following one-liners: git grep -l 'import.*RequestMethod' | while read F; do grep -q 'RequestMethod.POST' "$F" || sed -i '/import.*RequestMethod/d' "$F"; done git grep -l 'RequestMethod\.GET' | xargs sed -i 's|(value = \([^,]\+\), method = RequestMethod.GET)|(\1)|' No functional changes.
1 parent f77b010 commit c2265d2

10 files changed

+16
-21
lines changed

src/main/config/checkstyle-suppressions.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<suppress checks="LineLength" files="AbstractPageWithForm.java" lines="27,28,33" />
99
<suppress checks="LineLength" files="Form.java" lines="31,32,37" />
1010
<suppress checks="LineLength" files="Url.java" lines="73" />
11-
<suppress checks="LineLength" files="ErrorController.java" lines="74" />
11+
<suppress checks="LineLength" files="ErrorController.java" lines="73" />
1212

1313
<!-- false positives due to Lombok usage -->
1414
<suppress checks="HideUtilityClassConstructor" files="ru.mystamps.web.model" />

src/main/java/ru/mystamps/web/controller/AccountController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected void activationInitBinder(WebDataBinder binder) {
6262
binder.registerCustomEditor(String.class, "name", new StringTrimmerEditor(true));
6363
}
6464

65-
@RequestMapping(value = Url.REGISTRATION_PAGE, method = RequestMethod.GET)
65+
@RequestMapping(Url.REGISTRATION_PAGE)
6666
public RegisterAccountForm showRegistrationForm() {
6767
return new RegisterAccountForm();
6868
}
@@ -85,12 +85,12 @@ public String processRegistrationForm(
8585
return "redirect:" + Url.ACTIVATE_ACCOUNT_PAGE;
8686
}
8787

88-
@RequestMapping(value = Url.ACTIVATE_ACCOUNT_PAGE, method = RequestMethod.GET)
88+
@RequestMapping(Url.ACTIVATE_ACCOUNT_PAGE)
8989
public ActivateAccountForm showActivationForm() {
9090
return new ActivateAccountForm();
9191
}
9292

93-
@RequestMapping(value = Url.ACTIVATE_ACCOUNT_PAGE_WITH_KEY, method = RequestMethod.GET)
93+
@RequestMapping(Url.ACTIVATE_ACCOUNT_PAGE_WITH_KEY)
9494
public String showActivationFormWithKey(
9595
@PathVariable("key") String activationKey,
9696
Model model) {

src/main/java/ru/mystamps/web/controller/CategoryController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected void initBinder(WebDataBinder binder) {
5656
binder.registerCustomEditor(String.class, "nameRu", editor);
5757
}
5858

59-
@RequestMapping(value = Url.ADD_CATEGORY_PAGE, method = RequestMethod.GET)
59+
@RequestMapping(Url.ADD_CATEGORY_PAGE)
6060
public AddCategoryForm showForm() {
6161
return new AddCategoryForm();
6262
}
@@ -80,7 +80,7 @@ public String processInput(
8080
return "redirect:" + dstUrl;
8181
}
8282

83-
@RequestMapping(value = Url.INFO_CATEGORY_PAGE, method = RequestMethod.GET)
83+
@RequestMapping(Url.INFO_CATEGORY_PAGE)
8484
public String showInfo(@PathVariable("id") Category category, Model model, Locale userLocale) {
8585

8686
if (category == null) {

src/main/java/ru/mystamps/web/controller/CollectionController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.springframework.ui.Model;
2626
import org.springframework.web.bind.annotation.PathVariable;
2727
import org.springframework.web.bind.annotation.RequestMapping;
28-
import org.springframework.web.bind.annotation.RequestMethod;
2928

3029
import lombok.RequiredArgsConstructor;
3130

@@ -46,7 +45,7 @@ public class CollectionController {
4645
private final SeriesService seriesService;
4746
private final MessageSource messageSource;
4847

49-
@RequestMapping(value = Url.INFO_COLLECTION_PAGE, method = RequestMethod.GET)
48+
@RequestMapping(Url.INFO_COLLECTION_PAGE)
5049
public String showInfo(
5150
@PathVariable("id") Collection collection,
5251
Model model,

src/main/java/ru/mystamps/web/controller/CountryController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected void initBinder(WebDataBinder binder) {
5656
binder.registerCustomEditor(String.class, "nameRu", editor);
5757
}
5858

59-
@RequestMapping(value = Url.ADD_COUNTRY_PAGE, method = RequestMethod.GET)
59+
@RequestMapping(Url.ADD_COUNTRY_PAGE)
6060
public AddCountryForm showForm() {
6161
return new AddCountryForm();
6262
}
@@ -77,7 +77,7 @@ public String processInput(@Valid AddCountryForm form, BindingResult result, Use
7777
return "redirect:" + dstUrl;
7878
}
7979

80-
@RequestMapping(value = Url.INFO_COUNTRY_PAGE, method = RequestMethod.GET)
80+
@RequestMapping(Url.INFO_COUNTRY_PAGE)
8181
public String showInfo(@PathVariable("id") Country country, Model model, Locale userLocale) {
8282

8383
if (country == null) {

src/main/java/ru/mystamps/web/controller/ErrorController.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.springframework.stereotype.Controller;
2626
import org.springframework.web.bind.annotation.RequestHeader;
2727
import org.springframework.web.bind.annotation.RequestMapping;
28-
import org.springframework.web.bind.annotation.RequestMethod;
2928

3029
import lombok.RequiredArgsConstructor;
3130

@@ -41,7 +40,7 @@ public class ErrorController {
4140

4241
private final SiteService siteService;
4342

44-
@RequestMapping(value = Url.NOT_FOUND_PAGE, method = RequestMethod.GET)
43+
@RequestMapping(Url.NOT_FOUND_PAGE)
4544
public void notFound(
4645
HttpServletRequest request,
4746
CustomUserDetails userDetails,
@@ -66,7 +65,7 @@ public void notFound(
6665
}
6766
}
6867

69-
@RequestMapping(value = Url.INTERNAL_ERROR_PAGE, method = RequestMethod.GET)
68+
@RequestMapping(Url.INTERNAL_ERROR_PAGE)
7069
public void internalError(HttpServletRequest request) {
7170
// TODO: log to database (with *.status_code, *.message, *.servlet_name and user details)
7271

src/main/java/ru/mystamps/web/controller/ImageController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.springframework.stereotype.Controller;
2525
import org.springframework.web.bind.annotation.PathVariable;
2626
import org.springframework.web.bind.annotation.RequestMapping;
27-
import org.springframework.web.bind.annotation.RequestMethod;
2827

2928
import lombok.RequiredArgsConstructor;
3029

@@ -38,7 +37,7 @@ public class ImageController {
3837

3938
private final ImageService imageService;
4039

41-
@RequestMapping(value = Url.GET_IMAGE_PAGE, method = RequestMethod.GET)
40+
@RequestMapping(Url.GET_IMAGE_PAGE)
4241
public void getImage(@PathVariable("id") Integer imageId, HttpServletResponse response)
4342
throws IOException {
4443

src/main/java/ru/mystamps/web/controller/RobotsTxtController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@
2727

2828
import org.springframework.stereotype.Controller;
2929
import org.springframework.web.bind.annotation.RequestMapping;
30-
import org.springframework.web.bind.annotation.RequestMethod;
3130

3231
import ru.mystamps.web.Url;
3332

3433
@Controller
3534
public class RobotsTxtController {
3635
private static final Logger LOG = LoggerFactory.getLogger(RobotsTxtController.class);
3736

38-
@RequestMapping(value = Url.ROBOTS_TXT, method = RequestMethod.GET)
37+
@RequestMapping(Url.ROBOTS_TXT)
3938
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
4039
public void getRobotsText(HttpServletResponse response) {
4140
response.setContentType("text/plain");

src/main/java/ru/mystamps/web/controller/SeriesController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public Iterable<SelectEntityDto> getCountries(Locale userLocale) {
109109
return countryService.findAll(lang);
110110
}
111111

112-
@RequestMapping(value = Url.ADD_SERIES_PAGE, method = RequestMethod.GET)
112+
@RequestMapping(Url.ADD_SERIES_PAGE)
113113
public AddSeriesForm showForm() {
114114

115115
AddSeriesForm addSeriesForm = new AddSeriesForm();
@@ -145,7 +145,7 @@ public String processInput(
145145
return "redirect:" + dstUrl;
146146
}
147147

148-
@RequestMapping(value = Url.INFO_SERIES_PAGE, method = RequestMethod.GET)
148+
@RequestMapping(Url.INFO_SERIES_PAGE)
149149
public String showInfo(@PathVariable("id") Series series, Model model, User currentUser) {
150150

151151
if (series == null) {

src/main/java/ru/mystamps/web/controller/SiteController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.springframework.stereotype.Controller;
2323
import org.springframework.ui.Model;
2424
import org.springframework.web.bind.annotation.RequestMapping;
25-
import org.springframework.web.bind.annotation.RequestMethod;
2625

2726
import lombok.RequiredArgsConstructor;
2827

@@ -45,7 +44,7 @@ public class SiteController {
4544
private final CountryService countryService;
4645
private final SeriesService seriesService;
4746

48-
@RequestMapping(value = Url.INDEX_PAGE, method = RequestMethod.GET)
47+
@RequestMapping(Url.INDEX_PAGE)
4948
public String showIndexPage(Model model, Locale userLocale) {
5049
model.addAttribute("categoryCounter", categoryService.countAll());
5150
model.addAttribute("countryCounter", countryService.countAll());

0 commit comments

Comments
 (0)