usercontroller.java,java签到功能,spring+spring MVC+hibernate框架搭建

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 param=new HashMap();

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();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值