Browse Source

修改资源图片上传的接口,资源图片路径保存到数据库。

zzy.zhiyuan.foxmail 8 years ago
parent
commit
1ca9fb0264

+ 1 - 11
src/main/java/com/ekexiu/portal/service/ImageService.java

@ -75,6 +75,7 @@ public class ImageService {
75 75
		this.imagePath = imagePath;
76 76
		this.headPath = new File(this.imagePath, "head");
77 77
		this.orgPath = new File(this.imagePath, "org");
78
		this.resourcePath = new File(this.resourcePath, "resource");
78 79
	}
79 80
80 81
	public int getLargeHeadPhotoWidth() {
@ -277,17 +278,6 @@ public class ImageService {
277 278
		}
278 279
	}
279 280
	
280
	@Post
281
	@Path("/resoure")
282
	public void saveResourcePhoto(String resourceId, String fn) throws IOException {
283
		InputStream in = new FileInputStream(new File(this.tmpPath, fn));
284
		try {
285
			IoUtil.copy(in, new FileOutputStream(new File(this.resourcePath, resourceId + ".jpg")), false, true);
286
		} finally {
287
			in.close();
288
		}
289
	}
290
291 281
	@Post
292 282
	@Path("/head")
293 283
	public void saveHeadPhoto(String id, String fn,int x,int y,int w,int h) throws JfwBaseException, SQLException, IOException {

+ 31 - 7
src/main/java/com/ekexiu/portal/service/ImagesService.java

@ -1,5 +1,10 @@
1 1
package com.ekexiu.portal.service;
2 2

3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.FileOutputStream;
6
import java.io.IOException;
7
import java.io.InputStream;
3 8
import java.sql.Connection;
4 9
import java.sql.SQLException;
5 10
import java.util.List;
@ -12,22 +17,32 @@ import org.jfw.apt.web.annotation.operate.Post;
12 17
import org.jfw.apt.web.annotation.param.JdbcConn;
13 18
import org.jfw.apt.web.annotation.param.PathVar;
14 19
import org.jfw.util.StringUtil;
20
import org.jfw.util.io.IoUtil;
15 21

16 22
import com.ekexiu.portal.dao.ImageDao;
17 23
import com.ekexiu.portal.po.Image;
18 24

19 25
@Path("/images")
20 26
public class ImagesService {
27
	private File tmpPath;
28
	private File resourcePath;
21 29
	@Autowrie
22 30
	private ImageDao imageDao;
23
	private Image image;
31
	
32
	public File getTmpPath() {
33
		return tmpPath;
34
	}
35

36
	public void setTmpPath(File tmpPath) {
37
		this.tmpPath = tmpPath;
38
	}
24 39

25
	public Image getImage() {
26
		return image;
40
	public File getResourcePath() {
41
		return resourcePath;
27 42
	}
28 43

29
	public void setImage(Image image) {
30
		this.image = image;
44
	public void setResourcePath(File resourcePath) {
45
		this.resourcePath = resourcePath;
31 46
	}
32 47

33 48
	public ImageDao getImageDao() {
@ -39,8 +54,17 @@ public class ImagesService {
39 54
	}
40 55
	
41 56
	@Post
42
	@Path
43
	public String insert(@JdbcConn(true) Connection con, String imageSrc, String resourceId) throws SQLException {
57
	@Path("/resourceImg")
58
	public String insert(@JdbcConn(true) Connection con, String resourceId, String fn) throws SQLException, IOException {
59
		InputStream in = new FileInputStream(new File(this.tmpPath, fn));
60
		try {
61
			IoUtil.copy(in, new FileOutputStream(new File(this.resourcePath, resourceId + ".jpg")), false, true);
62
		} finally {
63
			in.close();
64
		}
65
		String imageSrc = this.resourcePath + "/" + resourceId + ".jpg";
66
		System.out.println(imageSrc);
67
		Image image = new Image();
44 68
		String imageId = StringUtil.buildUUID();
45 69
		image.setImageId(imageId);
46 70
		image.setImageSrc(imageSrc);

+ 7 - 0
src/main/java/com/ekexiu/portal/service/SysService.java

@ -279,6 +279,13 @@ public class SysService {
279 279
		return StringUtil.md5(pass);
280 280
	}
281 281
282
	/**
283
	 * 验证注册时填写的手机号和邮箱是否已经注册过
284
	 * @param con
285
	 * @param key 手机号或邮箱
286
	 * @return 如果该手机或邮箱已经注册过返回false, 否则返回true
287
	 * @throws SQLException
288
	 */
282 289
	@Get
283 290
	@Path("/isReg")
284 291
	public boolean isReg(@JdbcConn Connection con, String key)