1、SpringMVC中通过@ResponseBody、@RequestParam默认值,@PathVariable的用法

package com.kuman.cartoon.controller.friendsfuns;

import java.util.ArrayList;

import java.util.List;

import java.util.Map;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.util.CollectionUtils;

import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.bind.annotation.SessionAttributes;

import com.kuman.cartoon.common.Page;

import com.kuman.cartoon.common.controller.BaseController;

import com.kuman.cartoon.entity.Friend;

import com.kuman.cartoon.entity.User;

import com.kuman.cartoon.service.UserService;

/**

* "我的好友"和"我的粉丝"部分的代码

*

* 修改原来的好友和粉丝部分的代码

*

* @author to.to

*/

@Controller

@RequestMapping(value = "/friendsAndFuns", method = { RequestMethod.GET,

RequestMethod.POST })

@SessionAttributes(value = { "accountid", "account" })

public class FriendsAndFuns extends BaseController {

@SuppressWarnings("unused")

private static final Logger LOGGER = LoggerFactory

.getLogger(FriendsAndFuns.class);

@Autowired

UserService userService;

/**

* 跳转到"我的好友"和"我的关注页面"

*

* @param userId

*            用户登录用的Id

* @param friendId

*            登录用户的好友的Id

* @param pageNo

*            当前页码数

* @param pageRow

*            每页显示条数

* @return

*/

@RequestMapping(value = "/toFriendFuns/{userId}")

public String toFriendFuns(

Model model,

@PathVariable("userId") int userId,

@RequestParam(value = "pageNo", required = false, defaultValue = "1") int pageNo,

@RequestParam(value = "pageRow", required = false, defaultValue = "12") int pageRow,

@RequestParam(value = "friendId", required = false, defaultValue = "-1") int friendId) {

// 1、判断用户是否登陆过了,如果登录过了直接进入到后续过程

User user = isLogin(model);

if (null == user) {

return "redirect:/user/login";

} else {

// 如果有了直接调转到登陆页面

// LOGGER.info("friendId = " + friendId);

// LOGGER.info("pageNo = " + pageNo);

// LOGGER.info("pageRow = " + pageRow);

model.addAttribute("user", user);

model.addAttribute("friendId", friendId);

model.addAttribute("pageNo", pageNo);

model.addAttribute("pageRow", pageRow);

return "/web/friendsfuns/friendfuns";

}

}

/**

* 显示关注的用户

*

* @param map

* @param userId

* @param pageNo

* @param pageRow

* @return

*/

@SuppressWarnings({ "unchecked", "rawtypes" })

@RequestMapping(value = "/follow/{userId}", produces = { "text/html" })

public String showFollow(

Map<String, Object> map,

Model model,

@PathVariable("userId") int userId,

@RequestParam(value = "friendId", required = false, defaultValue = "-1") int friendId,

@RequestParam(value = "pageNo", required = false, defaultValue = "1") int pageNo,

@RequestParam(value = "pageRow", required = false, defaultValue = "12") int pageRow) {

// 1、判断用户是否登录了,如果登录了直接查询,如果没有要跳转到登录页面

User loginedUser = isLogin(model);

if (null == loginedUser) {

return "redirect:/user/login";

} else {

User user = userService.queryUser(userId, false);

Page page = userService.queryUserByFansId(pageNo, pageRow,

user.getUserId());

// 关注的好友

List<Object> fUserList = new ArrayList<Object>();

for (Object o : page.getRecordList()) {

Friend friend = (Friend) o;

// 关注的好友

User fUser = friend.getUser();

// 关注的好友所关注的好友

List<Friend> friendList = userService.queryUserByFansId(fUser

.getUserId());

if (!CollectionUtils.isEmpty(friendList)) {

fUser.setFollowCount(friendList.size());

}

fUserList.add(friend);

}

page.setRecordList(fUserList);

// 用户信息

map.put("user", user);

map.put("page", page);

return "/web/friendsfuns/follow";

}

}

/**

* 用于模拟跳转到"动态管理"页面中去

*

* @param model

* @return

*/

@RequestMapping(value = "/toUserDy/{userId}")

public String toUserDy(Model model, @PathVariable("userId") int userId) {

return "/web/friendsfuns/userdy";

}

/**

* 获取粉丝信息

*

* @param map

* @param userId

* @param pageNo

* @param pageRow

* @return

*/

@SuppressWarnings({ "rawtypes", "unchecked" })

@RequestMapping(value = "/funs/{userId}", produces = { "text/html" })

public String showFuns(

Map<String, Object> map,

Model model,

@PathVariable("userId") int userId,

@RequestParam(value = "friendId", required = false, defaultValue = "-1") int friendId,

@RequestParam(value = "pageNo", required = false, defaultValue = "1") int pageNo,

@RequestParam(value = "pageRow", required = false, defaultValue = "12") int pageRow) {

// 1、判断用户是否已经登录进去了,如果登录进去了,则可以查询自己的粉丝

User loginedUser = isLogin(model);

if (null == loginedUser) {

return "redirect:/user/login";

} else {

User user = userService.queryUser(userId, false);

Page page = userService.queryFansByUserId(pageNo, pageRow, userId);

// 粉丝

List<Object> fUserList = new ArrayList<Object>();

for (Object o : page.getRecordList()) {

Friend friend = (Friend) o;

// 粉丝

User fUser = friend.getFans();

// 粉丝所关注的好友

List<Friend> friendList = userService.queryUserByFansId(fUser

.getUserId());

if (!CollectionUtils.isEmpty(friendList)) {

fUser.setFollowCount(friendList.size());

}

fUserList.add(friend);

}

page.setRecordList(fUserList);

map.put("user", user);

map.put("page", page);

return "/web/friendsfuns/funs";

}

}

}

