试图将我的数据从控制器传递到模态页面.
点击此链接:https: //qtzar.com/2017/03/24/ajax-and-thymeleaf-for-modal-dialogs/
第一:在控制器中查询数据库的简单方法
@PostMapping("/showarea")
public String areaModel(Model model) {
LOG.info("/showarea");
List<Zona> zonas = zonaService.findAll();
model.addAttribute("area", zonas.get(0).getNom_ZONA());
LOG.info("area: " + zonas.get(0).getNom_ZONA());
return "modal::modalContents";
}
Run Code Online (Sandbox Code Playgroud)
我把区域放在我的模型中.
第二:我用了一个例子:https:
//v4-alpha.getbootstrap.com/components/modal/#modal-components
添加文字.
<button type="button" class="btn btn-primary" data-toggle="modal"
data-target="#exampleModal">Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog"
aria-labelledby="exampleModalLabel" aria-hidden="true" th:fragment="modalContents">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p th:if="${area != …Run Code Online (Sandbox Code Playgroud) 我正试图在jinja2中制作一个mod,但没办法.
{%set index = 1%}
选项1:
{% for .... %}
{% if {{index % 3 == 0}} %}
{% endif %}
{% set index = index + 1 %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
选项2:
{% for .... %}
{% if index.index is divisibleby 3 %}
{% endif %}
{% set index = index + 1 %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
任何的想法?
谢谢
我正在尝试创建我的路由,而不依赖于application.properties中的server.contextPath
这是一个例子:
@PreAuthorize("hasRole('ROLE_ADMIN')
@GetMapping("/dashboard/admin/list/param1/{param1}")
public String method(@PathVariable String param1, Model model, HttpServletRequest request) {
//Some stuff
String contextPath = request.getContextPath();
return contextPath + "/dashboard/admin/list";
}
Run Code Online (Sandbox Code Playgroud)
但正如预期的那样,由于添加了contextPath,因此找不到视图.
如果我像这样重定向:
String contextPath = request.getContextPath();
String redirect = contextPath + "/dashboard/admin/list";
return "redirect:/dashboard/admin/directorio/list";
Run Code Online (Sandbox Code Playgroud)
一切都很好,但有时我不需要重定向.
背后的想法是遵循流程在tomcat中部署为war文件,正如我在此链接中所要求的: 如何在application.properties中设置的情况下获取控制器中的上下文路径
所以问题是:是否可以在@GetMapping中添加一些参数来添加contextPath
更新1
我不确定你在问什么.
假设我从同一个项目中创建了两个war项目,名为webapp1和webapp2,我部署在我的tomcat服务器中.
我可以像这样访问这两个项目:
HTTP://本地主机:8080/webapp1 /仪表板/管理/列表/参数1/100
HTTP://本地主机:8080/webapp2的/仪表板/管理/列表/参数1/200
但是当我返回位于src/main/resources/templates/dashboard/admin/list.html中的百万富翁页面时,找不到页面(这是错误的),因为在方法中@GetMapping找不到contextPath可以是webapp1或webapp2.
我不想使用server.contextPath,因为在这种情况下,我认为你只能拥有一个名为server.contextPath的项目.
谢谢
尝试添加模型确认页面(继续/取消),其中包含一些信息.
信息来自一个带有几个输入的表格......
我创建了一个litte项目,我认为它说明了这个要求.
在提交之前,我想在模态页面中显示一个值,具体取决于在表单中输入的值.在这种情况下,我有3个输入来做一个简单的总和.
因此模态页面显示总和,用户可以决定是否继续.
这是该项目的链接.我被困在index.html jquery部分.
[ https://github.com/davisoski/action-listener] [1 ]
我认为这是正确的方法,但我不能在我的情况下做到这一点
[ https://qtzar.com/2017/03/24/ajax-and-thymeleaf-for-modal-dialogs/] [2 ]
任何的想法
更新1
我有一个简单的表格,有3个字段.我有一个带有/ saveform后映射的控制器,这种方法只需调用一个服务并进行求和.没问题.
<form action="#" th:action="@{/saveform}" th:object="${modelform}"
method="post">
<div class="form-group row">
<div class="col-12 col-md-6 col-lg-3">
<label class="col-form-label col-form-label-sm" for="value1">Value1</label>
<input class="form-control form-control-sm" th:field="*{value1}"
id="value1" type="text" />
</div>
</div>
<div class="form-group row">
<div class="col-12 col-md-6 col-lg-3">
<label class="col-form-label col-form-label-sm" for="value2">Value2</label>
<input class="form-control form-control-sm" th:field="*{value2}"
id="value2" type="text" />
</div>
</div>
<div class="form-group row">
<div class="col-12 col-md-6 col-lg-3">
<label class="col-form-label col-form-label-sm" for="value3">Value3</label>
<input class="form-control form-control-sm" th:field="*{value3}" …Run Code Online (Sandbox Code Playgroud) 我一直在Boostrap 4测试版中使用此代码,一切正常.
<label for="username" th:text="#{login.user">User</label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-user"></i></span> <input
type="text" id="username" name="username" class="form-control"
placeholder="Usuario" th:placeholder="#{login.user}"
th:required="true" />
</div>
Run Code Online (Sandbox Code Playgroud)
现在,我已将我的Bootstrap 4更新为当前的v4.0.0.但是,由此,代码无法正常工作.该input-group-addon班是不存在的引导css文件.
如果我将它添加到我的css样式文件中,一切正常:
.input-group-addon {
padding: .375rem .75rem;
margin-bottom: 0;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #495057;
text-align: center;
background-color: #e9ecef;
border: 1px solid #ced4da;
}
Run Code Online (Sandbox Code Playgroud)
我在做错了吗?谢谢
我正在尝试在CKAN的一个实例中更新资源。我正在使用demo.ckan.org进行测试。
我可以使用curl创建和更新数据集的资源,但是使用python则无法做到这一点。
我的起点是这个链接:http : //docs.ckan.org/en/latest/maintaining/filestore.html#filestore-api
这是代码:
import requests
requests.post('http://0.0.0.0:5000/api/action/resource_create',
data={"package_id":"my_dataset"},
headers={"X-CKAN-API-Key": "21a47217-6d7b-49c5-88f9-72ebd5a4d4bb"},
files=[('upload', file('/path/to/file/to/upload.csv'))])
Run Code Online (Sandbox Code Playgroud)
我的curl代码可以正常运行,因此我尝试对其进行调整:
curl -X POST http://demo.ckan.org/api/3/action/resource_update -d '{"id":"5b75fdf2-df9c-4a4f-bb28-d78ea7bc4e48", "url": "http://82.98.156.2/ckan_api/public_html/restaurantes.geojson", "name": "Better Restaurants", "format":"GEOJSON", "description":"Description of the resource"}' -H "Authorization: 97caad21-8632-4372-98fe-a24cdcaa90dc"
Run Code Online (Sandbox Code Playgroud)
这应该是python中的代码:
resource_dict = {
'id': '5b75fdf2-df9c-4a4f-bb28-d78ea7bc4e48',
'name':'REstaurantes con PYTHON',
'url':'http://82.98.156.2/ckan_api/public_html/restaurantes.geojson',
'description':'Description in PYTHON'
}
resource_dict = urllib.quote(json.dumps(resource_dict))
requests.post('http://demo.ckan.org/api/3/action/resource_update',
data=resource_dict,
headers={"Authorization: 97caad21-8632-4372-98fe-a24cdcaa90dc"})
Run Code Online (Sandbox Code Playgroud)
我找到了这个旧链接: 使用CKAN API和Python Requests库创建CKAN数据集
最后,它建议添加一些信息,但我可以弄清楚。
有什么建议吗?
我有一个form要修改的对象。该对象可以在两个页面中使用,并具有相同的值。
我想要两个按钮,并根据提交的按钮发送到一页或另一页。
现在我的代码是这样的:
<!-- Make my action dinamically depending on button submitted -->
<form action="#" th:action="@{/action}" th:object="${myObject}"
method="post">
<input type="submit" name="new" value="new"/>
<input type="submit" name="edit" value="edit"/>
</form>
Run Code Online (Sandbox Code Playgroud)
th:action应该是动态的。
我在控制器中创建了方法,因此根据我可以处理它的操作:
@RequestMapping(value = {"/new", "/edit"}, method = RequestMethod.POST)
public String handlePost(@RequestParam String action, @ModelAttribute MyObject myObject) {
if (action.equals("new")) {
//Make some stuff
return "new";
} else if (action.equals("edit")) {
//Make some stuff
return "edit";
}
return "index";
}
Run Code Online (Sandbox Code Playgroud)
在 Thymeleaf 文档中我看到了类似的东西,但我无法处理它。
更新1
我的对象是一个在我的页面中呈现的 N 列矩阵。如果一切正常,我会编辑其值,但我可以使用新操作添加新列。
我想要两个按钮,根据它们中的哪一个进入新建或进入编辑。对象始终存在。 …
thymeleaf ×3
java ×2
javascript ×2
spring ×2
spring-boot ×2
ajax ×1
bootstrap-4 ×1
ckan ×1
css ×1
curl ×1
forms ×1
jinja2 ×1
jquery ×1
modal-dialog ×1
python ×1