当前位置: 编程技术>移动开发
本页文章导读:
▪内存储器的使用_动态分配 内存的使用_动态分配
c语言中允许在执行程序时动态分配内存;而只有使用指针,才能动态分配内存;
1.动态分配内存(void*) malloc(int size)
char *pString = (char*) malloc(12+1); //为字符指针动态分.........
▪ 利用excel导出查询的记要表 利用excel导出查询的记录表
我们通常碰到查询出来的表格需要用EXCEL导出,这是我学习到的一个方案,拿出来与大家分享。本文主要是给自己留下点资料以便以后查看,如果有朋友需要了.........
▪ UITextField 封锁键盘 UITextField 关闭键盘
UITextField tf;
tf.delegate = self;
//实现重写了textFieldShouldReturn:方法
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
......
[1]内存储器的使用_动态分配
来源: 互联网 发布时间: 2014-02-18
内存的使用_动态分配
c语言中允许在执行程序时动态分配内存;而只有使用指针,才能动态分配内存;
1.动态分配内存(void*) malloc(int size)
char *pString = (char*) malloc(12+1); //为字符指针动态分配内存,可以存储12个字符
2.分配内存时使用sizeof运算符
sizeof可以获取某类型或变量占用的内存大小(字节数),返回一个size_t类型的无符号整数
3.用calloc()函数分配内存(void*) calloc(int count,int elementSize)
与mcalloc相比的优点:它把内存分配各指定大小的数组;它初始化了锁分配的内存,所有的位都是0;
int *pNumber = (int *)calloc(5,sizeof(int)); //参数:数组个数,每个数组元素占用字节数
4.释放动态分配的内存free(void *)
堆上分配的内存会在程序结束时自动释放,但最好在使用完这些内存后立即释放.
例如:free(pString);
free(pNumber);
5.重新分配内存(void*) realloc(void *,int)
重用前面malloc,calloc,realloc分配过的内存
[2] 利用excel导出查询的记要表
来源: 互联网 发布时间: 2014-02-18
利用excel导出查询的记录表
我们通常碰到查询出来的表格需要用EXCEL导出,这是我学习到的一个方案,拿出来与大家分享。本文主要是给自己留下点资料以便以后查看,如果有朋友需要了解的,可以讨论下,也希望指正我的错误,还是那句话,我是个新手,希望大家提供给我帮助
(1)在struts.xml中配置action
<action name="generateExcel" >
<result type="stream"> <paramname="contentType">application/vnd.ms-excel</param>
<paramname="contentDisposition">attchment;filename="AllUser.xls"</param>
<param name="inputName">downloadFile</param>
</result>
</action>
(2)service层
public InputStream getInputStream() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("sheel1");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("序号");
cell = row.createCell((short) 1);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("姓");
cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("名");
cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("年龄");
List<User> list = this.findAll();
for (int i = 0; i < list.size(); i++) {
User user = list.get(i);
row = sheet.createRow(i + 1);
cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(i + 1);
cell = row.createCell((short) 1);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(user.getFirstname());
cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(user.getLastname());
cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(user.getAge());
}
//String fileName = CharacterUtils.getRandomString(10);
//或者采用
String fileName = RandomStringUtils.randomAlphanumeric(10);
fileName = new StringBuffer(fileName).append(".xls").toString();
final File file = new File(fileName);
try {
OutputStream os = new FileOutputStream(file);
try {
wb.write(os);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
InputStream is = null;
try {
is = new FileInputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//增加线程,15000为等待文件下载时间
new Thread(new Runnable(){
public void run(){
try {
Thread.sleep(15000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
file.delete();
}
}).start();
return is;
}
(3)GenerateExcelAction
public InputStream getDownloadFile(){
return this.service.getInputStream();
}
(4)spring配置文件注入action
<bean id="generateExcelAction" >
<property name="service" ref="userService"></property>
</bean>
(5)jsp
<s:a href="/blog_article/generateExcel.action">生成Excel</s:a>
我们通常碰到查询出来的表格需要用EXCEL导出,这是我学习到的一个方案,拿出来与大家分享。本文主要是给自己留下点资料以便以后查看,如果有朋友需要了解的,可以讨论下,也希望指正我的错误,还是那句话,我是个新手,希望大家提供给我帮助
(1)在struts.xml中配置action
<action name="generateExcel" >
<result type="stream"> <paramname="contentType">application/vnd.ms-excel</param>
<paramname="contentDisposition">attchment;filename="AllUser.xls"</param>
<param name="inputName">downloadFile</param>
</result>
</action>
(2)service层
public InputStream getInputStream() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("sheel1");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("序号");
cell = row.createCell((short) 1);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("姓");
cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("名");
cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("年龄");
List<User> list = this.findAll();
for (int i = 0; i < list.size(); i++) {
User user = list.get(i);
row = sheet.createRow(i + 1);
cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(i + 1);
cell = row.createCell((short) 1);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(user.getFirstname());
cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(user.getLastname());
cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(user.getAge());
}
//String fileName = CharacterUtils.getRandomString(10);
//或者采用
String fileName = RandomStringUtils.randomAlphanumeric(10);
fileName = new StringBuffer(fileName).append(".xls").toString();
final File file = new File(fileName);
try {
OutputStream os = new FileOutputStream(file);
try {
wb.write(os);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
InputStream is = null;
try {
is = new FileInputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//增加线程,15000为等待文件下载时间
new Thread(new Runnable(){
public void run(){
try {
Thread.sleep(15000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
file.delete();
}
}).start();
return is;
}
(3)GenerateExcelAction
public InputStream getDownloadFile(){
return this.service.getInputStream();
}
(4)spring配置文件注入action
<bean id="generateExcelAction" >
<property name="service" ref="userService"></property>
</bean>
(5)jsp
<s:a href="/blog_article/generateExcel.action">生成Excel</s:a>
[3] UITextField 封锁键盘
来源: 互联网 发布时间: 2014-02-18
UITextField 关闭键盘
UITextField tf; tf.delegate = self; //实现重写了textFieldShouldReturn:方法 -(BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; }
最新技术文章: