SSM登陆注册
package com.coingod.controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.coingod.bean.User;
import com.coingod.bean.UserExample;
import com.coingod.bean.UserExample.Criteria;
import com.coingod.service.IUserService;
import com.coingod.service.system.ISysConfigService;
import com.coingod.util.JModelAndView;
@RequestMapping({ "/user" })
@Controller
public class UserControl {
@Autowired
private IUserService uservice;
// 系统参数
@Autowired
private ISysConfigService configService;
/**
* 修改用户信息
*/
@RequestMapping({ "/updateUser.htm" })
public String updateUser(User user) {
System.out.println(user);
int i = uservice.updateByPrimaryKey(user);
User user2 = new User();
user2.setAddtime(user.getAddtime());
if (i > 0) {
return "redirect:user_user.htm";
} else {
return null;
}
}
/**
* 跳转到编辑页面并显示修改数据
*/
@RequestMapping({ "/toUpdateUser.htm" })
public ModelAndView toUpdateUser(long id, HttpServletRequest request, HttpServletResponse response) {
ModelAndView mv = new JModelAndView("system/user/userUpdate.html", configService.getSysConfig(), 0, request,
response);
User user = uservice.selectByPrimaryKey(id);
mv.addObject("user", user);
return mv;
}
/**
* 根据id删除用户信息
*/
@RequestMapping({ "/delUser.htm" })
public String delUser(long id) {
int i = uservice.deleteByPrimaryKey(id);
if (i > 0) {
return "redirect:user_user.htm";
} else {
return "redirect:user_user.htm";
}
}
/**
* 添加用户
*/
@RequestMapping({ "/addUser.htm" })
public String addUser(HttpServletRequest request, HttpServletResponse response, User user) {
user.setAddtime(new Date());
int i = uservice.insertSelective(user);
if (i > 0) {
return "redirect:user_user.htm";
} else {
return "redirect:toUserAdd.htm";
}
}
/**
* 跳转到添加用户页面
*/
@RequestMapping({ "/toUserAdd.htm" })
public ModelAndView toUserAdd(HttpServletRequest request, HttpServletResponse response) {
ModelAndView mv = new JModelAndView("system/user/useradd.html", configService.getSysConfig(), 0, request,
response);
List<User> listUser = uservice.selectByExample(null);
mv.addObject("listUser", listUser);
return mv;
}
/**
* 跳转到用户管理页面
*/
@RequestMapping({ "/user_user.htm" })
public ModelAndView toShowUser(HttpServletRequest request, HttpServletResponse response, User user) {
ModelAndView mv = new JModelAndView("system/user/user.html", configService.getSysConfig(), 0, request,
response);
UserExample example = new UserExample();
Criteria c = example.createCriteria();
if (user.getUserApikey() != null && !"".equalsIgnoreCase(user.getUserApikey())) {
c.andUserApikeyLike("%" + user.getUserApikey() + "%");
}
List<User> listUser = uservice.selectByExample(example);
mv.addObject("listUser", listUser);
return mv;
}
/**
* @param userApikey
* @param userSecretkey
* @return 用户登陆
* @throws IOException
*/
@RequestMapping({ "/userlist.htm" })
public ModelAndView getUsertlist(String userApikey, String userSecretkey, String yzm, HttpSession session) throws IOException {
User users = uservice.login(userApikey, userSecretkey);
ModelAndView mv = new ModelAndView();
System.out.println(yzm);
// 判断验证码
//判断用户名
String name = (String) session.getAttribute("verify_code");
if (!name.equals(yzm)) {
System.out.println("登陆失败");
mv.setViewName("redirect:/admin/login.htm");
return mv;
} else {
}
if (users != null) {
if (users.getUserGrade() == 0 || users.getUserGrade() == 1) {
mv.addObject("users", users);
System.out.println("登陆成功");
mv.setViewName("redirect:/findAll.htm");
return mv;
}
} else {
System.out.println("登陆失败");
mv.setViewName("redirect:/admin/login.htm");
return mv;
}
System.out.println("登陆失败");
mv.setViewName("redirect:/admin/login.htm");
return mv;
}
/**
*
* ajax验证是否有用户
*
* @param request
* @param response
* @param userApikey
* @param userSecretkey
* @return
*/
@ResponseBody
@RequestMapping({ "/login_restist.htm" })
public String Login(HttpServletRequest request, HttpServletResponse response, String userApikey,
String userSecretkey) {
if (userApikey != null && !userApikey.equals("")) {
}
if (userSecretkey != null && !userSecretkey.equals("")) {
}
User u = uservice.login(userApikey, userSecretkey);
if (u != null) {
System.out.println(u);
return "true";
}
return "false";
}
@RequestMapping({ "/adminuser_list.htm" })
public ModelAndView Adminuser_list() {
ModelAndView mv = new ModelAndView();
List<User> u = uservice.userlist();
if (u != null && !u.equals("")) {
mv.addObject("ulist", u);
mv.setViewName("system/adminuserlist.jsp");
return mv;
}
return null;
}
@RequestMapping({ "/userinsert.htm" })
@ResponseBody
public Integer insert(HttpServletRequest request, HttpServletResponse response, String userApikey,
String userSecretkey, String UserPhone, String userName, String userGrade) {
User user = new User();
user.setAddtime(new Date());
if (userApikey != null && !userApikey.equals("")) {
user.setUserApikey(userApikey);
}
if (userSecretkey != null && !userSecretkey.equals("")) {
user.setUserSecretkey(userSecretkey);
}
if (UserPhone != null && !UserPhone.equals("")) {
user.setUserPhone(UserPhone);
}
if (userName != null && !userName.equals("")) {
user.setUsername(userName);
}
if (userGrade != null && !userGrade.equals("")) {
user.setUserGrade(Integer.parseInt(userGrade));
} else {
user.setUserGrade(3);// 3 普通用户
}
Integer i = uservice.insert(user);
if (i > 0) {
return i;
}
return 0;
}
}