through
to the /static/images and the name of the image to MySQL(将到中的图像添加到/静态/图像中,并将图像的名称添加到MySQL中)-6ren"> through to the /static/images and the name of the image to MySQL(将到中的图像添加到/静态/图像中,并将图像的名称添加到MySQL中)-我的DB Day模型有一些字段:时间戳,如id、Description、Content、Steps、mainImage。如果数据库中没有这样的时间戳,则构造函数为空,默认为​​。如果时间戳在BD中,则-6ren">
gpt4 book ai didi

Add an image from through
to the /static/images and the name of the image to MySQL(将到中的图像添加到/静态/图像中,并将图像的名称添加到MySQL中)

转载 作者:bug小助手 更新时间:2023-10-25 17:53:17 26 4
gpt4 key购买 nike



My DB Day model has fields: timestamp such as id, description, content, steps, mainImage. The constructor is empty with default values ​​if there is no such timestamp in the database. "non-empty" if timestamp is in BD, getters/setters. There is a view full_day.html with info and an Edit Day button. When clicked Edit, a modal window opens with a form for changing the day using the "Save" button.

我的DB Day模型有一些字段:时间戳,如id、Description、Content、Steps、mainImage。如果数据库中没有这样的时间戳,则构造函数为空,默认为​​。如果时间戳在BD中,则为非空,则为getters/setters。有一个带有信息的Full_Day.html视图和一个编辑Day按钮。当点击编辑时,一个模式窗口打开,其中有一个表单,可以使用“保存”按钮更改日期。


In short, I want my user to add an image to a form (and some other things) and the image file goes to the /static/images/ and the file name goes to the MySQL Table. What are the ideas to do?

简而言之,我希望我的用户将一个图像添加到一个表单(以及其他一些内容)中,图像文件转到/Static/Images/,文件名转到MySQL表。有什么想法可以做吗?


(It is the details of the info I described above)

(这是我上面描述的信息的详细信息)


CalendarController.java:

CalendarController.java:


// Other methods
@GetMapping("/{year}/{month}/{dayNumber}")
public String day(Model model,
@PathVariable int year,
@PathVariable String month,
@PathVariable int dayNumber) {

long timestamp = convertToDateTimestamp(year, month, dayNumber);

Optional<Day> gotDay = dayRepository.findById(timestamp);
ArrayList<Day> currentDay = new ArrayList<>();

gotDay.ifPresent(currentDay::add);

model.addAttribute("gotDay", gotDay);
model.addAttribute("currentDay", currentDay);
model.addAttribute("year", year);
model.addAttribute("month", month);
model.addAttribute("dayNumber", dayNumber);
return "full_day";
}

@PostMapping("/{year}/{month}/{dayNumber}")
public String saveDay(Model model,
@ModelAttribute("gotDay") Day currentDay,
@PathVariable int year,
@PathVariable String month,
@PathVariable int dayNumber
) {

currentDay.setTimestamp(convertToDateTimestamp(year, month, dayNumber));
dayRepository.save(currentDay);

return "redirect:/calendar/" + year + "/" + month + "/" + dayNumber;
}

Day.java:

Day.java:


@Entity
@Table(schema = "memoryfulday", name = "memoryful")
public class Day {
@Id
private Long timestamp;
private String description, content;
private int steps;
private String mainImage;
// private MultipartFile mainImage;

public Day(Long timestamp) {
this.timestamp = timestamp;
this.mainImage = "NoPhoto.png";
this.description = "No brief description";
this.steps = 0;
this.content = "No content";
}

public Day(Long timestamp, String mainImage, String description, String content, int steps) {
this.timestamp = timestamp;
this.mainImage = mainImage;
this.description = description;
this.content = content;
this.steps = steps;
}

// toString()
// getters/setters
}

full_day.html:

Full_Day.html:


<!-- some code -->
<div id="edit-modal" class="edit-modal">
<div class="edit-content">
<span class="close">&times;</span>
<h2>Edit Day Window</h2>

<form method="post" th:object="${gotDay}">
<label for="steps">Daily steps</label>
<input value="${day.steps}" th:field="*{steps}" id="steps" type="number" tabindex="1" placeholder="10000">

<label for="description">Description</label>
<input value="${day.description}" th:field="*{description}" id="description" type="text" tabindex="2" placeholder="Enter day's description">

<label for="content">Content</label>
<textarea th:text="${day.content}" th:field="*{content}" id="content" tabindex="3" placeholder="Enter day's content"></textarea>
<input type="submit" tabindex="4" class="left-right" id="editSubmit" value="Save">
</form>
</div>
</div>

// some js to interract with modal window

I watched videos, searched info in websites, but I didn't find what I wanted. I tried some code that ChatGPT wrote for me, but it couldn't help me.

我看了视频,在网站上搜索信息,但我没有找到我想要的。我尝试了一些ChatGPT为我编写的代码,但它不能帮助我。


更多回答

To post data & files, you can try this. To generate directory to upload files to you can try this

要发布数据和文件,您可以尝试此操作。要生成要将文件上载到的目录,您可以尝试以下操作

优秀答案推荐
更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com