我有一个List<SomeBean>
从Web服务填充的.我想将该列表的内容复制/克隆到相同类型的空列表中.谷歌搜索复制列表建议我使用Collections.copy()
方法.在我看到的所有示例中,目标列表应该包含要进行复制的确切项目数.
由于我使用的列表是通过Web服务填充的,它包含数百个对象,我不能使用上述技术.或者我使用它错了?? !! 无论如何,为了使它工作,我试图做这样的事情,但我仍然有一个IndexOutOfBoundsException
.
List<SomeBean> wsList = app.allInOne(template);
List<SomeBean> wsListCopy=new ArrayList<SomeBean>(wsList.size());
Collections.copy(wsListCopy,wsList);
System.out.println(wsListCopy.size());
Run Code Online (Sandbox Code Playgroud)
我尝试使用wsListCopy=wsList.subList(0, wsList.size())
但ConcurrentAccessException
后来我在代码中得到了一个.命中和审判.:)
无论如何,我的问题很简单,如何将列表的整个内容复制到另一个列表?当然不是通过迭代.
尝试使用Spring-JDBC.我用这个作为参考.我正在尝试获得具有相同姓氏的演员列表.运行此代码给了我想要的结果:
public List<String> getActorsWithSameLastName(String lastName,
NamedParameterJdbcTemplate template) {
String query = "SELECT FIRSTNAME FROM ACTORS WHERE LASTNAME=:LASTNAME";
Map<String, String> paramMap = new HashMap<String, String>();
paramMap.put("LASTNAME", lastName);
return template.queryForList(query, paramMap, String.class);
}
Run Code Online (Sandbox Code Playgroud)
我有一个List<String>
姓氏.如何获得具有列表的演员列表?我是否遍历姓氏列表并且getActorsWithSameLastName()
每次调用或者弹簧是否提供了迭代的方式并为我提取结果?请指教.
我REST-Jersey
在我的项目中使用.所有POST数据都以JSON
格式发送,并在服务器端解组为相应的bean.像这样的东西:
向服务器发送请求:
$('a#sayHelloPost').click(function(event){
event.preventDefault();
var mangaData = {
title:'Bleach',
author:'Kubo Tite'
}
var formData=JSON.stringify(mangaData);
console.log(formData);
$.ajax({
url:'rest/cred/sayposthello',
type: 'POST',
data: formData,
dataType: 'json',
contentType:'application/json'
})
});
Run Code Online (Sandbox Code Playgroud)
有效载荷:
{"title":"Bleach","author":"Kubo Tite"}
Run Code Online (Sandbox Code Playgroud)
服务器端:
@POST
@Path("/sayposthello")
@Produces(MediaType.APPLICATION_JSON)
public Response sayPostHello(MangaBean mb){
System.out.println(mb);
return Response.status(200).build();
}
Run Code Online (Sandbox Code Playgroud)
MangaBean:
public class MangaBean {
private String title;
private String author;
@Override
public String toString() {
return "MangaBean [title=" + title + ", author=" + author + "]";
}
public String getTitle() {
return title; …
Run Code Online (Sandbox Code Playgroud) 最近迁移到POSTGRESQL,我试图在创建db表的新条目时获取唯一生成的密钥.该表screenstable
如下所示:
CREATE TABLE screenstable
(
id serial NOT NULL,
screenshot bytea,
CONSTRAINT screen_id PRIMARY KEY (id )
)
Run Code Online (Sandbox Code Playgroud)
插入数据的方法screenstable
如下:
@Autowired NamedParameterJDBCTemplate template;
public int insertImage(ImageBean imageBean){
String query = "insert into screenstable (screenshot) values (:image)";
SqlParameterSource data = new BeanPropertySqlParameterSource(imageBean);
KeyHolder keyHolder = new GeneratedKeyHolder();
template.update(query, data, keyHolder);
return keyHolder.getKey().intValue();
}
Run Code Online (Sandbox Code Playgroud)
并且ImageBean
是
import java.util.Arrays;
public class ImageBean {
private int id;
private byte[] image;
@Override
public String toString() {
return "ImageBean [id=" + id …
Run Code Online (Sandbox Code Playgroud) Spring的新手,我试图在List<Map<String, Object>>
表中插入一个.到目前为止,我一直在使用SqlParameterSource
for batch update,它在向它们提供java bean时工作正常.像这样的东西:
@Autowired
private NamedParameterJDBCTemplate v2_template;
public int[] bulkInsertIntoSiteTable(List<SiteBean> list){
SqlParameterSource[] batch = SqlParameterSourceUtils
.createBatch(list.toArray());
int[] updateCounts = v2_template
.batchUpdate(
"insert into sitestatus (website, status, createdby) values (:website, :status, :username)",
batch);
return updateCounts;
}
Run Code Online (Sandbox Code Playgroud)
但是,我尝试使用相同的技术代替bean的地图列表,它失败了(正确地说是这样).
public int[] bulkInsertIntoSiteTable(List<Map<String, Object>> list){
SqlParameterSource[] batch = SqlParameterSourceUtils
.createBatch(list.toArray());
int[] updateCounts = v2_template
.batchUpdate(
"insert into sitestatus (website, status, createdby) values (:website, :status, :username)",
batch);
return updateCounts;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码失败,出现以下异常:
Exception in thread "main" org.springframework.dao.InvalidDataAccessApiUsageException: No value supplied …
Run Code Online (Sandbox Code Playgroud) 我是AJAX的新手.我正在使用AJAX向服务器发送请求.该服务返回一个文本文件.但是返回数据时不会出现下载框.返回文件的其余服务如下:
@Path("/examples")
public class ExampleCodesRest {
@POST
@Path("/getcode")
@Produces(MediaType.TEXT_PLAIN)
public Response getCodes(@Context ServletContext context){
String in=context.getRealPath("/WEB-INF/reports.jrxml");
File file=new File(in);
ResponseBuilder response = Response.ok((Object) file);
response.header("Content-Disposition",
"attachment; filename=\"file_from_server.log\"");
return response.build();
}
}
Run Code Online (Sandbox Code Playgroud)
我的AJAX调用如下:
$('a#link').click(function(event){
event.preventDefault();
$.ajax({
url: '/reports/rest/examples/getcode',
type: 'POST'
});
});
Run Code Online (Sandbox Code Playgroud)
没有AJAX,文件下载成功.使用AJAX,它不会下载文件.请咨询.
我在Ubuntu 12.04上运行了MySQL Server 5.5.32.Ubuntu正在VM上运行.主机平台是Windows 7. 如何从Windows连接Ubuntu的MySQL?
到目前为止我做了以下事情:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Run Code Online (Sandbox Code Playgroud)
运行show grant for root;
显示:
+-------------------------------------------------------------+
| Grants for root@% |
+-------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION |
+-------------------------------------------------------------+
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试从Windows上运行的SQLYog连接到此服务器时,出现错误Error 2003 Cannot connect to mysql server on '192.168.xxx.xxx'
.
IP正在向SQLYog提供,我从中得到了它ifconfig
.提供了inet addr.
inet addr:192.168.226.xxx Bcast:192.168.226.yyy
Run Code Online (Sandbox Code Playgroud)
使用的地址是不正确的还是这些授权问题?请指教.
我在我的Web应用程序中使用Jersey.发送到服务器的数据是JSON格式,而后者在服务器端解组,获得的对象用于进一步处理.安全审计为这种方法带来了一些漏洞.
我的休息代码:
@POST
@Path("/registerManga")
@Produces(MediaType.APPLICATION_JSON)
public Response registerManga(MangaBean mBean){
System.out.println(mBean);
return Response.status(200).build();
}
Run Code Online (Sandbox Code Playgroud)
MangaBean:
public class MangaBean {
public String title;
public String author;
@Override
public String toString() {
return "MangaBean [title=" + title + ", author=" + author + "]";
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
}
Run Code Online (Sandbox Code Playgroud)
数据以以下格式发送:
["title":"Bleach","author":"kubo tite"]
Run Code Online (Sandbox Code Playgroud)
上面的数据被成功解组到一个对象中,我将其作为输出:
MangaBean …
Run Code Online (Sandbox Code Playgroud) 我是JAXB的新手,我试图解组 XML文档.我使用该xjc
命令从XSD文件构建DataSet和ObjectFactory:
<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="AUTHOR" type="xs:string" minOccurs="0"/>
<xs:element name="TITLE" type="xs:string" minOccurs="0"/>
<xs:element name="ISBN" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
NewDataSet
生成的类如下:
package generated;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"table"
})
@XmlRootElement(name = "NewDataSet")
public class NewDataSet {
@XmlElement(name = "Table")
protected List<NewDataSet.Table> …
Run Code Online (Sandbox Code Playgroud) java ×7
spring ×3
jersey ×2
spring-jdbc ×2
ajax ×1
batch-insert ×1
c ×1
collections ×1
copy ×1
eclipse ×1
eclipse-cdt ×1
jax-rs ×1
jaxb ×1
jquery ×1
json ×1
mysql ×1
parsing ×1
pojo ×1
postgresql ×1
rest ×1
xml ×1