- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试在数据库中存储文件图像和一些数据,但在运行我的应用程序时遇到以下错误。
错误是:
创建名称为“filePostComtroller”的 bean 时出错:通过字段“filePostService”表达的依赖关系不满足;嵌套异常是 org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“filePostServiceImpl”的 bean 时出错:通过字段“filePostDAO”表达的依赖关系不满足;嵌套异常是 org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“filePostDAOImpl”的 bean 时出错:通过字段“sessionFactory”表达的依赖关系不满足;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建 ServletContext 资源 [/WEB-INF/rms-servlet.xml] 中定义的名为“sessionFactory”的 bean 时出错:调用 init 方法失败;嵌套异常是 org.hibernate.MappingException:无法确定类型:java.util.List,表:file_post,列:[org.hibernate.mapping.Column(file)]
FilePost 类:
@Entity
@Table(name="file_post")
public class FilePost implements Serializable {
private static final long serialVersionUID = 74458L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="post_id")
private int postId;
@NotBlank
@Column(name="post_heading")
private String postHeading;
@NotBlank
@Column(name="post_description")
private String postDescription;
@Column(name="post_date")
private String postDate;
@Column(name="file")
private List<MultipartFile> file;
@ManyToOne(fetch=FetchType.LAZY, cascade= {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.DETACH,CascadeType.REFRESH })
@JoinColumn(name="user_username")
private User user;
public FilePost() {
this.user = new User();
}
public FilePost(String postHeading, String postDescription, String postDate, List<MultipartFile> file, User user) {
this.postHeading = postHeading;
this.postDescription = postDescription;
this.postDate = postDate;
this.file = file;
this.user = user;
}
public FilePost(int postId, String postHeading, String postDescription, String postDate, List<MultipartFile> file,
User user) {
this.postId = postId;
this.postHeading = postHeading;
this.postDescription = postDescription;
this.postDate = postDate;
this.file = file;
this.user = user;
}
public int getPostId() {
return postId;
}
public void setPostId(int postId) {
this.postId = postId;
}
public String getPostHeading() {
return postHeading;
}
public void setPostHeading(String postHeading) {
this.postHeading = postHeading;
}
public String getPostDescription() {
return postDescription;
}
public void setPostDescription(String postDescription) {
this.postDescription = postDescription;
}
public String getPostDate() {
return postDate;
}
public void setPostDate(String postDate) {
this.postDate = postDate;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public List<MultipartFile> getFile() {
return file;
}
public void setFile(List<MultipartFile> file) {
this.file = file;
}
@Override
public String toString() {
return "FilePost [postId=" + postId + ", postHeading=" + postHeading + ", postDescription=" + postDescription
+ ", postDate=" + postDate + ", file=" + file + "]";
}
文件后 Controller :
@Controller
public class FilePostComtroller {
@Autowired
private FilePostService filePostService;
@GetMapping("/showFilePostForm")
public String showFilePostForm(Model theModel) {
FilePost theFilePost = new FilePost();
theModel.addAttribute("filePost", theFilePost);
return "filepost-form";
}
@PostMapping("/savePost")
public String uploadFole(@ModelAttribute("filePost") @Valid FilePost theFilePost, BindingResult theResult,
Principal principal, HttpServletRequest servletRequest) {
if (theResult.hasErrors()) {
return "filepost-form";
}
//file
List<MultipartFile> files = theFilePost.getFile();
List<String> fileNames = new ArrayList<String>();
if (null != files && files.size() > 0) {
for(MultipartFile multipartFile: files) {
String fileName = multipartFile.getOriginalFilename();
fileNames.add(fileName);
File resourcesFile = new File(servletRequest.getServletContext().getRealPath("C:/Users/MD MITHU SARKER/eclipse-workspace/Resource-Management-System/WebContent/resources/file"), fileName);
try {
multipartFile.transferTo(resourcesFile);
} catch (IOException e) {
e.printStackTrace();
}
}
}
// get user name
String username = principal.getName();
theFilePost.getUser().setUserName(username);
//save
filePostService.saveFilePost(theFilePost);
return "filepost-form";
}
文件后服务:
public interface FilePostService {
void saveFilePost(FilePost theFilePost);
}
FilePostServiceImpl:
@Service
public class FilePostServiceImpl implements FilePostService {
@Autowired
private FilePostDAO filePostDAO;
@Override
@Transactional
public void saveFilePost(FilePost theFilePost) {
filePostDAO.saveFilePost(theFilePost);
}
FilePostDAO:
public interface FilePostDAO {
void saveFilePost(FilePost theFilePost);
}
FilePostDAOImpl:
@Repository
public class FilePostDAOImpl implements FilePostDAO {
// need to inject the session factory
@Autowired
private SessionFactory sessionFactory;
@Override
public void saveFilePost(FilePost theFilePost) {
Session currentSession = sessionFactory.getCurrentSession();
currentSession.saveOrUpdate(theFilePost);
}
filepost-form.jsp
<form:form action="savePost" modelAttribute="filePost" method="POST" enctype="multipart/form-data">
<label>Post Heading:</label><br>
<form:input type="text" path="postHeading" name="postHeading"/><br><br>
<form:errors path="postHeading"></form:errors>
<label>Post Description:</label><br>
<form:input type="text" path="postDescription" name="postDescription"/><br><br>
<form:errors path="postDescription"></form:errors>
<label>Post Date:</label><br>
<form:input type="date" path="postDate" name="postDate"/><br><br>
<form:errors path="postDate"></form:errors>
<label for="file">Post File: </label><br>
<form:input type="file" path="file" name="file" multiple="multiple"/><br><br>
<input type="submit" value="Submit"/>
</form:form>
最佳答案
您需要将图像保存为数据库中的blob
,并在实体中将其声明为字节数组byte[]
关于java - 无法确定 : java. util.List 的类型,位于表 : file_post, 的列 : [org. hibernate.mapping.Column(file)],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58068966/
我正在使用 javascript 并有以下类: const Product = require('../models').Product class ProductService { cons
我正在开发一个简单的应用程序,宠物用户可以在其中创建关于他们宠物的板并在板上显示图片。 我正在尝试创建一个功能,用户可以点击他们的图板,将他们重定向到他们的图板,该图板将显示他们所有的宠物图片。 当我
我有这样的事情:循环遍历 ids,并对每个 ids 向服务器(同一域)发出 ajax 请求 (async:true) 并将接收到的数据附加到 DOM 元素。这不是一项艰巨的任务,它确实有效。示例代码:
我正在尝试使用 Pillow 在我的网络应用程序中添加用户可上传的图像。我创建了一个 Django Upload 模型并将其注册到 Admin 中。当我使用管理控制台添加照片后,我收到以下错误。最初该
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
说到 UINavigationBar 时我有点困惑。我以编程方式设置它,它的作用是将我的 viewController 向下推(因此在启动应用程序后看不到 Storyboard中看到的 View 底部
我有以下查询,它可以满足我的要求,并显示从出生日期转换而来的人们的年龄。但我现在想通过说大于或小于这些年龄来缩小结果范围,但我不知道该怎么做。 SELECT u.`id` as `user_id`
我有一个 ListView (不是 recyclerView),其中每一行都有一个按钮、几个 TextView 和一个 EditText。单击特定按钮(“editTremp”)后,我希望 EditTe
我的 cellAtIndexPath 中有一个查询。正如常见的那样,此查询从单元格行索引处的数组中获取对象。我想知道每次加载 tableView 时是否只有一个查询,还是将其算作每个 indexPat
我目前正在探索 http://www.ecovivo.be/rubriek/food 上使用的模板中的错误. 问题:访问该链接时,您会注意到右侧有一个带有内容的大型 float 图像。现在一切正常。但
我在 ViewController 之间通过引用传递特定模型的数组。 如果我更改数组中特定元素的任何值,它会在所有 ViewController 中很好地反射(reflect),但是当我从该数组中删除
svg 包含更多元素,其中之一是下拉选择器。我遇到的问题是选择器只能在其顶部边缘被点击,而不能在选择器的其他任何地方被点击。 选择器称为 yp-date-range-selector。在下一张图片中,
我的元素使用 20 行 20 列的 css 网格布局(每个单元格占屏幕的 5%)。其中一个页面有一个按钮。最初该页面包含在网格第 5-8 列和网格第 6-9 行中,按钮本身没有问题,但我需要将其居中放
我想使用 CSS Trick 使图像居中.但是如果图像大小是随机的(不固定的)怎么办。令人惊讶的是,我不想保持图像响应,我想在不改变其宽度或高度(实际像素)的情况下将图像置于中心。 下面是我的代码:
我正在尝试在网址之间进行路由。产品是一个类: from django.db import models from django.urls import reverse # Create your mo
我正在通过查看 Django 教程来制作网站。我收到一个错误: NoReverseMatch at /polls/ Reverse for 'index' with no arguments not
我一直在试用 Django 教程 Django Tutorial Page 3并遇到了这个错误 "TemplateDoesNotExist at /polls/ " . 我假设问题出在我的代码指向模板
我有一个应用程序,其中大部分图像资源都存储在单独的资源包中(这样做是有正当理由的)。这个资源包与主应用程序包一起添加到项目中,当我在 Interface Builder 中设计我的 NIB 时,所有这
我使用 Xcode 6.3.2 开发了一个 iPad 应用程序。我将我的应用程序提交到 App Store 进行审核,但由于崩溃而被拒绝。以下是来自 iTunes 的崩溃报告。 Incident Id
我正在使用以下内容来显示水平滚动条: CSS: div { width: 300px; overflow-x: scroll; } div::-webkit-scrollbar {
我是一名优秀的程序员,十分优秀!