Java 所需请求部分
将图片添加到表格时,会发生错误: 所需消息请求部分“图片”不存在 说明由于以下原因,服务器无法或将不处理请求: 被认为是客户端错误的东西(例如,格式错误 请求语法、无效的请求消息帧或欺骗请求 路由) 数据库中没有加载任何内容 我的控制器:Java 所需请求部分,java,html,spring,hibernate,jsp,Java,Html,Spring,Hibernate,Jsp,将图片添加到表格时,会发生错误: 所需消息请求部分“图片”不存在 说明由于以下原因,服务器无法或将不处理请求: 被认为是客户端错误的东西(例如,格式错误 请求语法、无效的请求消息帧或欺骗请求 路由) 数据库中没有加载任何内容 我的控制器: @Controller @RequestMapping("/general") public class OrderController { private OrderService orderService; private Dao dao;
@Controller
@RequestMapping("/general")
public class OrderController {
private OrderService orderService;
private Dao dao;
public OrderController(OrderService orderService) {
this.orderService = orderService;
}
@Autowired
public void setOrderService(OrderService orderService) {
this.orderService = orderService;
}
public OrderController() {
}
@GetMapping(value = "/list")
public String get(Model theModel) {
theModel.addAttribute("orders", orderService.getOrders());
return "index";
}
@GetMapping(value = "/showFormForAdd")
public String add(Model theModel) {
Orders orders = new Orders();
theModel.addAttribute("order", orders);
return "create-orders";
}
@PostMapping(value = "/saveOrders")
public String addOrders(@ModelAttribute("order") Orders orders, @RequestParam("picture") MultipartFile file) throws IOException {
orders = orderService.uploadOrders(orders, file);
orderService.add(orders);
return "redirect:/general/list";
}
}
道:
@存储库
公共接口Dao{
列出getAllOrders();
作废addAll(订单);
}
OrderDaoImpl:
@Repository
public class OrderDaoImpl implements Dao {
private SessionFactory orderDao = OrderDao.getSessionFactory();
public OrderDaoImpl() {
}
@Autowired
public void setOrderDao(SessionFactory orderDao) {
this.orderDao = orderDao;
}
@Override
@Transactional
public List<Orders> getAllOrders() {
Session session = orderDao.openSession();
try {
session.beginTransaction();
Query<Orders> query = session.createQuery("from Orders", Orders.class);
return query.getResultList();
} finally {
session.getTransaction().commit();
session.close();
}
}
@Override
@Transactional
public void addAll(Orders orders) {
Session session = orderDao.openSession();
try {
session.beginTransaction();
session.save(orders);
} finally {
session.getTransaction().commit();
session.close();
}
}
}
@存储库
公共类OrderDaoImpl实现Dao{
私有SessionFactory orderDao=orderDao.getSessionFactory();
公共命令daoimpl(){
}
@自动连线
public void setOrderDao(SessionFactory orderDao){
this.orderDao=orderDao;
}
@凌驾
@交易的
公共列表getAllOrders(){
Session Session=orderDao.openSession();
试一试{
session.beginTransaction();
Query Query=session.createQuery(“来自订单”,Orders.class);
返回query.getResultList();
}最后{
session.getTransaction().commit();
session.close();
}
}
@凌驾
@交易的
公共无效添加所有(订单){
Session Session=orderDao.openSession();
试一试{
session.beginTransaction();
会话。保存(命令);
}最后{
session.getTransaction().commit();
session.close();
}
}
}
create-orders.jsp:
<head>
<title>Car Shop</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
</head>
<body>
<form:form action="${pageContext.request.contextPath}/general/saveOrders" enctype="multipart/form-data"
modelAttribute="order" method="post">
<div class="container">
<div id="row">
<div class="col-md-9">
<h2 style="text-align: center">Создание объявления</h2>
<div class="form-group">
<label for="description" type="table" class="table">Description:</label>
<label>
<input id="description" name="description"/>
</label>
</div>
<div class="form-group">
<label for="price" type="table" class="table">Price:</label>
<label>
<input id="price" name="price"/>
</label>
</div>
<div class="form-group">
<label for="body" type="table" class="table">Body:</label>
<label>
<input id="body" name="body"/>
</label>
</div>
<div class="form-group">
<label for="brand" type="table" class="table">Brand:</label>
<label>
<input id="brand" name="brand"/>
</label>
</div>
<div class="form-group">
<label for="engine" type="table" class="table">Engine:</label>
<label>
<input id="engine" name="engine"/>
</label>
</div>
<div class="form-group">
<label for="model" type="table" class="table">Model:</label>
<label>
<input id="model" name="model"/>
</label>
</div>
<div class="form-group">
<label>Sold:</label>
<label>
<input id="sold" type="checkbox" name="sold">
</label>
</div>
<div class="form-group">
<label for="pic">Image</label>
<label>
<input id="pic" name="picture" type="file" class="file">
</label>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default" name="saveOrders">Сохранить</button>
</div>
</div>
<p>
<a href="${pageContext.request.contextPath}/general/list"
class="btn btn-outline-info btn-lg my-3">Back to Orders list</a>
</p>
</div>
</div>
</div>
</form:form>
</body>
汽车店
Создание объявления
说明:
价格:
正文:
品牌:
发动机:
型号:
出售:
形象
Сохранить
是否有类似于存储库类的相关类?是的。这是Dao和OrderDaoImpl。我对此表示怀疑。
<head>
<title>Car Shop</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
</head>
<body>
<form:form action="${pageContext.request.contextPath}/general/saveOrders" enctype="multipart/form-data"
modelAttribute="order" method="post">
<div class="container">
<div id="row">
<div class="col-md-9">
<h2 style="text-align: center">Создание объявления</h2>
<div class="form-group">
<label for="description" type="table" class="table">Description:</label>
<label>
<input id="description" name="description"/>
</label>
</div>
<div class="form-group">
<label for="price" type="table" class="table">Price:</label>
<label>
<input id="price" name="price"/>
</label>
</div>
<div class="form-group">
<label for="body" type="table" class="table">Body:</label>
<label>
<input id="body" name="body"/>
</label>
</div>
<div class="form-group">
<label for="brand" type="table" class="table">Brand:</label>
<label>
<input id="brand" name="brand"/>
</label>
</div>
<div class="form-group">
<label for="engine" type="table" class="table">Engine:</label>
<label>
<input id="engine" name="engine"/>
</label>
</div>
<div class="form-group">
<label for="model" type="table" class="table">Model:</label>
<label>
<input id="model" name="model"/>
</label>
</div>
<div class="form-group">
<label>Sold:</label>
<label>
<input id="sold" type="checkbox" name="sold">
</label>
</div>
<div class="form-group">
<label for="pic">Image</label>
<label>
<input id="pic" name="picture" type="file" class="file">
</label>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default" name="saveOrders">Сохранить</button>
</div>
</div>
<p>
<a href="${pageContext.request.contextPath}/general/list"
class="btn btn-outline-info btn-lg my-3">Back to Orders list</a>
</p>
</div>
</div>
</div>
</form:form>
</body>