首页 \ 问答 \ 如何用freemarker分割hashmap的值?(How to split a value of a hashmap with freemarker?)

如何用freemarker分割hashmap的值?(How to split a value of a hashmap with freemarker?)

我有一个哈希映射如下:

gfpFileBean.getChaines().put("IN-RDU", "GFPZ001Q;OK" );     
gfpFileBean.getChaines().put("IN-PLEIADES", "GFPZ003Q;OK" );

我的Freemarker模板是:

<#list gfpVb.chaines as key,value> 
                   <td>
                   <strong>${key}</strong>                                
                   </td>
                   <td>
                   <strong>${value}</strong>
</#list>

我想知道是否可以用freemarker分割hashmap的值,以在表中显示我想要的值。


I have a hash map as below :

gfpFileBean.getChaines().put("IN-RDU", "GFPZ001Q;OK" );     
gfpFileBean.getChaines().put("IN-PLEIADES", "GFPZ003Q;OK" );

My Freemarker template is :

<#list gfpVb.chaines as key,value> 
                   <td>
                   <strong>${key}</strong>                                
                   </td>
                   <td>
                   <strong>${value}</strong>
</#list>

I would like to know if it is possible to split the value of hashmap with freemarker, to display the value where I want it in the table.


原文:https://stackoverflow.com/questions/50137884
更新时间:2022-06-27 18:06

最满意答案

你有一些未成年人的问题和一些大问题:

小:

  • 您不会在hints影响ai_protocol ,但当hints不为NULL时,它需要getaddrinfo()
  • 您使用connect()的返回值作为文件描述符,但它是一个错误代码号。 您必须在客户端使用socket()返回的文件描述符,或者在服务器中使用accept()
  • 在服务器中使用send()时,使用错误的文件描述符。 您不应该在处理SOCK_STREAM套接字类型的连接的文件描述符上发送数据。
  • getaddrinfo()返回一个列表,你应该迭代它,但是你认为总是有一个结果,但是它们可能是零或者多于一个。
  • hints被初始化,你用memset()调用未定义的行为,因为sizeof(struct addrinfo) > sizeof(struct addrinfo *)所以当你在ai上写0(GLOBAL ... GLOBAL EVERYWHERE)

大:

  • 你没有理由地使用全局
  • 您可以逐行声明多个变量。
  • 你没有理由地使用全局
  • 您不验证所有系统调用错误!
  • 你没有理由地使用全局

// server and client
struct addrinfo hints = {
  .ai_family = AF_INET,
  .ai_socktype = SOCK_STREAM,
  .ai_flags = AI_PASSIVE,
  .ai_protocol = IPPROTO_TCP,
};
// server
if (send(connfd, &msg_s, 1, MSG_CONFIRM) == -1) {
  // error
}
// client
if (recv(sockfd, &msg_r, 1, MSG_CONFIRM) == -1) {
  // error
}

You have some minors issue and some big issue:

Small:

  • You don't affect ai_protocol in hints, but it's require by getaddrinfo() when hints is not NULL
  • You use the return of connect() as a file descriptor but it's a error code number. You must use the file descriptor return by socket() in a client, or by accept() in a server.
  • You use the wrong file descriptor when you use send() in the server. You SHOULD not send data on the file descriptor that handle connection in a SOCK_STREAM socket type.
  • getaddrinfo() return a list, you should iterate on it, but you assume that there is always one result, but they could be zero or more than one.
  • hints is initialized, you invoke undefined behavior with memset() because sizeof(struct addrinfo) > sizeof(struct addrinfo *) so you are out of bound when you write zero on ai (GLOBAL... GLOBAL EVERYWHERE)

Big:

  • You use global without reason
  • You declare more than one variable by line.
  • You use global without reason
  • You don't verify all your system call error !
  • You use global without reason

// server and client
struct addrinfo hints = {
  .ai_family = AF_INET,
  .ai_socktype = SOCK_STREAM,
  .ai_flags = AI_PASSIVE,
  .ai_protocol = IPPROTO_TCP,
};
// server
if (send(connfd, &msg_s, 1, MSG_CONFIRM) == -1) {
  // error
}
// client
if (recv(sockfd, &msg_r, 1, MSG_CONFIRM) == -1) {
  // error
}

相关问答

