我在classpath的目录下有一些静态图像文件,我希望通过变量传递其中一个图像文件的相对路径。在 Thymeleaf 上,目标是该变量将用作 src 属性的路径<img>。
控制器:
@Controller
public class SomeController {
@RequestMapping("/some")
public String someRequest(Model model) {
String imageFilepath = someObject.getImageFilepath();
// e.g., if imageFilepath = "/img/myPic.jpg", there can be a file "/img/myPic.jpg" under classpath:static
model.addAttribute("myPath", imageFilepath);
return "myThymeleafTemplate";
}
}
Run Code Online (Sandbox Code Playgroud)
百里香叶模板:
<img th:src="@{<I want to use my variable 'myPath' here instead of a hard-coded string '/img/myPic.jpg'>}">
Run Code Online (Sandbox Code Playgroud)
Thymeleaf 模板中 th:src 的尖括号(含)内的上下文正是我想要放置imageFilepath变量字符串的位置。这样的目标可行吗?
每次在 Windows 10 上启动 Python Flask 应用程序时,我都需要设置一长串临时环境变量。现在我想创建一个批处理文件,以便通过双击运行所有设置。如果我复制它们并粘贴到 cmd 提示符下,以下几行运行良好,但我无法在批处理文件中运行它们。
批处理文件的执行总是在批处理文件的第 2 行跳闸并退出,venv\scripts\activate如果我在 cmd 中逐行复制和粘贴,则完全没有问题。
cd C:\py\project
venv\scripts\activate
set env1=val1
set env2=val2
set FLASK_APP=some.py
flask run
Run Code Online (Sandbox Code Playgroud) batch-file ×1
cmd ×1
java ×1
python-venv ×1
spring ×1
spring-boot ×1
spring-mvc ×1
thymeleaf ×1