从字符串到字节数组的strust2类型转换?
问题描述:
我在用户端获得一些输入,但没有字符限制。所以我将输入存储为BLOB数据类型。从字符串到字节数组的strust2类型转换?
我直接用getter和setter填充我的实体。
Action类:
public class OperatorNotesAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private OperatorNotesInfo note;
....
}
OperatorNotesInfo
是我瓦纳得到填补的实体。在客户端我发送由用户填充的动作类使用JavaScript的输入:
JS:
$.ajax({
type: 'POST',
url: "<s:url action='updateNote'/>",
data:
{
'note.title':$('#title').val(),
'note.id.operatorId':$('#operatorId').val(),
'note.content':$('textarea').val()
},
这里含量在操作类字节阵列型的,因为它是存储为团块。
如何键入将用户输入的输入转换为字节数组,以便保存实体note
的内容属性?
答
您需要编写一个自定义类型转换器。来自输入的字符串默认转换为String
类型。你可以阅读which types conversion is supported via built-in type conversion。如果你想将字符串转换为bytearray,你需要编写一个转换器。然后用它与你的财产
@TypeConversion(converter="org.conversion.StringToBytearrayConverter")
public void setContent(byte[] bytes) {
this.content = bytes;
}
你想从字符串转换为字节数组? – 2014-09-25 11:24:19
@AleksandrM:是的。 – 2014-09-25 11:30:15
你有没有试过gooogle如何将字符串转换为java中的字节数组? – 2014-09-25 11:39:49