Skip to content

Commit 0471e0d

Browse files
committed
2016-05-02
1 parent 3ca009f commit 0471e0d

19 files changed

+274
-31
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

WebRoot/WEB-INF/classes/com/bishe/photo/entity/PhotoAlbumMapper.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66

77
<insert id="saveAlbum" parameterType="com.bishe.photo.entity.PhotoAlbum">
8+
<selectKey resultType="int" order="AFTER" keyProperty="id">
9+
SELECT LAST_INSERT_ID() AS id
10+
</selectKey>
811
insert into t_photoalbum(name,type,userId)
912
values(#{name,jdbcType=VARCHAR},#{type,jdbcType=NUMERIC},#{userId,jdbcType=NUMERIC})
1013
</insert>
@@ -24,4 +27,12 @@
2427
where id=#{id,jdbcType=NUMERIC}
2528
</update>
2629

30+
<select id="findById" parameterType="int" resultType="com.bishe.photo.entity.PhotoAlbum">
31+
select id,name,type,coverUrl,userId from t_photoalbum where id= #{id,jdbcType=NUMERIC}
32+
</select>
33+
34+
<update id="updateCover" parameterType="hashMap">
35+
update t_photoalbum set coverUrl = #{url,jdbcType=VARCHAR} where id= #{id,jdbcType=NUMERIC}
36+
</update>
37+
2738
</mapper>

WebRoot/WEB-INF/classes/com/bishe/photo/entity/PhotoMapper.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
33
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
44
<mapper namespace="com.bishe.photo.dao.PhotoDao">
5-
65

76
<insert id="save" parameterType="com.bishe.photo.entity.Photo">
87
<selectKey resultType="int" order="AFTER" keyProperty="id">
@@ -13,7 +12,21 @@
1312
#{belongId,jdbcType=NUMERIC},#{userId,jdbcType=NUMERIC})
1413
</insert>
1514

16-
<select id="findAll" parameterType="int" resultType="com.bishe.photo.entity.Photo">
15+
<select id="findCommentByPhotoId" parameterType="int" resultType="com.bishe.photo.entity.Comment">
16+
select * from t_comment where photoId = #{id}
17+
</select>
18+
19+
<resultMap type="com.bishe.photo.entity.Photo" id="photoMap">
20+
<id column="id" property="id"/>
21+
<collection property="comments" javaType="java.util.ArrayList"
22+
ofType="com.bishe.photo.entity.Comment" column="id"
23+
select="findCommentByPhotoId">
24+
</collection>
25+
26+
</resultMap>
27+
28+
29+
<select id="findAll" parameterType="int" resultMap="photoMap">
1730
select id,name,photoUrl,belongId
1831
from t_photo where belongId=#{belongId,jdbcType=NUMERIC}
1932
</select>
Binary file not shown.
Binary file not shown.

WebRoot/WEB-INF/classes/db.sql

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ CREATE DATABASE photo DEFAULT CHARACTER SET utf8;
33
CREATE TABLE t_user(
44
u_id int PRIMARY KEY auto_increment,
55
username varchar(32) not null default '',
6-
password varchar(32) not null default '',
6+
password varchar(32) not null default ''
77
)ENGINE=innoDB;
88

99
--角色表(序列)
@@ -44,7 +44,7 @@ ALTER TABLE t_role_privilege ADD FOREIGN KEY(role_id) REFERENCES t_role(id);
4444
--相册表
4545
CREATE TABLE t_photoalbum(
4646
id int PRIMARY KEY auto_increment,
47-
name VARCHAR(32),
47+
name VARCHAR(100),
4848
type int,
4949
coverUrl VARCHAR(32),
5050
userId int references t_user(id)
@@ -54,8 +54,19 @@ CREATE TABLE t_photoalbum(
5454

5555
CREATE TABLE t_photo(
5656
id int PRIMARY KEY auto_increment,
57-
name VARCHAR(32),
57+
name VARCHAR(100),
5858
photoUrl VARCHAR(100),
5959
belongId int references t_photoalbum(id),
6060
userId int references t_user(id)
6161
)ENGINE=innoDB;
62+
63+
64+
CREATE TABLE t_comment(
65+
id int PRIMARY KEY auto_increment,
66+
content VARCHAR(300),
67+
date Date,
68+
photoId int references t_photo(id),
69+
userId int references t_user(id),
70+
userName VARCHAR(32)
71+
)ENGINE=innoDB;
72+

src/com/bishe/photo/controller/PhotoAlbumController.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.bishe.photo.controller;
22

3+
import java.util.ArrayList;
34
import java.util.List;
45

56
import javax.servlet.http.HttpServletRequest;
@@ -12,6 +13,7 @@
1213
import org.springframework.web.bind.annotation.ResponseBody;
1314

1415
import com.bishe.photo.domain.Message;
16+
import com.bishe.photo.entity.Photo;
1517
import com.bishe.photo.entity.PhotoAlbum;
1618
import com.bishe.photo.entity.User;
1719
import com.bishe.photo.service.PhotoAlbumService;
@@ -32,11 +34,21 @@ public Message addAlbum(String name,Integer type,HttpServletRequest request){
3234
logger.info("sessionId:"+session.getId());
3335
logger.info("user:"+user);
3436
PhotoAlbum photoAlbum = new PhotoAlbum(name,type,user.getId());
35-
photoAlbumService.saveAlbum(photoAlbum);
36-
return new Message("1", "创建相册成功");
37+
Integer saveId = photoAlbumService.saveAlbum(photoAlbum);
38+
return this.findById(saveId);
3739
}
3840

3941

42+
@RequestMapping("/findById")
43+
@ResponseBody
44+
public Message findById(Integer id){
45+
logger.info("查询id为:"+id+" 的照片");
46+
PhotoAlbum photos = photoAlbumService.findById(id);
47+
List<PhotoAlbum> photoAlbum = new ArrayList<>();
48+
photoAlbum.add(photos);
49+
return new Message("1",photoAlbum);
50+
}
51+
4052
@ResponseBody
4153
@RequestMapping("/findAll")
4254
public Message findAll(HttpServletRequest request){
@@ -53,15 +65,17 @@ public Message findAll(HttpServletRequest request){
5365

5466
@ResponseBody
5567
@RequestMapping("/delete")
56-
public Message delete(Integer id){
68+
public Message delete(Integer id,HttpServletRequest request){
5769
logger.info("删除相册");
70+
logger.info("删除相册id为"+id+"的相册");
5871
try {
5972
photoAlbumService.delete(id);
6073
} catch (Exception e) {
6174
e.printStackTrace();
6275
return new Message("0","删除失败");
6376
}
64-
return new Message("1","删除成功");
77+
78+
return this.findAll(request);
6579
}
6680

6781
@ResponseBody
@@ -76,4 +90,20 @@ public Message update(PhotoAlbum photoAlbum){
7690
}
7791
return new Message("1","更新成功");
7892
}
93+
94+
95+
//设置封面
96+
@ResponseBody
97+
@RequestMapping("/setCover")
98+
public Message setCover(String url,Integer id){
99+
logger.info("更新相册id为:"+id + " --的封面为:"+url);
100+
try {
101+
photoAlbumService.updateCover(url, id);
102+
} catch (Exception e) {
103+
e.printStackTrace();
104+
return new Message("0","设置封面失败");
105+
}
106+
return new Message("1","设置封面成功");
107+
}
108+
79109
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy