小编Dav*_*ave的帖子

Thymeleaf - th:field ="$ {}"和th:field ="*{}"之间的区别

我在教程中找不到这两条指令之间的区别.

th:field ="$ {something}"th:field ="*{something}"

谁能告诉我一些例子?

thymeleaf

13
推荐指数
1
解决办法
1万
查看次数

org.codehaus.jackson.JsonParseException:意外的字符('/'(代码47))

我有一个包含json格式的HashMap客户列表的文件.

像这样:

{"Davide":{"name":"Davide","cf":"FRCDVD","pi":"1234",
    "telephone":"333","website":"www","sector":"Student","address":"Rome"}}
Run Code Online (Sandbox Code Playgroud)

这只是列表的一个客户.每次调用控制器时,我都想从文件中获取数据并将它们转换为HashMap列表.

我尝试这样做:

HashMap<String, Customer> listCustomer = new HashMap<>();
listCustomer = new ObjectMapper().readValue(pathCustomerFile, HashMap.class); //This line gives me error
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误:

org.codehaus.jackson.JsonParseException:意外字符('/'(代码47)):也许是(非标准)评论?(因为功能'ALLOW_COMMENTS'未启用解析器而未被识别为一个)

我怎样才能做到这一点?

java json hashmap

7
推荐指数
2
解决办法
8299
查看次数

使用jQuery粘贴后删除空格

我试过了(jsfiddle),但它没有用.

你怎么能看到警报是空的.就像.val()函数在复制字符串之前启动.

$(document).on('paste', '#pasteIt', function(){
    alert($("#pasteIt").val());
    var withoutSpaces = $("#pasteIt").val();
    withoutSpaces = withoutSpaces.replace(/\s+/g, '');
    $("#pasteIt").text(withoutSpaces);
});
Run Code Online (Sandbox Code Playgroud)

为什么?

jquery

7
推荐指数
1
解决办法
2239
查看次数

Thymeleaf - 仅使用两位小数格式化百分比

我正在尝试使用 Thymeleaf 格式化百分比。但是,对于 99.99 这样的 %,thymeleaf 将此值格式化为 100。我不想要它。

我这样做了:

Java端

BigDecimal percentage = (a).multiply(new BigDecimal(100)).divide(b, 3, RoundingMode.HALF_DOWN);
Run Code Online (Sandbox Code Playgroud)

百里香侧

th:text="${#numbers.formatDecimal(percentage, 1, 'POINT', 2, 'COMMA')}"
Run Code Online (Sandbox Code Playgroud)

如果百分比是 99.99 Thymeleaf 给我 100.00

为什么?

java formatting bigdecimal percentage thymeleaf

5
推荐指数
1
解决办法
4494
查看次数

是的 - 在运行时创建和修改验证模式

我需要创建一个用户然后更新它。所以我需要两个不同的模式。

这是第一个,用于用户创建:

const addressSchema = object().shape({
    street: string().required(),
    city: string().required(),
});

const signUpSchema = object().shape({
    req: object().shape({
        username: string().trim().required(),
        password: string().trim().required(),
        role: string().trim().required(),
        address: addressSchema
            .default(null)
            .nullable()
            .when(role, isAdminRole(object().required()))
    })
})
Run Code Online (Sandbox Code Playgroud)

现在,我想重用上面的架构来进行客户的更新操作。但是,它不能等于,因为例如在更新操作中,我不想更改密码。第二,不能有.required()限制。因为,在更新操作中,也许,我只想修改用户名而不是角色。更新架构应如下所示:

const addressUpdateSchema = object().shape({
    street: string().min(1), // .min(1) because it's not a required field but it can't be an empty string neither
    city: string().min(1),
});

const updateSchema = object().shape({
    req: object().shape({
        username: string().trim().min(1), 
        role: string().trim().min(1),
        address: addressUpdateSchema
            .default(null)
            .nullable()
            .when(role, isAdminRole(object()))
    })
})
Run Code Online (Sandbox Code Playgroud)

为了实现这些模式,我这样做了:

1 - …

javascript typescript yup

