首页>代码>maven+spring+spring mvc+mybatis整合,舒服的整合舒服的开发>/ssm/src/main/java/cn/jsxwsl/maven/ssm/controller/UserController.java
package cn.jsxwsl.maven.ssm.controller;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.jsxwsl.maven.ssm.bean.User;
import cn.jsxwsl.maven.ssm.service.UserService;


@Controller
@RequestMapping("/user")
public class UserController {

	@Autowired
	private UserService userService;
	
	// 返回页面
	@RequestMapping("/{id}.html")
	public ModelAndView getUser(@PathVariable("id")long id){
		ModelAndView md = new ModelAndView();
		User user = userService.getUserById(id);
		md.addObject("user",user);
		md.setViewName("user");
		return md;
		
	}

	// 返回json数据
	@RequestMapping("/ujson/{id}")
	@ResponseBody
	public Map<String, Object> getUserJson(@PathVariable("id") long id ){
		List<User> user = userService.getUserList();
		Map<String, Object> map = new HashMap<>();
		map.put("state", "success");
		map.put("obj", user);
		return map;
	}
	
	
	@RequestMapping("/users.html")
	public ModelAndView getUserList(){
		ModelAndView md = new ModelAndView();
//		List<User> users = userService.getUserList();
//		md.addObject("users",users);
		md.setViewName("user");
		return md;
		
	}
	
	
}
最近下载更多
李亮  LV19 2023年3月6日
543666826  LV33 2021年11月28日
hwshws  LV9 2021年5月24日
panbiao  LV11 2021年3月31日
1587767925  LV7 2020年12月17日
yangyinjie  LV2 2020年9月2日
777sssd  LV7 2020年7月10日
18337281853  LV12 2020年4月29日
blackteatea  LV3 2020年3月8日
hellozui  LV10 2019年12月30日
最近浏览更多
gecongkai  LV8 2023年6月23日
shuidajiao 2023年6月18日
暂无贡献等级
想飞的大肥猪  LV9 2023年6月12日
18303889377  LV1 2023年5月16日
zuidaima87  LV1 2023年5月12日
bibibi234  LV1 2023年4月4日
HQ 2023年3月9日
暂无贡献等级
李亮  LV19 2023年3月6日
安东尼online  LV11 2023年2月15日
LITIANYU084414  LV11 2023年1月4日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友