首页 文章 精选 留言 我的

精选列表

搜索[估值水平],共10000篇文章
优秀的个人博客,低调大师

struts2-01:作用域传值

方式一、使用ServletActionContext(耦合度高,不建议使用) public String login(){ ServletActionContext.getRequest().getSession().setAttribute("user","王彬"); return "success"; } Struts.xml <action name="login" class="cn.xcq.entity.Action1" method="login"> <result>/success.jsp</result> </action> Success.jsp <%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %> <html> <head> <title>Title</title> </head> <body> <h1>成功页面</h1> ${sessionScope.user} </body> </html> 方式二、实现接口 这个案例使用session作用域,所以实现SessionAware接口 Struts2底层将作用域都封装成了Map。 public class Action1 implements SessionAware { //声明一个Map private Map<String, Object> session; //使用session需 实现sessionaware接口 //requesr RequestAware接口。。。。 public String login(){ session.put("user","程高升"); return "success"; } //重写SessionAware的setSession方法,将声明的session赋值给它 @Override public void setSession(Map<String, Object> map) { this.session=map; } } Success.jsp <%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %> <html> <head> <title>Title</title> </head> <body> <h1>成功页面</h1> ${sessionScope.user} </body> </html> 方式三、ActionContext //方式三 public String login(){ //session Map<String, Object> session = ActionContext.getContext().getSession(); session.put("user","林帅"); //request Map<String, Object> request =(Map<String, Object>) ActionContext.getContext().get("request"); request.put("name","程高升"); return "success"; }

优秀的个人博客,低调大师

[SpringMVC] Web层返回值包装JSON

由于采用前后端分离的开发方式,web层需返回JSON形式的数据。 思路 建立通用 请求响应类 Message.java 使用jackson库包装请求响应Bean 尽可能使用注解方式 代码 jackson 依赖 pom.xml <!-- 用于SpringMVC自动转换类为json --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.7.4</version> </dependency> <!-- 用于自己进行类和json的互相转换 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson.version}</version> </dependency> 请求响应Bean类 Message.java package com.spz.demo.security.bean; import com.fasterxml.jackson.annotation.JsonInclude; import com.spz.demo.security.common.MessageCode; import lombok.Data; import java.io.Serializable; import java.util.HashMap; import java.util.Map; /** * 请求响应Bean * 使用JSON包装请求返回,使用jackson库 * * @author spz */ @Data @JsonInclude(JsonInclude.Include.NON_NULL) public class Message implements Serializable { private int code ; private String message ; private Map<String,Object> data = new HashMap<String, Object>(); /** * 自定义返回 * @param code * @param message * @return */ public Message setMessage(int code, String message){ this.code = code; this.message = message; return this; } /** * 返回成功 * @return */ public Message setSuccessMessage(){ this.code = MessageCode.SUCCESS ; this.message = "操作成功" ; return this; } /** * 返回成功 * @param message * @return */ public Message setSuccessMessage(String message){ this.code = MessageCode.SUCCESS ; this.message = message ; return this; } /** * 返回错误 * @param message * @return */ public Message setErrorMessage(String message){ this.code = MessageCode.ERROR ; this.message = message ; return this; } /** * 返回警告 * @param message * @return */ public Message setWarnMessage(String message){ this.code = MessageCode.WARN ; this.message = message ; return this; } /** * 返回登录失败 * @param message * @return */ public Message setLoginFailMessage(String message){ this.code = MessageCode.LOGIN_FAILED ; this.message = message ; return this; } /** * 返回没有权限 * @param message * @return */ public Message setPermissionDeniedMessage(String message){ this.code = MessageCode.PERMISSION_DENIED ; this.message = message ; return this; } } @JsonInclude(JsonInclude.Include.NON_NULL) 表示不解析为null的字段。 Message返回码 MessageCode.java package com.spz.demo.security.common; public class MessageCode { // 请求成功 public static int SUCCESS = 2000 ; // 警告 public static int WARN = 2001; // token public static int TOKEN_ERROR = 4001;//token 不合法 public static int TOKEN_OVERDUE = 4002;//token 已过期 // 登录失败 public static int LOGIN_FAILED = 4003; // 没有权限 public static int PERMISSION_DENIED = 4004; // 服务器处理失败(常用错误) public static int ERROR = 5000 ; } Controller层方法使用范例 在Controller层使用,只需要在方法上使用*ResponseBody注解即可,SpringMVC会自动将方法返回的Message转为json @Controller @RequestMapping("/admin") public class AdminController{ // 用户登录方法 @RequestMapping(value = "/login",method = RequestMethod.POST) @ResponseBody public Message login(HttpServletRequest request)throws Exception{ //.....业务逻辑代码 // 1. 返回成功,附带数据 Message rest = new Message(). setSuccessMessage("登录成功"); rest.getData().put("loginAccount",account);//可添加一些需要显示的数据 rest.getData().put("role",1);//登录人权限 rest.getData().put("loginTime",new Date());//登录时间 //return rest;//Controller方法返回 // 2. 返回失败,不附带数据 //return new Message().setErrorMessage("请求失败,xxx") return rest; } } 在拦截器等地方返回,需要自行将Message类转为json字符串,写入response流 输出到response工具方法WebUtil.writeJSONToResponse() /** * 输出json字符串到 HttpServletResponse * @param response * @param str : 字符串 */ public static void writeJSONToResponse(HttpServletResponse response, String str){ PrintWriter jsonOut = null; response.setContentType("application/json;charset=UTF-8"); try { jsonOut = response.getWriter(); jsonOut.write(str); }catch (Exception e){ e.printStackTrace(); }finally{ if(jsonOut != null){ jsonOut.close(); } } } 使用Message和json工具类 注意JSON.toJSONString()是fastjson里的。 WebUtil.writeJSONToResponse(httpServletResponse,JSON.toJSONString( new Message().setErrorMessage("xxx错误") )); 实际返回结果 返回成功,附带数据 JSON { "code": 2000, "message": "登录成功", "data": { "loginAccount": "admin_1", "role": 1, "loginTime": "2018-04-23 10:06:35" } } 返回失败,不附带数据 JSON { "code":5000, "message":"请求失败", "data":{} } 参考Demo SpringBoot小项目快速搭建

优秀的个人博客,低调大师

iOS 数组里面取字典的值

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 NSArray *arrData = @[@ "1" ,@ "2" ,@ "3" ,@ "4" ]; NSArray *arrKey = @[@ "A" ,@ "B" ,@ "C" ,@ "D" ]; NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObjects:arrData forKeys:arrKey]; NSArray *arrData1 = @[@ "5" ,@ "6" ,@ "7" ,@ "8" ]; NSArray *arrKey1 = @[@ "E" ,@ "F" ,@ "G" ,@ "H" ]; NSMutableDictionary *dic1 = [NSMutableDictionary dictionaryWithObjects:arrData1 forKeys:arrKey1]; NSMutableArray *arr = [NSMutableArray arrayWithObjects:dic,dic1, nil]; for ( int i=0; i<[arr count]; i++) { for (id f in [arr objectAtIndex:i]) { NSLog(@ "value = %@" ,[[arr objectAtIndex:i] valueForKey:f]); NSLog(@ "key = %@" ,f); } } NSLog(@ "arr = %@" ,[arr description]); 结果: 本文转自新风作浪 51CTO博客,原文链接:http://blog.51cto.com/duxinfeng/1214724,如需转载请自行联系原作者

