首页>代码>java签到功能,spring+spring MVC+hibernate框架搭建>/sign/src/cfw/controller/UserController.java
package cfw.controller;


import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cfw.model.Sign;
import cfw.model.User;
import cfw.service.SignService;
import cfw.service.UserService;

@Controller
@RequestMapping("/user/")
public class UserController {
	
	@Autowired
	@Qualifier("userService")
	private UserService userService;
	@Autowired
	@Qualifier("signService")
	private SignService signService;
	//登录简单的验证
	@ResponseBody
	@RequestMapping(value="/login/")
	public String login(HttpServletRequest request , ModelMap model){
		String username=request.getParameter("username");
		String password=request.getParameter("password");
		Map<String,Object> param=new HashMap<String,Object>();
		param.put("username", username);
		param.put("password", password);
		User user=this.userService.getUserByParam(param);
		if(user==null){
			return "0";
		}
		request.getSession().setAttribute("user", user);
		return "1";
	}
	@RequestMapping(value="/index/")
	public String index(HttpServletRequest request , ModelMap model){
		User user=(User) request.getSession().getAttribute("user");
		if(user==null){
			//未登录转到登录页面 WEB-INF/index.jsp
			return "redirect:/"; 
		}
		//判断用户是否签到
		int is_sign=this.signService.isSign(user);
		model.addAttribute("user", user);
		model.addAttribute("is_sign", is_sign);
		return "/user";
	}
	//签到
	@ResponseBody
	@RequestMapping(value="/sign/")
	public String sign(HttpServletRequest request , ModelMap model){
		User user=(User) request.getSession().getAttribute("user");
		this.signService.sign(user);
		return "";
	}
	
	//获取签到历史
	@ResponseBody
	@RequestMapping(value="/getSign/")
	public String getSign(HttpServletRequest request , ModelMap model){
		User user=(User) request.getSession().getAttribute("user");
		String year=request.getParameter("year");
		String month=request.getParameter("month");
		Sign sign=this.signService.getSign(user,year,month);
		JSONObject jsonObject=JSONObject.fromObject(sign);
		return jsonObject.toString();
	}
}
最近下载更多
aihdgt  LV1 2023年6月14日
a6134034  LV2 2023年2月24日
蓝哈哈  LV1 2022年5月24日
不懂不懂  LV1 2022年5月18日
axiaobai  LV5 2022年2月21日
mudingc木钉  LV30 2021年6月11日
1161371062  LV1 2021年5月27日
迷彩风情  LV26 2021年3月4日
Hadoop_CPU  LV6 2020年12月22日
2869580060  LV10 2020年5月14日
最近浏览更多
bai fei liu  LV1 4月19日
谢尚证 4月9日
暂无贡献等级
SZEPEZS  LV8 3月15日
微笑刺客  LV15 2023年12月8日
uni-code_0123  LV1 2023年12月7日
husiyu  LV3 2023年10月15日
aihdgt  LV1 2023年6月14日
鹅鹅鹅饿 2023年6月6日
暂无贡献等级
a小塔塔 2023年4月26日
暂无贡献等级
女王不该在山炮村养花  LV8 2023年4月22日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友