-
Notifications
You must be signed in to change notification settings - Fork 700
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
修复多用户同时注册时可能造成用户名重复的bug;新增UserDao的SpringJDBC模板类实现
- Loading branch information
Showing
9 changed files
with
186 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,10 @@ | |
<li>未经许可不得将本项目商用,如需商用请联系作者<a href="mailto:[email protected]">[email protected]</a></li> | ||
</ul> | ||
<h2>关键技术</h2> | ||
<p>基于SSM框架开发</p> | ||
<p>基于SSM框架开发的商城系统,代码严格遵循MVC分层思想,可部署到服务器上,设计精良,不断完善</p> | ||
<h3>前端</h3> | ||
<ul> | ||
<li>前端对应View层</li> | ||
<li>前端使用jsp页面展示,并通过EL表达式接收服务器打给浏览器的数据</li> | ||
<li>使用js实现网页动态效果,通过jQuery简化操作,并配合html5实现前端的数据校验</li> | ||
<li>使用Ajax技术完成前端用户名可用性校验、退出登录功能</li> | ||
|
@@ -152,6 +153,16 @@ | |
</td> | ||
<td>2020年9月25日</td> | ||
</tr> | ||
<tr> | ||
<td>0.3.1</td> | ||
<td> | ||
<ul> | ||
<li>新增UserDao的SpringJDBC模板类实现</li> | ||
<li>注册用户功能开启事务,修复多个用户同时注册时可能造成用户名重复的bug</li> | ||
</ul> | ||
</td> | ||
<td>2020年9月29日</td> | ||
</tr> | ||
</table> | ||
<h2>配置情况</h2> | ||
<ul> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package com.supermarket.dao; | ||
|
||
import com.supermarket.domain.User; | ||
import com.supermarket.domain.UserImpl; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.jdbc.core.BeanPropertyRowMapper; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class UserJDBC implements UserDao { | ||
@Autowired | ||
private JdbcTemplate jdbcTemplate = null; | ||
|
||
@Override | ||
public User queryUser(User user) { | ||
List<? extends User> users = this.queryUsers(user); | ||
if (users.isEmpty()) | ||
return null; | ||
else | ||
return users.get(0); | ||
} | ||
|
||
@Override | ||
public List<? extends User> queryUsers(User user) { | ||
if (user == null) | ||
return new LinkedList<>(); | ||
String sql = "select * from user where 1 = 1"; | ||
List<Object> args = new LinkedList<Object>(); | ||
if (user.getId() != 0) { | ||
sql = sql + " and id = ?"; | ||
args.add(user.getId()); | ||
} | ||
if (user.getUsername() != null) { | ||
sql = sql + " and username = ?"; | ||
args.add(user.getUsername()); | ||
} | ||
if (user.getPassword() != null) { | ||
sql = sql + " and password = ?"; | ||
args.add(user.getPassword()); | ||
} | ||
if (user.getNickname() != null) { | ||
sql = sql + " and nickname = ?"; | ||
args.add(user.getNickname()); | ||
} | ||
if (user.getEmail() != null) { | ||
sql = sql + " and email = ?"; | ||
args.add(user.getEmail()); | ||
} | ||
List<? extends User> users = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(UserImpl.class), args.toArray()); | ||
return users; | ||
} | ||
|
||
@Override | ||
public User queryUser(Map<String, Object> map) { | ||
List<? extends User> users = this.queryUsers(map); | ||
if (users.isEmpty()){ | ||
return null; | ||
}else { | ||
return users.get(0); | ||
} | ||
} | ||
|
||
@Override | ||
public List<? extends User> queryUsers(Map<String, Object> map) { | ||
if (map == null) | ||
return new LinkedList<>(); | ||
String sql = "select * from user where 1 = 1"; | ||
List<Object> args = new LinkedList<Object>(); | ||
if (map.get("id") != null) { | ||
sql = sql + " and id = ?"; | ||
args.add(map.get("id")); | ||
} | ||
if (map.get("username") != null) { | ||
sql = sql + " and username = ?"; | ||
args.add(map.get("username")); | ||
} | ||
if (map.get("password") != null) { | ||
sql = sql + " and password = ?"; | ||
args.add(map.get("password")); | ||
} | ||
if (map.get("nickname") != null) { | ||
sql = sql + " and nickname = ?"; | ||
args.add(map.get("nickname")); | ||
} | ||
if (map.get("email") != null) { | ||
sql = sql + " and email = ?"; | ||
args.add(map.get("email")); | ||
} | ||
List<? extends User> users = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(UserImpl.class), args.toArray()); | ||
return users; | ||
} | ||
|
||
@Override | ||
public void insertUser(User user) { | ||
if (user == null) | ||
return; | ||
this.jdbcTemplate.update( | ||
"insert into user (id, username, password, nickname, email) values (?, ?, ?, ?, ?)", | ||
user.getId(), | ||
user.getUsername(), | ||
user.getPassword(), | ||
user.getNickname(), | ||
user.getEmail() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.supermarket.exception; | ||
|
||
public class MsgRollbackException extends MsgException{ | ||
/** | ||
* 韩餐构造方法 | ||
* | ||
* @param message 在网页中的提示信息 | ||
*/ | ||
public MsgRollbackException(String message) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters