Skip to content

Commit e33f2b4

Browse files
committed
图书新增图片字段,登录md5加密
1 parent 9b16366 commit e33f2b4

16 files changed

Lines changed: 269 additions & 813 deletions

src/main/java/com/bookshop/controller/BooksController.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.io.File;
44
import java.io.IOException;
55
import java.io.UnsupportedEncodingException;
6-
import java.net.URLDecoder;
76
import java.text.SimpleDateFormat;
87
import java.util.ArrayList;
98
import java.util.Date;
@@ -13,11 +12,8 @@
1312

1413
import javax.servlet.http.HttpServletRequest;
1514

16-
import org.junit.runner.Request;
1715
import org.springframework.beans.factory.annotation.Autowired;
1816
import org.springframework.stereotype.Controller;
19-
import org.springframework.validation.BindingResult;
20-
import org.springframework.web.bind.annotation.RequestBody;
2117
import org.springframework.web.bind.annotation.RequestMapping;
2218
import org.springframework.web.bind.annotation.RequestMethod;
2319
import org.springframework.web.bind.annotation.RequestParam;
@@ -144,11 +140,6 @@ public ModelAndView addBooks(@RequestParam("bookPic")MultipartFile bookPic,HttpS
144140
req.put("bService", request.getParameter("bService"));
145141
req.put("bSaleNum", request.getParameter("bSaleNum"));
146142

147-
Books books = booksService.createBooks(req);
148-
if(books.getbAddTime()==null){
149-
books.setbAddTime(new Date());
150-
}
151-
152143
//上传图片
153144
if(!bookPic.isEmpty()) {
154145
String path=request.getSession().getServletContext().getRealPath("/img/book_images/");
@@ -171,6 +162,12 @@ public ModelAndView addBooks(@RequestParam("bookPic")MultipartFile bookPic,HttpS
171162
mav.addObject("bookPicNotExit", "未选择图书图片");
172163
}
173164

165+
req.put("bPic", newFileName);
166+
Books books = booksService.createBooks(req);
167+
if(books.getbAddTime()==null){
168+
books.setbAddTime(new Date());
169+
}
170+
174171
if (booksService.insertSelective(books) == 1) {
175172
mav.addObject("bookAddSuccess", "书籍添加成功!");
176173
//重定向到展示图书页面----------------------------未完成

src/main/java/com/bookshop/controller/UserController.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ public Map register() {
9999
return resultMap;
100100
}
101101

102+
//对密码进行Md5加密
103+
String md5Password=StringUtil.EncoderByMd5(uPassword);
102104

103-
Users users=new Users(uAccount, uPassword, uPhone,uRole);
105+
Users users=new Users(uAccount, md5Password, uPhone,uRole);
104106
if(usersService.insert(users)!=1) {
105107
resultMap.put("registerError", "服务器问题,注册失败");
106108
}else {
@@ -149,7 +151,8 @@ public Map login() {
149151
UsersExample example=new UsersExample();
150152
Criteria criteria=example.createCriteria();
151153
criteria.andUAccountEqualTo(userName);
152-
criteria.andUPasswordEqualTo(password);
154+
String md5Password=StringUtil.EncoderByMd5(password);
155+
criteria.andUPasswordEqualTo(md5Password);
153156

154157
int count=usersService.countByExample(example);
155158
if(count!=1) {

src/main/java/com/bookshop/dao/BookImagesMapper.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/main/java/com/bookshop/mapper/BookImagesMapper.xml

Lines changed: 0 additions & 140 deletions
This file was deleted.

src/main/java/com/bookshop/mapper/BooksMapper.xml

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<mapper namespace="com.bookshop.dao.BooksMapper">
44
<resultMap id="BaseResultMap" type="com.bookshop.modle.Books">
55
<id column="b_id" jdbcType="VARCHAR" property="bId" />
6+
<result column="b_pic" jdbcType="VARCHAR" property="bPic" />
67
<result column="b_name" jdbcType="VARCHAR" property="bName" />
78
<result column="b_description" jdbcType="VARCHAR" property="bDescription" />
89
<result column="b_price" jdbcType="REAL" property="bPrice" />
@@ -13,6 +14,7 @@
1314
<result column="b_add_time" jdbcType="TIMESTAMP" property="bAddTime" />
1415
<result column="b_service" jdbcType="VARCHAR" property="bService" />
1516
<result column="b_sale_num" jdbcType="INTEGER" property="bSaleNum" />
17+
<result column="b_state" jdbcType="INTEGER" property="bState" />
1618
</resultMap>
1719
<sql id="Example_Where_Clause">
1820
<where>
@@ -73,8 +75,8 @@
7375
</where>
7476
</sql>
7577
<sql id="Base_Column_List">
76-
b_id, b_name, b_description, b_price, b_discount, b_author, b_press, b_press_time,
77-
b_add_time, b_service, b_sale_num
78+
b_id, b_pic, b_name, b_description, b_price, b_discount, b_author, b_press, b_press_time,
79+
b_add_time, b_service, b_sale_num, b_state
7880
</sql>
7981
<select id="selectByExample" parameterType="com.bookshop.modle.BooksExample" resultMap="BaseResultMap">
8082
select
@@ -107,21 +109,26 @@
107109
</if>
108110
</delete>
109111
<insert id="insert" parameterType="com.bookshop.modle.Books">
110-
insert into books (b_id, b_name, b_description,
111-
b_price, b_discount, b_author,
112-
b_press, b_press_time, b_add_time,
113-
b_service, b_sale_num)
114-
values (#{bId,jdbcType=VARCHAR}, #{bName,jdbcType=VARCHAR}, #{bDescription,jdbcType=VARCHAR},
115-
#{bPrice,jdbcType=REAL}, #{bDiscount,jdbcType=INTEGER}, #{bAuthor,jdbcType=VARCHAR},
116-
#{bPress,jdbcType=VARCHAR}, #{bPressTime,jdbcType=DATE}, #{bAddTime,jdbcType=TIMESTAMP},
117-
#{bService,jdbcType=VARCHAR}, #{bSaleNum,jdbcType=INTEGER})
112+
insert into books (b_id, b_pic, b_name,
113+
b_description, b_price, b_discount,
114+
b_author, b_press, b_press_time,
115+
b_add_time, b_service, b_sale_num,
116+
b_state)
117+
values (#{bId,jdbcType=VARCHAR}, #{bPic,jdbcType=VARCHAR}, #{bName,jdbcType=VARCHAR},
118+
#{bDescription,jdbcType=VARCHAR}, #{bPrice,jdbcType=REAL}, #{bDiscount,jdbcType=INTEGER},
119+
#{bAuthor,jdbcType=VARCHAR}, #{bPress,jdbcType=VARCHAR}, #{bPressTime,jdbcType=DATE},
120+
#{bAddTime,jdbcType=TIMESTAMP}, #{bService,jdbcType=VARCHAR}, #{bSaleNum,jdbcType=INTEGER},
121+
#{bState,jdbcType=INTEGER})
118122
</insert>
119123
<insert id="insertSelective" parameterType="com.bookshop.modle.Books">
120124
insert into books
121125
<trim prefix="(" suffix=")" suffixOverrides=",">
122126
<if test="bId != null">
123127
b_id,
124128
</if>
129+
<if test="bPic != null">
130+
b_pic,
131+
</if>
125132
<if test="bName != null">
126133
b_name,
127134
</if>
@@ -152,10 +159,16 @@
152159
<if test="bSaleNum != null">
153160
b_sale_num,
154161
</if>
162+
<if test="bState != null">
163+
b_state,
164+
</if>
155165
</trim>
156166
<trim prefix="values (" suffix=")" suffixOverrides=",">
157167
<if test="bId != null">
158168
#{bId,jdbcType=VARCHAR},
169+
</if>
170+
<if test="bPic != null">
171+
#{bPic,jdbcType=VARCHAR},
159172
</if>
160173
<if test="bName != null">
161174
#{bName,jdbcType=VARCHAR},
@@ -187,6 +200,9 @@
187200
<if test="bSaleNum != null">
188201
#{bSaleNum,jdbcType=INTEGER},
189202
</if>
203+
<if test="bState != null">
204+
#{bState,jdbcType=INTEGER},
205+
</if>
190206
</trim>
191207
</insert>
192208
<select id="countByExample" parameterType="com.bookshop.modle.BooksExample" resultType="java.lang.Long">
@@ -200,6 +216,9 @@
200216
<set>
201217
<if test="record.bId != null">
202218
b_id = #{record.bId,jdbcType=VARCHAR},
219+
</if>
220+
<if test="record.bPic != null">
221+
b_pic = #{record.bPic,jdbcType=VARCHAR},
203222
</if>
204223
<if test="record.bName != null">
205224
b_name = #{record.bName,jdbcType=VARCHAR},
@@ -231,6 +250,9 @@
231250
<if test="record.bSaleNum != null">
232251
b_sale_num = #{record.bSaleNum,jdbcType=INTEGER},
233252
</if>
253+
<if test="record.bState != null">
254+
b_state = #{record.bState,jdbcType=INTEGER},
255+
</if>
234256
</set>
235257
<if test="_parameter != null">
236258
<include refid="Update_By_Example_Where_Clause" />
@@ -239,6 +261,7 @@
239261
<update id="updateByExample" parameterType="map">
240262
update books
241263
set b_id = #{record.bId,jdbcType=VARCHAR},
264+
b_pic = #{record.bPic,jdbcType=VARCHAR},
242265
b_name = #{record.bName,jdbcType=VARCHAR},
243266
b_description = #{record.bDescription,jdbcType=VARCHAR},
244267
b_price = #{record.bPrice,jdbcType=REAL},
@@ -248,14 +271,18 @@
248271
b_press_time = #{record.bPressTime,jdbcType=DATE},
249272
b_add_time = #{record.bAddTime,jdbcType=TIMESTAMP},
250273
b_service = #{record.bService,jdbcType=VARCHAR},
251-
b_sale_num = #{record.bSaleNum,jdbcType=INTEGER}
274+
b_sale_num = #{record.bSaleNum,jdbcType=INTEGER},
275+
b_state = #{record.bState,jdbcType=INTEGER}
252276
<if test="_parameter != null">
253277
<include refid="Update_By_Example_Where_Clause" />
254278
</if>
255279
</update>
256280
<update id="updateByPrimaryKeySelective" parameterType="com.bookshop.modle.Books">
257281
update books
258282
<set>
283+
<if test="bPic != null">
284+
b_pic = #{bPic,jdbcType=VARCHAR},
285+
</if>
259286
<if test="bName != null">
260287
b_name = #{bName,jdbcType=VARCHAR},
261288
</if>
@@ -286,12 +313,16 @@
286313
<if test="bSaleNum != null">
287314
b_sale_num = #{bSaleNum,jdbcType=INTEGER},
288315
</if>
316+
<if test="bState != null">
317+
b_state = #{bState,jdbcType=INTEGER},
318+
</if>
289319
</set>
290320
where b_id = #{bId,jdbcType=VARCHAR}
291321
</update>
292322
<update id="updateByPrimaryKey" parameterType="com.bookshop.modle.Books">
293323
update books
294-
set b_name = #{bName,jdbcType=VARCHAR},
324+
set b_pic = #{bPic,jdbcType=VARCHAR},
325+
b_name = #{bName,jdbcType=VARCHAR},
295326
b_description = #{bDescription,jdbcType=VARCHAR},
296327
b_price = #{bPrice,jdbcType=REAL},
297328
b_discount = #{bDiscount,jdbcType=INTEGER},
@@ -300,7 +331,8 @@
300331
b_press_time = #{bPressTime,jdbcType=DATE},
301332
b_add_time = #{bAddTime,jdbcType=TIMESTAMP},
302333
b_service = #{bService,jdbcType=VARCHAR},
303-
b_sale_num = #{bSaleNum,jdbcType=INTEGER}
334+
b_sale_num = #{bSaleNum,jdbcType=INTEGER},
335+
b_state = #{bState,jdbcType=INTEGER}
304336
where b_id = #{bId,jdbcType=VARCHAR}
305337
</update>
306338

0 commit comments

Comments
 (0)