Browse Source

添加按照base64转码的方式保存资源图片的接口。

zzy.zhiyuan.foxmail 8 years ago
parent
commit
d98b906e28

+ 28 - 0
src/main/java/com/ekexiu/portal/service/ImagesService.java

9
import java.sql.SQLException;
9
import java.sql.SQLException;
10
import java.util.List;
10
import java.util.List;
11

11

12
import org.jfw.util.codec.Base64;
12
import org.jfw.apt.annotation.Autowrie;
13
import org.jfw.apt.annotation.Autowrie;
13
import org.jfw.apt.web.annotation.Path;
14
import org.jfw.apt.web.annotation.Path;
14
import org.jfw.apt.web.annotation.operate.Delete;
15
import org.jfw.apt.web.annotation.operate.Delete;
78
		}
79
		}
79
	}
80
	}
80
	
81
	
82
	@Post
83
	@Path("/saveResImg")
84
	public String insertResourceImg(@JdbcConn(true) Connection con, String resourceId, String base64) throws SQLException, IOException {
85
		Base64 bs64 = new Base64();
86
		byte[] bs = bs64.decode(base64.getBytes("UTF-8"));
87
		String imageSrc = this.resourcePath + "/" + resourceId + ".jpg";
88
		FileOutputStream fos = new FileOutputStream(imageSrc);
89
		try {
90
			fos.write(bs);
91
			fos.flush();
92
		} finally {
93
			fos.close();
94
		}
95
		Image image1 = this.imageDao.queryOne(con, resourceId);
96
		if(null == image1){
97
			Image image = new Image();
98
			String imageId = StringUtil.buildUUID();
99
			image.setImageId(imageId);
100
			image.setImageSrc(imageSrc);
101
			image.setResourceId(resourceId);
102
			this.imageDao.insert(con, image);
103
			return imageId;
104
		} else {
105
			return null;
106
		}
107
	}
108
	
81
	@Put
109
	@Put
82
	@Path
110
	@Path
83
	public void update(@JdbcConn(true) Connection con, String resourceId) throws SQLException{
111
	public void update(@JdbcConn(true) Connection con, String resourceId) throws SQLException{

+ 21 - 0
src/main/java/com/ekexiu/portal/service/ResourceService.java

119
		}
119
		}
120
		return resourceId;
120
		return resourceId;
121
	}
121
	}
122
	
123
	@Post
124
	@Path("/saveRes")
125
	public String insertRes(@JdbcConn(true) Connection con, Resource resource, @Nullable String base64) {
126
		String resourceId = StringUtil.buildUUID();
127
		try {
128
			if(null != base64){
129
				this.imagesService.insertResourceImg(con, resourceId, base64);
130
			}
131
			resource.setResourceId(resourceId);
132
			this.resourceDao.insert(con, resource);
133
		} catch (SQLException | IOException e) {
134
			try {
135
				con.rollback();
136
			} catch (SQLException e1) {
137
				e1.printStackTrace();
138
			}
139
			e.printStackTrace();
140
		}
141
		return resourceId;
142
	}
122

143

123
	@Post
144
	@Post
124
	@Path("/updateResource")
145
	@Path("/updateResource")