Я пытаюсь вставить объект в БД, но .save()
, редактирование и т. Д ... не работает. Это не показывает никакой ошибки. Кроме того, это работает, если я вставляю его с CommandLineRunner
, но это не так. Я что-то забыл?
@Entity
@Table(name = "categories")
public class Categories {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_category")
private int id_category;
@Column(name = "category_name")
private String category_name;
public Categories() {
}
...
@Repository("categoriesRepository")
public interface CategoriesRepository extends JpaRepository<Categories, Integer> {
}
@Service
@Transactional
public class CategoriesService{
public List<Categories> findAll() {
return categoriesRepository.findAll();
}
public void saveCat(Categories categories) {
this.categoriesRepository.save(categories);
}
...
@Controller
@RequestMapping("admin")
public class AdminController {
@Autowired
private CategoriesService categoriesService;
@RequestMapping(value = "saveCategory", method = RequestMethod.POST)
public String saveCategories(@ModelAttribute("categories") Categories theCategories) {
categoriesService.saveCat(theCategories);
return "redirect:/admin/allCategories";
}
@RequestMapping("/editCategories/{id_category}")
public ModelAndView showEditCategoriesForm(@PathVariable(name = "id_category") int id_category) {
ModelAndView mav = new ModelAndView("admin/admin_editCategories");
Categories theCategories = categoriesService.getView(id_category);
mav.addObject("categories", theCategories);
return mav;
}
@RequestMapping("/deleteCategories/{id_category}")
public String deleteCategories(@PathVariable(name = "id_category") int id_category) {
categoriesService.delete(id_category);
return "redirect:/admin/allCategories";
}
<form action="#" th:action="@{/saveCategory}" th:object="${categories}"
method="post">
<table border="1" cellpadding="10">
<tr>
<td>category</td>
<td><input type="text" placeholder="enter category" th:field="*{category_name}"/></td>
</tr>
<tr>
<td colspan="2"><button type="submit">SAVE</button> </td>
</tr>
</table>
</form>
Страница ошибки Whitelabel Это приложение не имеет явного сопоставления для / error, поэтому вы видите это как запасной вариант.
Вс 20 октября 02:28:01 CEST 2019 Произошла непредвиденная ошибка (тип = Не найдено, статус = 404). Нет доступных сообщений