Код: Выделить всё
BlogКогда я вставляю одно значение, это нормально, но когда я вставляю более одного значения (теги), оно вставляется в базу данных как одно значение.

У меня нет Опыт работы с JavaScript. Как разделить значения в текстовом поле и отправить эти значения на сервер для вставки в базу данных?
Код: Выделить всё
create.jspКод: Выделить всё
$('#tag').tagEditor({
autocomplete: {
delay: 0, // show suggestions immediately
clickDelete:true,
position: { collision: 'flip' }, // automatic menu position up/down
placeholder: 'Enter tags ...',
source: function(request, response) {
$.ajax({
url : 'blog/listTag.html',
type : "POST",
data : {
term : request.term
},
dataType : "json",
success : function(jsonResponse) {
response(jsonResponse.tagList);
}
});
},
},
});
Код: Выделить всё
BlogAction.javaКод: Выделить всё
public String execCreate() {
try {
facade.createBlog(blog,tag);
return "success";
} catch (Exception e) {
logger.error(
Logger.EVENT_FAILURE,
"could not insert blog values, error: *"
+ e.getMessage() + "*");
}
return "input";
}
Код: Выделить всё
BlogService.javaКод: Выделить всё
@Transactional(readOnly = false)
@Override
public void createBlog(Blog blog,Tag tags) {
Blog newBlog = new Blog();
User user = (User) ESAPI.authenticator().getCurrentUser();
Tag tag=new Tag();
String name[]=tags.getName();
for(int i=0; i
Подробнее здесь: [url]https://stackoverflow.com/questions/28914422/inserting-into-database-a-texfield-containing-multiple-values-in-struts-2[/url]
Мобильная версия