首页>代码>spring mvc+spring+mybatis用户后台登录注册maven项目,仅供入门学习>/comicproject/src/main/java/com/jit/comic/controller/UserController.java
/**
 * 
 */
package com.jit.comic.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

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.jit.comic.model.User;
import com.jit.comic.service.UserService;

import net.sf.json.JSONObject;

/**
 * @author suewong
 * 上午11:13:49
 * @param
 *since 1.0
 */
@Controller
public class UserController {
	
	@Autowired
	private UserService userservice;
	private boolean flag;
	ModelAndView mv=new ModelAndView();
	String resp="";
	
	
	@RequestMapping("/toRegister")
	public ModelAndView toRegister(){
		
		mv.setViewName("html/register");
		return mv;
	}
	
	
	
	
	
	
	@RequestMapping("/register")
	@ResponseBody
	public String userRegister(String userinfo){
		System.out.println(userinfo.toString());
		JSONObject obj = JSONObject.fromObject(userinfo);
		User user=new User();
		user.setUsername(obj.getString("username"));
		user.setPassword(obj.getString("password"));
		try {
			
			flag=userservice.userRegister(user);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(flag==true){
			resp="success";
		}else{
			resp="error";
		}
		return resp;
	}
	
	
	@RequestMapping("/toLogin")
	public ModelAndView toLogin(){
		mv.setViewName("html/login");
		return mv;
	}
	
	@RequestMapping("/login")
	@ResponseBody
	public String userLogin(String userinfo,HttpServletResponse response){

	
		JSONObject obj = JSONObject.fromObject(userinfo);
		User user=new User();
		user.setUsername(obj.getString("username"));
		user.setPassword(obj.getString("password"));
		try {
			flag=userservice.userLogin(user);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(flag==true){
			resp="success";
			
		}else{
			  
         
			resp="error";
		}
		
		return resp;
	}
}
最近下载更多
微信网友_6802079662936064  LV3 2024年1月2日
微信网友_6536105093189632  LV1 2023年6月26日
gecongkai  LV8 2023年6月22日
女王不该在山炮村养花  LV8 2023年4月13日
李亮  LV19 2023年3月5日
ITabcace  LV1 2022年12月16日
唐文慧  LV1 2022年11月23日
多次抛弃前妻  LV4 2022年6月6日
dingguanchen  LV6 2022年2月17日
13112360  LV2 2021年12月16日
最近浏览更多
zhoubowen  LV3 2024年12月29日
xiaoaitx  LV8 2024年11月19日
M0netxxx 2024年11月19日
暂无贡献等级
Wzzzccc 2024年10月21日
暂无贡献等级
lun123456 2024年6月22日
暂无贡献等级
qiwwwww  LV2 2024年6月20日
szqqqaaqqa  LV1 2024年6月20日
adminww1234  LV1 2024年6月17日
哇哇敲代码  LV1 2024年3月20日
微信网友_6802079662936064  LV3 2023年12月31日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友