更多
  • TCP无法发送/ recv字符串。 TCP无法发送/ recv超过一个字节的消息。 TCP不能发送/ recv结构长于一个字节。 TCP传输是一个字节流。 如果要传输比一个字节更复杂的内容,则需要在顶部使用额外的协议,因此需要HTTP,SMTP等协议。 例如,如果您特别想要发送以null结尾的字符串,则需要缓冲并连接接收到的数据,直到检测到null为止 - 然后您将拥有“C”样式的字符串并可以继续组合下一个字符串。 Rgds,马丁 TCP cannot send/recv strings. TCP cann ...
  • 这是因为Windows句柄的特殊性质 - 创建时它们可以被4整除,并且在使用时,它们的最低两位被忽略。 将句柄递增1会使m_Socket象以前一样引用相同的套接字(只有当你递增4时,该函数才会返回一个错误 - 除非有另一个打开该值的句柄)。 你不应该以这种方式探测打开的手柄。 虽然有其他方法可以枚举打开的句柄,但不应该使用它们。 不要依靠系统来跟踪你的手柄 - 自己跟踪它们。 It's because of the peculiar nature of Windows handles -- when cre ...
  • 看起来代码的意图是在'\n'字节到达时停止读取。 如果是这种情况,则需要一次读取套接字1个字节而不是使用整个可用缓冲区大小,特别是因为您只检查缓冲区的最后一个字节而不是检查接收的每个字节。 您还应该将循环逻辑更改为仅在一个位置而不是两个位置调用recv() 。 当缓冲区耗尽时,您当前的实现是使用slen=0调用recv(),这将设置c=0并使缓冲区中的第一个字节无效。 试试这个: int TcpSocket::ReadFromClient(int socket, char* buf, int len) { ...
  • 你有一些未成年人的问题和一些大问题: 小: 您不会在hints影响ai_protocol ,但当hints不为NULL时,它需要getaddrinfo() 您使用connect()的返回值作为文件描述符,但它是一个错误代码号。 您必须在客户端使用socket()返回的文件描述符,或者在服务器中使用accept() 。 在服务器中使用send()时,使用错误的文件描述符。 您不应该在处理SOCK_STREAM套接字类型的连接的文件描述符上发送数据。 getaddrinfo()返回一个列表,你应该迭代它,但是你 ...
  • 除非您计划发送大量数据(许多千字节)并经常(每秒几个数据包),否则我建议您将数据转换为字符串(也称为“序列化数据”)并以此方式传递。 它有几个好处: 它是可移植的 - 无论int或float或double大小是什么 - 或者字段之间的填充是什么。 它很容易调试(您只需查看数据并说明它是对还是错) 发送/接收机器的字节顺序无关紧要。 另一方面,发送二进制数据很复杂,因为您需要担心数据字段的各个大小及其内部表示(字节顺序,如何在二进制中重新表示double精度,结构内数据字段的填充,不能通过指针等等)。 唯一的 ...
  • 如果无法在协议中嵌入有效负载大小,则必须通过关闭套接字或检查超时来识别EOF。 您可以使用select函数并为其设置超时,请参阅此处使用select和recv通过套接字从Web服务器获取文件并使用https://stackoverflow.com/a/30395738/4490542 If you can't embed payload size in your protocol, you have to identify EOF by closing socket or checking for time ...
  • 是的,在一个线程上recv()和使用相同套接字在另一个线程上send()是安全的。 服务器端,使用专用线程只有在同时连接到服务器的客户端相对较少的情况下才能有效工作。 如果可伸缩性是一个问题,则需要使用异步I / O,甚至是I / O完成端口(如果可能),以在单个线程上管理多个客户端,从而将所需线程的数量降至最低。 Yes, it is safe to recv() on one thread and send() on another thread using the same socket. Serve ...
  • 在unix上有hping http://www.hping.org/和mausezahn http://www.perihel.at/sec/mz/但是我不知道是否有任何这些在windows下编译。 我所知道的所有应用程序/库都基于libpcap / winpcap。 On unix there is hping http://www.hping.org/ and mausezahn http://www.perihel.at/sec/mz/ but I don't know if any of those ...
  • 假设这是TCP(而不是UDP),您可以将套接字视为字节流。 发件人可以以他想要的任何方式将它们放入,并且您可以以任何您想要的方式将它们取出。 因此,发送方可以在一次调用中写入1k块,如果需要,您可以一次接收一个字节。 有很多方法,但这里有两个相当简单的方法: 如果发送方在发送所有数据后关闭套接字,接收方将接收所有发送的数据,下一次对recv的调用将返回0,表示没有更多内容可以接收。 这就是HTTP / 1.0的工作原理。 您可以更改协议以发送某种包含您要发送的数据长度的标头,然后recv将知道预期的字节数。 ...
  • 编辑:我在这里看到了很多问题,其中解决了send()和recv()的困难,但是我没有找到解释为什么当只发送少得多的字节时recv会返回如此大的数字。 我认为len是不正确的,因为运算符“=”的优先级低于运算符“>”。 您可以尝试使用括号。 您可以在以下示例中看到len具有不同的值: #include int f() ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)