Java 实战范例之线上婚纱摄影预定系统的实现
作者:qq_1334611189 时间:2021-08-08 14:19:42
一、项目简述
功能: 前后用户的登录注册,婚纱照片分类,查看,摄影师预 订,后台订单管理,图片管理等等。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术:HTML+CSS+JavaScript+jsp+mysql+Spring+SpringMVC+mybatis+Spring boot
用户登陆信息操作代码:
/**
* 用户登陆信息操作
*/
@Controller
@RequestMapping("/user")
@Scope("prototype")
public class UserController {
private static final Logger logger = LoggerFactory.getLogger(UserController.class);
private ReturnResult returnResult = new ReturnResult();
@Resource(name = "userService")
private IUserService userService;
/**
* 登录
* @param user
* @param session
* @return
*/
@RequestMapping(value = "login")
@ResponseBody
public ReturnResult login(TUser user, HttpSession session) {
returnResult.setStatus(ReturnCodeType.FAILURE);
try {
user = userService.login(user);
if (user != null) {
user.setPassword(null);
session.setAttribute("user", user);
returnResult.setStatus(ReturnCodeType.SUCCESS);
}
} catch (Exception e) {
logger.error("登录失败" + e);
}
return returnResult;
}
/**
* 从session中获取用户信息
* @param session
* @return
*/
@RequestMapping("getUserInfo")
@ResponseBody
public ReturnResult getUserInfo(HttpSession session) {
returnResult.setStatus(ReturnCodeType.FAILURE);
TUser user = (TUser) session.getAttribute("user");
if (user != null) {
returnResult.setStatus(ReturnCodeType.SUCCESS).setData(user);
} else {
logger.info("获取用户信息失败:用户未登录");
}
return returnResult;
}
/**
* 注册用户
* @param user
* @return
*/
@RequestMapping(value = "register")
@ResponseBody
public ReturnResult register(TUser user) {
returnResult.setStatus(ReturnCodeType.FAILURE);
try {
if (userService.checkUserByName(user.getName())) {
if (userService.register(user) >= 0) {
returnResult.setStatus(ReturnCodeType.SUCCESS);
}
}
} catch (Exception e) {
logger.error("注册失败" + e);
}
return returnResult;
}
/**
* 检测用户名是否存在
* @param name
* @return
*/
@RequestMapping(value = "checkUserName")
@ResponseBody
public ReturnResult checkUserName(String name) {
returnResult.setStatus(ReturnCodeType.FAILURE);
try {
if (userService.checkUserByName(name)) {
returnResult.setStatus(ReturnCodeType.SUCCESS);
}
} catch (Exception e) {
logger.error("检测用户名是否存在失败:" + e);
}
return returnResult;
}
/**
* 管理员查看所有的用户信息
* @param session
* @return
*/
@RequestMapping("getAllUserInfo")
@ResponseBody
public ReturnResult getAllUserInfo(HttpSession session,PageVO page,String name) {
returnResult.setStatus(ReturnCodeType.FAILURE);
try {
if (session.getAttribute("admin") != null) {
Map<String, Object> resultMap = new HashMap<String, Object>();
StringBuffer sql = new StringBuffer("SELECT DISTINCT * FROM t_user WHERE 1=1");
if(StringUtils.isNotBlank(name)){
sql.append(" AND name="+name);
}
List<Map<String, Object>> results = userService.selectPageBySQL(sql.toString(), page.getPage() - 1,
page.getRows());
if (!results.isEmpty() && results != null) {
int total = userService.selectCount(new TUser());
int rows = page.getRows();
rows = rows == 0 ? 10 : rows;
resultMap.put("total", (total % rows != 0 ? (total / rows + 1) : (total / rows)));
resultMap.put("page", page.getPage());
resultMap.put("records", total);
resultMap.put("rows", results);
returnResult.setStatus(ReturnCodeType.SUCCESS).setData(resultMap);
}
} else {
logger.info("获取所有的用户信息失败:管理员未登录");
}
} catch (Exception e) {
logger.error("获取所有的用户信息失败:" + e);
}
return returnResult;
}
/**
* 退出
* @param session
* @return
*/
@RequestMapping("logout")
@ResponseBody
public ReturnResult logout(HttpSession session) {
session.invalidate();
return returnResult.setStatus(ReturnCodeType.SUCCESS);
}
/**
* 修改密码
* @param oldPassword
* @param password
* @param session
* @return
*/
@RequestMapping("updatePassword")
@ResponseBody
public ReturnResult updatePassword(TUser user) {
returnResult.setStatus(ReturnCodeType.FAILURE);
try {
if (userService.updatePassword(user) > 0) {
returnResult.setStatus(ReturnCodeType.SUCCESS);
}
} catch (Exception e) {
logger.error("修改密码失败:" + e);
}
return returnResult;
}
}
来源:https://blog.csdn.net/m0_59687645/article/details/121204024
标签:Java,婚纱摄影,预定系统
0
投稿
猜你喜欢
c#和net存取cookies操作示例
2023-10-11 15:28:26
java如何读取超大文件
2022-10-24 08:20:54
Java并发框架:Executor API详解
2021-10-31 14:30:28
java 二分法算法的实例
2023-04-25 05:04:05
Android编程设计模式之原型模式实例详解
2021-09-14 02:20:47
spring boot入门之诞生背景及优势影响
2021-09-16 06:31:57
Java中Thread类详解及常用的方法
2022-09-29 11:35:44
详解Spring Boot微服务如何集成fescar解决分布式事务问题
2022-01-21 18:43:51
IDEA中已配置阿里镜像但maven无法下载jar包的问题及解决方法
2021-11-09 11:06:53
解决IDEA和CMD中java命令提示错误: 找不到或无法加载主类的问题
2023-09-19 02:31:16
Spring Boot2.x如何自定义Endpoint
2023-03-05 18:04:12
C#中如何使用Chart图表问题
2023-04-02 16:35:06
C#使用WebService结合jQuery实现无刷新翻页的方法
2022-02-23 12:00:32
如何解决通过spring-boot-maven-plugin package失败问题
2021-10-16 15:43:45
Java实现简易界面通讯录
2023-02-09 20:12:59
c#学习之30分钟学会XAML
2022-02-08 03:09:52
java异常处理执行顺序详解try catch finally
2022-10-01 04:10:10
C#实现顺序表(线性表)完整实例
2022-06-04 15:42:31
浅析Java中JSONObject和JSONArray使用
2022-06-05 14:58:30
Java中的synchronized关键字
2023-07-28 18:39:26