优秀的个人博客,低调大师

iOS开发技巧 - 使用UIPickerView来选择值

(Swift) import UIKit class ViewController: UIViewController, UIPickerViewDataSource { var picker: UIPickerView! override func viewDidLoad() { super.viewDidLoad() picker = UIPickerView() // select the current view controller as the data source of the picker view picker.dataSource = self picker!.delegate = self picker.center = view.center view.addSubview(picker) } /* Implemented some of the methods of the UIPickerViewDataSource protocol */ // returns the number of 'columns' to display func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int { if pickerView == picker { return 1 } return 0 } // returns the number of rows in each component func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { if pickerView == picker { return 10 } return 0 } } func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! { return "\(row + 1)" } (Objective-C) @interface ViewController () <UIPickerViewDataSource, UIPickerViewDelegate> @property (nonatomic, strong) UIPickerView *myPicker; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.myPicker = [[UIPickerView alloc] init]; // select the current view controller as the data source of the picker view self.myPicker.dataSource = self; self.myPicker.delegate = self; self.myPicker.center = self.view.center; [self.view addSubview:self.myPicker]; } /* Implemented some of the methods of the UIPickerViewDataSource protocol */ - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { if ([pickerView isEqual:self.myPicker]){ return 1; } return 0; } - (NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { if ([pickerView isEqual:self.myPicker]){ return 10; } return 0; } - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { if ([pickerView isEqual:self.myPicker]) { /* Row is zero-based and we want the first row (with index 0) to be rendered as Row 1, so we have to +1 every row index */ return [NSString stringWithFormat:@"Row %ld", (long)row + 1]; } return nil; }

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册