我有一个产品列表,我从webservice检索,当应用程序第一次打开时,应用程序从webservice获取产品列表.我想将此列表保存到共享首选项.
List<Product> medicineList = new ArrayList<Product>();
Run Code Online (Sandbox Code Playgroud)
产品类是:
public class Product {
public final String productName;
public final String price;
public final String content;
public final String imageUrl;
public Product(String productName, String price, String content, String imageUrl) {
this.productName = productName;
this.price = price;
this.content = content;
this.imageUrl = imageUrl;
}
}
Run Code Online (Sandbox Code Playgroud)
我如何保存此列表不是每次都从webservice请求?
我试图在HashMap中找到一个键.我可以使用'get'打印所选键,但是当我在if语句中使用'containsKey'时,找不到它.
我知道密钥存在于Map中,但它一直返回false.人们有什么想法?
我的代码:
public static boolean checkLowerStructuralSupport(Location location) {
boolean hasSupport = false;
Location supportingLocation = new Location(location.getX(), location.getY(), location.getZ() - 1);
System.out.println(_levels.get(supportingLocation.getZ()).getLevelSites2().get(supportingLocation)); //works
if (_levels.get(supportingLocation.getZ()).getLevelSites2().containsKey(supportingLocation)) {
hasSupport = true;
} else {
hasSupport = false;
}
return hasSupport;
}
Run Code Online (Sandbox Code Playgroud)
以下是Location类的代码:
public class Location {
protected int _x;
protected int _y;
protected int _z;
public Location(int xAxis, int yAxis, int zAxis) {
this._x = xAxis;
this._y = yAxis;
this._z = zAxis;
}
public void equals() {
//not implemented yet
} …Run Code Online (Sandbox Code Playgroud) 我检索从MySQL领域的日期时间,但我需要详谈了到最近的10分钟.
例如,如果日期时间是2013-11-06 14:00:01,我想将时间返回到2013年6月11日14:10.
最简单的方法是什么?
$datetime = new DateTime($mysqldata);
echo $datetime->format('d/m/Y G:i');
Run Code Online (Sandbox Code Playgroud)
任何建议表示赞赏
谢谢.
我有一个使用xib文件创建的自定义UIButton.当我在我的视图上使用我的自定义按钮时,按下它时它不起作用.
我的RoundBtn.swift文件:
import UIKit
@IBDesignable class RoundBtn: UIButton {
var nibName = "RoundBtn"
@IBOutlet weak var btnImageView: UIImageView!
@IBOutlet weak var btnLabel: UILabel!
@IBInspectable var image: UIImage? {
get {
return btnImageView.image
} set(image) {
btnImageView.image = image
}
}
@IBInspectable var label: String? {
get {
return btnLabel.text
} set(label) {
btnLabel.text = label
}
}
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
func setup() {
let view = …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的字符串:
String text = "new SingleSizeProduct(422056, 1265858, 5430, '3XL', 75, 0, '14.90', '16.50', '29.90', 'TL'),new SingleSizeProduct(422056, 1265859, 5341, 'L', 55, 0, '14.90', '16.50', '29.90', 'TL'),new SingleSizeProduct(422056, 1265860, 5459, 'M', 45, 1, '14.90', '16.50', '29.90', 'TL'),new SingleSizeProduct(422056, 1265861, 5446, 'S', 35, 0, '14.90', '16.50', '29.90', 'TL'),new SingleSizeProduct(422056, 1265862, 5458, 'XL', 60, 0, '14.90', '16.50', '29.90', 'TL'),new SingleSizeProduct(422056, 1265863, 5511, 'XXL', 65, 0, '14.90', '16.50', '29.90', 'TL')";
Run Code Online (Sandbox Code Playgroud)
和正则表达式:
String regex = "new SingleSizeProduct((.*))";
Run Code Online (Sandbox Code Playgroud)
我想分别匹配所有6个组,但是当我匹配模式时,我得到这样的结果:
( [0] => new SingleSizeProduct(422056, 1265858, 5430, '3XL', …
我想在应用程序运行时触发通知时显示警报,这是我用于本地通知的教程.在教程中,它用于UIAlertView显示警报并且它可以工作,这里是代码:
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
// Point for handling the local notification when the app is open.
// Showing reminder details in an alertview
UIAlertView(title: notification.alertTitle, message: notification.alertBody, delegate: nil, cancelButtonTitle: "OK").show()
}
Run Code Online (Sandbox Code Playgroud)
但它警告UIAlertView在iOS 9中已弃用,所以我使用了UIAlertController,但是当我运行它时会发出警告:
Attempt to present <UIAlertController: 0x7c322a00> on <xxx> whose view is not in the window hierarchy!
Run Code Online (Sandbox Code Playgroud)
这是我的didReceiveLocalNotification方法:
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
let alert = UIAlertController(title: "", message: notification.alertBody, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", …Run Code Online (Sandbox Code Playgroud) 我有以下字典列表,其中每个字典都可以有一个children带有进一步字典列表的键。这可以嵌套任意深度。我如何在 Jinja 中循环它以输出嵌套列表?
[{
'id': '1',
'name': 'Level 1',
'children': [{
'id': '11',
'name': 'Level 1.1'
}, {
'id': '12',
'name': 'Level 1.2'
}, {
'id': '13',
'name': 'Level 1.3',
'children': [{
'id': '131',
'name': 'Level 1.3.1'
}]
}]
},
{
'id': '2',
'name': 'Level 2',
'children': [{
'id': '21',
'name': 'Level 2.1'
}]
}]
Run Code Online (Sandbox Code Playgroud) 我有一个用python和flask框架编写的电子商务项目,我在会话中保存购物车信息,当我尝试将产品添加到会话时,nginx给出了这个错误:
从上游读取响应标头时,上游发送了太大的标头,客户端:xx.xxx.xx.xxx,服务器:mysite.com,请求:“POST /add_to_cart HTTP/1.1”,上游:“uwsgi://unix:/path /uwsgi.sock:”,主机:“mysite.com”
当我在会话中有大量信息时会发生这种情况,
我尝试添加fastcgi和proxy_buffer参数,但仍然不起作用,这是我的 nginx conf 文件:
server {
listen 443 ssl;
server_name mysite.com;
ssl_certificate /path/nginx.pem;
ssl_certificate_key /path/nginx.key;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
access_log /path/access.log main;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
proxy_buffering on;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
location /static/ {
alias /path/web/static/;
access_log off;
index index.html index.htm;
}
location / {
try_files $uri @uwsgi;
root /path/www/;
index index.html index.htm;
}
location @uwsgi {
include uwsgi_params;
uwsgi_pass unix:/path/web/uwsgi.sock;
}
}
Run Code Online (Sandbox Code Playgroud)