SpringMVC中通过@ResponseBody返回对象,Js中调用@ResponseBody返回值,统计剩余评论字数的js,@RequestParam默认值,@PathVariable的用法的更多相关文章

  1. hibernate 返回对象指定属性,需要返回的列,可以直接返回 对象属性

    // hibernate 返回对象指定属性,需要返回的列,可以直接返回 对象属性 @Override public TeamPlan getTeamPlanByBaoMingId(String bao ...

  2. [Effective C++ --021]必须返回对象时,别妄想返回其reference

    引言 在条目20中,我们知道了值传递和引用传递的效率问题,因此在设计程序时,我们可能就尽可能来返回引用而不是值. 可是,可能会犯下面的一些错误:传递一些引用指向其实并不存在的对象. 第一节:返回临时变 ...

  3. 条款21: 必须返回对象时,不要强行返回对象的reference

    总结: 绝不要返回一个local栈对象的指针或引用:绝不要返回一个被分配的堆对象的引用:绝不要返回一个静态局部对象(为了它,有可能同时需要多个这样的对象的指针或引用). 条款4中给出了“在单线程环境中 ...

  4. 条款21:必须返回对象object时,不要返回其引用reference

    如下为一个有理数类,其中包含一个用来计算乘积的函数: #include <iostream> using namespace std; class Rational { public: R ...

  5. 【21】必须返回对象时,别妄想返回器reference

    1.考虑有理数Rational,有个友元操作符*,返回Rational对象.返回对象,导致临时对象的构造,析构.效率低,因此会想返回方法内局部对象的引用,这种方法不可行.为什么? 2.调用方法是在st ...

  6. 切记切记:Spring配置文件中,Component-scan无法扫描到的类中的自动装配对象无法被调用,报空指针错误。

    Spring单例注入,单例对象可设置成Spring元件. 只有Spring的元件中@Autowired才有用,在普通类中@Autowired虽然不会编译报错,但运行时会报空指针错误.

  7. C#中获取多个对象list中对象共有的属性项

    场景 有一组数据list<TestDataList> 每一个TestDataList是一个对象,此对象可能有温度数据,也可能没有温度数据. 有温度数据的情况下,温度数据属性又是一个list ...

  8. objective-c中自己创建的对象为什么不能调用release

    dealloc方法,本就不应该手动调用. 你自己创建的对象,看你代码怎么写的了.例子:NSString *str1 = [NSString stringWithString:@"abc&qu ...

  9. Effective C++ -----条款21:必须返回对象时,别妄想返回其reference

    绝不要返回pointer或reference指向一个local stack对象,或返回reference指向一个heap-allocated对象,或返回pointer或reference指向一个loc ...

随机推荐

  1. sololearn的c++学习记录_4m11d

    Function Templates Functions and classes help to make programs easier to write, safer, and more main ...

  2. 学习ASP.NET Core Razor 编程系列七——修改列表页面

    学习ASP.NET Core Razor 编程系列目录 学习ASP.NET Core Razor 编程系列一 学习ASP.NET Core Razor 编程系列二——添加一个实体 学习ASP.NET ...

  3. Android Studio精彩案例(七)《ToolBar使用详解<一>》

    转载本专栏文章,请注明出处,尊重原创 .文章博客地址:道龙的博客 本文参考博客:http://blog.csdn.net/h_zhang/article/details/51232773 http:/ ...

  4. lucene全文检索基础

    全文检索是一种将文件中所有文本与检索项匹配的文字资料检索方法.比如用户在n个小说文档中检索某个关键词,那么所有包含该关键词的文档都返回给用户.那么应该从哪里入手去实现一个全文检索系统?相信大家都听说过 ...

  5. jdbc批量插入

    分享牛,分享牛原创.有这样一个需求,文本文件中的数据批量的插入mysql,怎么用jdbc方式批量插入呢? jdbc默认提供了批量插入的方法,可能用一次就忘记了,这里做笔记记录一下jdbc批量插入吧. ...

  6. Excel 、数据库 一言不合就转换

    Excel 与数据库 对于从事相关行业的小伙伴们而言,可谓是再熟悉不过了,但是面对这两者的转换,你是否已经手忙脚乱,乃至焦头烂额? 还好,今后你将不再受此折磨.不再有日日夜夜加班导入数据的枯燥工作,不 ...

  7. Premake可生成vcxproj.filters

    Premake可生成vcxproj.filters (金庆的专栏) 添加 vcxproj.filters 文件可以用目录结构组织源文件. 例如premake5添加所有文件: files {       ...

  8. 给定一个实数数组,按序排列(从小到大),从数组从找出若干个数,使得这若干个数的和与M最为接近,描述一个算法,并给出算法的复杂度。

    有N个正实数(注意是实数,大小升序排列) x1 , x2 ... xN,另有一个实数M. 需要选出若干个x,使这几个x的和与 M 最接近. 请描述实现算法,并指出算法复杂度. #define M 8 ...

  9. pandas小记:pandas时间序列分析和处理Timeseries

    http://blog.csdn.net/pipisorry/article/details/52209377 其它时间序列处理相关的包 [P4J 0.6: Periodic light curve ...

  10. React native和原生之间的通信

    RN中文网关于原生模块(Android)的介绍可以看到,RN前端与原生模块之 间通信,主要有三种方法: 1)使用回调函数Callback,它提供了一个函数来把返回值传回给JavaScript. 2)使 ...