Spring MVC в первую очередь MVC, а не REST
столкнулся с множеством проблем
еще и Spring Security со своим доступом к ресурсам головняки создает
Поэтому сейчас хочу попробовать 2 вариант
@Test
@Repeat(50)
public void someRepeatableTest() {
...
}
@RunWith(Parameterized.class)
public class SomeParameterizedTest {
private int x;
private int y;
public SomeParameterizedTest(int x, int y) {
this.x = x;
this.y = y;
}
@Test
public void someRepeatableTest() {
...
}
@Parameters
public static Iterable<Object[]> data() {
Random random = new Random();
return IntStream.rangeClosed(1, 50)
.boxed()
.map(i -> random.ints(1, 100)
.limit(2)
.boxed()
.toArray())
.collect(Collectors.toList());
}
}
if (bindingResult.hasErrors()) {
return "detailed_news_template";
}
@RequestMapping(value = "/user/addComment", method = RequestMethod.POST)
public String addComment(HttpServletRequest req, @ModelAttribute("Comment") @Valid Comment comment, BindingResult bindingResult, RedirectAttributes redirectAttributes) throws IOException {
if (bindingResult.hasErrors()) {
redirectAttributes.addFlashAttribute("errors", bindingResult.getAllErrors());
return "redirect:/user/detailedNews";
}
...
}
interface DaraRepository extends CrudRepository<Data, Long> {
List<Data> findBySync(Boolean sync);
List<Data> findBySyncIsNull();
}
import org.springframework.lang.Nullable;
interface DaraRepository extends CrudRepository<Data, Long> {
List<Data> findBySync(@Nullable Boolean sync);
}
@Query("from Data data where data.sync is null")
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
...
<form:form modelAttribute="formData" method="post">
<c:forEach items="${formData.sprints}" var="sprint" varStatus="status">
<input type="text" name="sprints[${status.index}]['name']" placeholder="Name"></td><br>
<input type="text" name="sprints[${status.index}]['phone']" placeholder="Phone"><br>
<input type="text" name="sprints[${status.index}]['email']" placeholder="E-Mail"><br>
</c:forEach>
<input type="submit" value="Сохранить">
</form:form>
public class SprintsForm {
private List<Map<String, String>> sprints;
public List<Map<String, String>> getSprints() {
return sprints;
}
public void setSprints(List<Map<String, String>> sprints) {
this.sprints = sprints;
}
}
@Controller
@RequestMapping("/")
public class FormController {
@RequestMapping(method = RequestMethod.GET)
public ModelAndView showForm() {
SprintsForm formData = new SprintsForm();
return new ModelAndView("form" , "formData", formData);
}
@RequestMapping(method = RequestMethod.POST)
public ModelAndView handleForm(@ModelAttribute SprintsForm formData, BindingResult result) {
if (result.hasErrors())
return new ModelAndView("form", "formData", formData);
...
}
}
@Controller
public class SomeController {
@RequestMapping(value = "/some-url/{someParam}", method = RequestMethod.GET)
public String someMethod(@PathVariable String someParam, Model model, HttpServletResponse response) {
return "some_template_name";
}
}
@Entity
public class Zone {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToOne(mappedBy = "zone")
private ZoneDescription description;
// Геттеры и сеттеры не указаны для краткости
}
@Entity
public class ZoneDescription {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToOne
private Zone zone;
@ManyToOne(optional = false)
private ZoneLanguage language;
// Геттеры и сеттеры не указаны для краткости
}
@Entity
public class ZoneLanguage {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
/* Раскоментировать, если нужна двунаправленная связь
@OneToMany(mappedBy = "language")
private Set<ZoneDescription> descriptions = new HashSet<>();
*/
// Геттеры и сеттеры не указаны для краткости
}
Zone zone = zoneRepository.getById(zoneId);
ZoneDescription description = zone.getDescription();
A special directory exists within the application hierarchy named WEB-INF. This directory contains all things related to the application that aren’t in the document root of the application. The WEB-INF node is not part of the public document tree of the application. No file contained in the WEB-INF directory may be served directly to a client by the container. However, the contents of the WEB-INF directory are visible to servlet code using the getResource and getResourceAsStream method calls on the ServletContext, and may be exposed using the RequestDispatcher calls.