SpringMVC中通过@ResponseBody返回对象,Js中调用@ResponseBody返回值,统计剩余评论字数的js,@RequestParam默认值,@PathVariable的用法
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的用法的更多相关文章
- hibernate 返回对象指定属性,需要返回的列,可以直接返回 对象属性
// hibernate 返回对象指定属性,需要返回的列,可以直接返回 对象属性 @Override public TeamPlan getTeamPlanByBaoMingId(String bao ...
- [Effective C++ --021]必须返回对象时,别妄想返回其reference
引言 在条目20中,我们知道了值传递和引用传递的效率问题,因此在设计程序时,我们可能就尽可能来返回引用而不是值. 可是,可能会犯下面的一些错误:传递一些引用指向其实并不存在的对象. 第一节:返回临时变 ...
- 条款21: 必须返回对象时,不要强行返回对象的reference
总结: 绝不要返回一个local栈对象的指针或引用:绝不要返回一个被分配的堆对象的引用:绝不要返回一个静态局部对象(为了它,有可能同时需要多个这样的对象的指针或引用). 条款4中给出了“在单线程环境中 ...
- 条款21:必须返回对象object时,不要返回其引用reference
如下为一个有理数类,其中包含一个用来计算乘积的函数: #include <iostream> using namespace std; class Rational { public: R ...
- 【21】必须返回对象时,别妄想返回器reference
1.考虑有理数Rational,有个友元操作符*,返回Rational对象.返回对象,导致临时对象的构造,析构.效率低,因此会想返回方法内局部对象的引用,这种方法不可行.为什么? 2.调用方法是在st ...
- 切记切记:Spring配置文件中,Component-scan无法扫描到的类中的自动装配对象无法被调用,报空指针错误。
Spring单例注入,单例对象可设置成Spring元件. 只有Spring的元件中@Autowired才有用,在普通类中@Autowired虽然不会编译报错,但运行时会报空指针错误.
- C#中获取多个对象list中对象共有的属性项
场景 有一组数据list<TestDataList> 每一个TestDataList是一个对象,此对象可能有温度数据,也可能没有温度数据. 有温度数据的情况下,温度数据属性又是一个list ...
- objective-c中自己创建的对象为什么不能调用release
dealloc方法,本就不应该手动调用. 你自己创建的对象,看你代码怎么写的了.例子:NSString *str1 = [NSString stringWithString:@"abc&qu ...
- Effective C++ -----条款21:必须返回对象时,别妄想返回其reference
绝不要返回pointer或reference指向一个local stack对象,或返回reference指向一个heap-allocated对象,或返回pointer或reference指向一个loc ...
随机推荐
- 容器化现有ASP.NET MVC 5应用
.NET Core的出现使得ASP.NET应用在Linux环境下使用变得更加普及.而配合上Docker容器,令ASP.NET应用的布署与管理也变得更加方便.在新的项目中运用ASP.NET Core无可 ...
- Oracle12c中SQL性能优化(SQL TUNING)新特性之自动重优化(automatic reoptimization)
Oracle12c中的自动重优化 Oracle12c中的自适应查询优化有一系列不同特点组成.像自适应计划(AdaptivePlans)功能可以在运行时修改执行计划,但并不允许计划中连接顺序的改变.自动 ...
- 工作流引擎 Flowable 6.0.0.RC1 release,完全兼容Activi
Flowable 6.0.0.RC1 release,第一个可流动的6引擎版本(6.0.0.RC1). Flowable 6.0.0.RC1 relase新增加的功能以及特色: 包重命名为org.Fl ...
- android JNI的.so库调用
在一篇博客中看到一篇文章,感觉描述的还可以: 在前面的博客中介绍的都是使用java开发Android应用,这篇博客将介绍java通过使用jni调用c语言做开发 为了更加形象的介绍jni,先观察下面的图 ...
- NLP系列(4)_朴素贝叶斯实战与进阶
作者: 寒小阳 && 龙心尘 时间:2016年2月. 出处:http://blog.csdn.net/han_xiaoyang/article/details/50629608 htt ...
- Swift对象实例方法名混淆的解决
在Xcode7.x中,比如有以下一个类: class Foo{ func test(v:Int,before:Int)->Int{ return v + 1 } } 我可以直接这么做: let ...
- logstash分析日志
待处理日志格式如下: [totalCount: 298006556, count: 287347623, queryCount: 259027994, exeCount: 28319629, tota ...
- Android Multimedia框架总结(十八)Camera2框架从Java层到C++层类关系
Agenda: getSystemService(Context.CAMERA_SERVICE) CameraManager.getCameraIdList() ICameraService.aidl ...
- Swift中方法闭包参数不能省略括号的一种情况
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 我们知道在swift中,如果方法的最后一个参数是一个闭包类型, ...
- java虚拟机 jvm 方法区实战
和java堆一样,方法区是一块所有线程共享的内存区域,用于保存系统的类信息,类的信息有哪些呢.字段.方法.常量池.方法区也有一块内存区域所以方法区的内存大小,决定了系统可以包含多少个类,如果系统类太多 ...