我正在尝试创建一个有效的编辑页面。从我的模型中架起的默认编辑页面正在运行,但是为我的名为Image的文件字段分配了Byte []输入,这不可行。我将其替换为文件输入,并删除了一些不需要编辑的字段。当我编辑所有字段并尝试对其进行编辑时,“图像”字段会给出“图像字段是必需的”。验证消息,即使在我选择要上传的.png文件之后也是如此。
我的Edit.cshtml文件(不完整,但是我没有日期,AuthorUserName等输入字段,这可能是问题所在。)
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [SpringConfig.xml]; nested exception is java.lang.NoSuchMethodError: org.springframework.data.solr.repository.config.SolrRepositoryConfigExtension.registerIfNotAlreadyRegistered(Lorg/springframework/beans/factory/support/AbstractBeanDefinition;Lorg/springframework/beans/factory/support/BeanDefinitionRegistry;Ljava/lang/String;Ljava/lang/Object;)V
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.mkyong.core.App.main(App.java:64)
Caused by: java.lang.NoSuchMethodError: org.springframework.data.solr.repository.config.SolrRepositoryConfigExtension.registerIfNotAlreadyRegistered(Lorg/springframework/beans/factory/support/AbstractBeanDefinition;Lorg/springframework/beans/factory/support/BeanDefinitionRegistry;Ljava/lang/String;Ljava/lang/Object;)V
at org.springframework.data.solr.repository.config.SolrRepositoryConfigExtension.registerSolrMappingContextIfNotPresent(SolrRepositoryConfigExtension.java:156)
at org.springframework.data.solr.repository.config.SolrRepositoryConfigExtension.registerBeansForRoot(SolrRepositoryConfigExtension.java:105)
at org.springframework.data.repository.config.RepositoryBeanDefinitionParser.parse(RepositoryBeanDefinitionParser.java:72)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1438)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:185)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
... 14 more
我的编辑POST方法
class TableEdit(QtWidgets.QTableWidget):
def __init__(self, parent=None):
super(TableEdit, self).__init__(parent)
self.hover_item = None
row, column = 3, 3
self.setColumnCount(column)
self.setAlternatingRowColors(True)
self.setRowCount(row)
for r in range(self.rowCount()):
for c in range(self.columnCount()):
item = QtWidgets.QTableWidgetItem("This is cell {} {}".format(r + 1, c + 1))
self.setItem(r, c, item)
self.setHorizontalHeaderItem(0, QtWidgets.QTableWidgetItem("Col1"))
self.horizontalHeader().setVisible(False)
# self.setShowGrid(False)
self.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
self.setSelectionMode(QtWidgets.QAbstractItemView.NoSelection)
self.setAcceptDrops(True)
self.setMouseTracking(True)
def dragMoveEvent(self, event):
p = self.viewport().mapFromGlobal(QtGui.QCursor().pos())
it = self.itemAt(p)
if self.hover_item != it:
if self.hover_item is not None:
self.hover_item.setBackground(QtCore.Qt.white)
self.hover_item = it
if self.hover_item is not None:
self.hover_item.setBackground(QtCore.Qt.yellow)
super(TableEdit, self).dragMoveEvent(event)
# ...
还有Post的模型
<h4>Post</h4>
<hr />
<div class="row">
<div class="col-md-12">
<form asp-action="Edit" enctype="multipart/form-data">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="IDPost" />
<div class="row">
<div class="form-group col-md-4">
<label asp-for="Title" class="control-label"></label>
<input asp-for="Title" class="form-control" />
<span asp-validation-for="Title" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="form-group col-md-4">
<label asp-for="Image" class="control-label"></label>
<input asp-for="Image" type="file" />
<span asp-validation-for="Image" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="form-group col-md-4">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
//and so on
编辑:该字段为Byte [],但我先获取文件(图像),然后将其转换为Byte []。