5
推荐指数
1
解决办法
5013
查看次数

启用 scrollX 时标题列与 DataTable 未对齐

我有这个插件经常出现的问题。

启用 scrollX 选项时,标题列未对齐。我尝试了许多在 stackoverflow 上阅读的解决方案,但没有成功。

可能是插件版本的问题吧?

但是,这是我的数据表设置:

 var oTable = $('#table').dataTable({
        "bJQueryUI": true,
        "aaData": jsonList,
        "bPaginate": true,
        "scrollX": true,
        "scrollCollapse" : true,
        "bLengthChange" : true,
        "bAutoWidth" : true,
        "oLanguage" : IT,
        "aoColumns": [
            { "mDataProp": "name", "sClass": "alignCenter" }, 
            { "mDataProp": "surname", "sClass": "alignCenter" }, 
            { "mDataProp": "age", "sClass": "alignCenter" },
            { "mDataProp": "city", "sClass": "alignCenter" }, 
            { "mDataProp": "state", "sClass": "alignCenter" }, 
            { "mDataProp": "work", "sClass": "alignCenter" },                 
        ],
        "aaSorting": [[1, 'asc']],
        "fnDrawCallback": function () {         
            formatTable();
        } …
Run Code Online (Sandbox Code Playgroud)

jquery datatables

4
推荐指数
1
解决办法
3147
查看次数

如何将 JSON 内容放入 HTML 中的 &lt;ul&gt; 标签和表单中

我将 java 映射转换为 JSON 映射(JSON 保存在文件中),如下所示:

{"Luigi":{"name":"Luigi","cf":"lg","pi":"123","telephone":"333","website":"site.it","sector":"Engineer","address":"Italy"},"Davide":{"name":"Davide","cf":"dvd","pi":"123456789","telephone":"755921","website":"mysite.it","sector":"Software developer","address":"Italy"}}
Run Code Online (Sandbox Code Playgroud)

在我的 jsp 中,我有一个具有 JSON 映射相同字段的表单(姓名、cf、电话......)。

我会将 JSON 映射(Luigi 和 Davide)的所有键放入无序列表中。像那样:

<ul> 
    <li>Luigi</li> 
    <li>Davide</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

当我单击其中之一时,我希望将相应的值放入表单中。

我正在考虑使用 jQuery 来做到这一点。

更新,表单代码

<form>                        
    <div class="form-group">
        <label class="form-control">Customer Name:</label>
        <input id="nameCustomer" class="form-control" type="text" placeholder="Name customer" autofocus>
    </div>
    <div class="form-group">
        <label class="form-control">Fiscal Code:</label>
        <input id="fiscalCode" class="form-control" type="text" placeholder="Fiscal code">
    </div>
    <div class="form-group">
        <label class="form-control">VAT Number:</label>
        <input id="vat" class="form-control" type="text" placeholder="VAT number (if available)">
    </div>
    <div class="form-group">
        <label class="form-control">Phone:</label>
        <input id="telephone" class="form-control" type="text" placeholder="Phone number">
    </div>
    <div …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery json

2
推荐指数
1
解决办法
2699
查看次数

Spring - RestController 注释不捕获请求

我不明白为什么如果我使用 RestController 注释将类声明为服务,如下所示:

@RestController("/registration")
public class RegistrationService {

    @RequestMapping(value="/", 
                produces="application/json")
    public String initializeSession(Model model){

        return "{\"success\":1}";
    }
}
Run Code Online (Sandbox Code Playgroud)

当我做一个请求时

http://localhost:8080/SpringRest/registration/

我得到 404 状态并在控制台中:

No mapping found for HTTP request with URI [/SpringRest/registration/] in DispatcherServlet with name 'dispatcherServlet'
Run Code Online (Sandbox Code Playgroud)

一切正常,如果我改变@RestController("/registration")

@Controller @RequestMapping("/registration")

并在方法声明上方添加@ResponseBody。

这是我的配置:

网页.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns="http://java.sun.com/xml/ns/javaee"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     id="WebApp_ID" version="2.5">

<display-name>SpringRest</display-name>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/application-config.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


<!--
    - Servlet that dispatches request to registered handlers (Controller implementations).
-->
<servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name> …
Run Code Online (Sandbox Code Playgroud)

java spring annotations spring-restcontroller

2
推荐指数
2
解决办法
3315
查看次数

是否可以在HTML / jQuery中创建字母垂直边栏?

我有一个“ ul”名单。我将创建一个按字母顺序排列的垂直边栏,当我单击他的一个字母时,将过滤以该字母开头的li名称。

示例:这是用于移动设备,我需要用于网络应用程序。

我没有找到任何插件或代码示例。

更新:说明

该列表已经排序。我只需要一个字母垂直的侧边栏即可上下滚动列表。

html javascript css jquery

1
推荐指数
1
解决办法
1915
查看次数

.html()jQuery函数返回NaN

我有

<div id="tablePlace"></div>
Run Code Online (Sandbox Code Playgroud)

if ($('#radioOne').is(':checked') == true) {
         $("#tablePlace").html(" ");
         $("#tablePlace").append(htmlTable); //htmlTable is a string that contains an html table code
         loadNestedTable(temp);
    }
Run Code Online (Sandbox Code Playgroud)

它有效但在div中我找到了NaN.如果我评论$("#tablePlace").append(htmlTable);,NaN不会出现.

为什么?

UPDATE

htmlValue代码:

var tab = '<table id="decretoSingolo">'+
+'<thead>' 
+   '<tr>'
+       '<th>Ente</th>'
+       '<th>CUP</th>'
+       '<th>Decreto impegno</th>'
+       '<th>Data decreto impegno</th>'
+       '<th>Importo impegno</th>'
+       '<th>Finanziato MIUR</th>'
+       '<th>Importo pagato</th>'
+       '<th>Importo in pagamento</th>'
+   '</tr>'
+ '</thead>'
+   '<tbody>'
+   '</tbody>'
+'</table>'

+'<div style="display:none">'    
+   '<table id="dettagliDecretoSingolo">'
+   '<thead>' 
+           '<tr>' …
Run Code Online (Sandbox Code Playgroud)

javascript jquery

1
推荐指数
1
解决办法
409
查看次数

如何隐藏,当页面启动时,使用jQuery自动生成html元素

页面启动时,jQuery会生成一个我想要隐藏的表单.因为我想在点击按钮时显示它.

通过这些说明,我创建了表单:

$("#cards").append('<li id="card" class="feed-element animated fadeInRight" style="color: grey" data-user="' + key + '">\n\
                        <button id="previewCard" type="button" value = "' + key + '" class="btn btn-primary btn-sm btn-block btn-xs">' + preview + '</li>\n\
                        <form id="cardFormDetail" class="animated fadeInRight">\n\
                            <div class="form-group">\n\
                                <input id="customerCardDate" class="form-control" type="text">\n\
                            </div>\n\
                            <div class="form-group">\n\
                                <input id="customerCardScope" class="form-control" type="text">\n\
                            </div>\n\
                            <div class="form-group">\n\
                                <textarea id="customerCardText" class="form-control" rows="5"></textarea>\n\
                            </div>\n\
                        </form>\n\
                        <button id="modifiedCard" type="button" value = "' + key + '" class="btn btn-primary btn-xs pull-left">Modified</button>\n\
                        <button id="deleteRequestCard" type="button" value = "' + …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery

0
推荐指数
1
解决办法
45
查看次数

将字符串日期转换为dd/MM/yyyy格式的java.util.Date

我在网上看到了更多问题,但我还没有找到解决方案.

我有一个类似"14/05/1994" 的字符串,完全采用这种格式.

我需要,转变为java.util.Date相同的格式.

我试过了:

    DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    Date dataFrom = new Date();
    dataFrom = df.format("14/05/1994");
Run Code Online (Sandbox Code Playgroud)

但结果是:1994年5月14日星期六00:00:00 CET

结果可能是:14/05/1994不是作为字符串,而是作为java.util.Date?

java date

0
推荐指数
1
解决办法
3260
查看次数