小编Jac*_*ack的帖子

什么是jstcache以及为什么将它添加到我的HTML标签中?

在使用Firebug时,我注意到jstcache我的一些html标签中添加了一个属性名称,而在页面源中却看不到它.在Firebug中我看到了以下内容

<html lang="en" jstcache="0">
  <head>
  <body jstcache="0">
  <div class="mydiv" jstcache="0">
    ....
Run Code Online (Sandbox Code Playgroud)

我谷歌的结果显示它与JSTemplate有关,我没有使用它,我不知道为什么它被添加到我的代码中?

html javascript

14
推荐指数
2
解决办法
1万
查看次数

查找与所选点的特定距离内的所有地址的最佳方法是什么

我正在开发一个应用程序,它应该显示位于特定距离的地址.我知道如何找到两点之间的距离,但问题是我不确定在性能方面什么是最好的方法.

一种方法是检索所有地址并逐一检查后端的选定地址,但有没有办法最小化我从数据库中检索的项目数,而不是使用内存?最好的做法是什么?如何做?

想象一下,我有300,000条记录,我必须全部检索它们并计算它们到选定点的距离吗?正如詹姆斯建议我可以在不同地区记录并计算距离,那么哪种方法可以遵循,通过查询或Java进行距离计算?

  public class Address{
    long Id;
    Double latitude;
    Double longitude;
    ..
  }
Run Code Online (Sandbox Code Playgroud)

计算

public static double distFrom(double lat1, double lng1, double lat2, double lng2) {
  double earthRadius = 3958.75;
  double dLat = Math.toRadians(lat2-lat1);
  double dLng = Math.toRadians(lng2-lng1);
  double sindLat = Math.sin(dLat / 2);
  double sindLng = Math.sin(dLng / 2);
  double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2)
        * Math.cos(Math.toRadians(lat1)) *     Math.cos(Math.toRadians(lat2));
  double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
  double dist = earthRadius * c;

  return dist;
}
Run Code Online (Sandbox Code Playgroud)

这个问题 …

java mysql spring hibernate latitude-longitude

12
推荐指数
2
解决办法
2407
查看次数

如何使用Hibernate Projection检索复杂的类及其成员?

我有一个类,需要使用Hibernate从DB检索.问题是我的班级有多个成员,其中大多数是班级,我该如何检索它们?

@Entity
public class Student {
  @Id
  long id;
  String name;
  String fname;
  @OneToMany
  List<Course> courses;
  @ManyToOne
  Dealer dealer;
  ...
}

@Entity
public class Dealer {
   @Id
   long id;
   String name; 
   @OneToMany(fetch = FetchType.LAZY, mappedBy = "cr.dealer", cascade = CascadeType.ALL)
   Set<Car> cars = new HashSet<Cars>(0);
   ..

}
Run Code Online (Sandbox Code Playgroud)

我需要检索学生ID 1及其所有课程,经销商和经销商汽车列表.

我的预测如下,但它不会返回任何内容.

  ...
    .setProjection(Projections.projectionList()

    .add(Projections.property("friends.cars").as("cars")
    ...
Run Code Online (Sandbox Code Playgroud)

java sql orm hibernate hibernate-criteria

12
推荐指数
1
解决办法
621
查看次数

如何使用jQuery来更改组中除一个元素之外的所有元素的属性

我有以下代码,显示我的图库的灯箱.有三个图像,我需要允许用户点击任何图像以在灯箱中查看图库.问题是,当我点击一个图像时,它不显示所选图像,而是显示用户上次打开灯箱时看到的列表/或最后一个图像中的第一个图像.DEMO

我的灯箱里有一个基于http://kenwheeler.github.io/slick/的旋转木马,所以我需要改变旋转木马的顺序.我注意到插件生成tabindex属性所以我试图将其更改为0 for selected image,-1 for all other images但代码不起作用.我包括了一个演示,但由于某些原因它根本不起作用.在尝试使用JSFiddle解决问题时,请使用以下代码.

为了解决与属性的问题,我看了一下这些问题1,2,3,但无法弄清楚如何使用它.

<!DOCTYPE html>
<html lang="en">
<head>
  <title>slick - the last carousel you'll ever need</title>
  <link href='http://fonts.googleapis.com/css?family=Lato:400,700' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" type="text/css" href="http://kenwheeler.github.io/slick/slick/slick.css"/>
  <link rel="stylesheet" type="text/css" href="http://kenwheeler.github.io/slick/slick/slick-theme.css"/>
  <link rel="stylesheet" type="text/css" href="http://kenwheeler.github.io/slick/slick/style.css">


  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js" type="text/javascript"></script>
  <style>
#cover-page {
  background: #fff none repeat scroll 0 0;
  margin-left: 15%;
  margin-top: …
Run Code Online (Sandbox Code Playgroud)

javascript css jquery css3

12
推荐指数
1
解决办法
2005
查看次数

Spring安全性显示"由于'用于自定义成员身份,您的登录尝试未成功

我对Spring安全性感到困惑,当我打开登录页面时,它甚至在提交表单之前就会显示以下错误消息.我不知道如何解决这个问题.

Your login attempt was not successful due to 
Run Code Online (Sandbox Code Playgroud)

我-servlet.xml中

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd 
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.2.xsd 
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">


.....

<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:8889/myproject" />
        <property name="username" value="test" />
        <property name="password" value="test" />
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
        depends-on="dataSource">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.myproject.model" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.use_sql_comments">true</prop>
                <prop key="hibernate.show_sql">true</prop> …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security

12
推荐指数
1
解决办法
338
查看次数

如何使用Spring-security以编程方式登录用户?

我需要以编程方式登录通过Facebook API进行身份验证的用户.原因是每个用户(例如购物车)都有多个项目相关联,因此一旦用户使用Facebook API进行身份验证,我需要使用spring安全性登录用户以便能够访问他/她的购物车.

基于我的研究,有很多方法可以实现它,但我无法部署任何方法,因为我从我的代码发送登录请求,另一个问题是有些人创建了用户对象,但他们没有解释如何创建它.

那些创建用户对象但没有解释如何的人.

从第一个例子:这个答案

  Authentication auth = 
  new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities());
Run Code Online (Sandbox Code Playgroud)

从第二个例子:这一个

  34.User details = new User(username);
  35.token.setDetails(details);
Run Code Online (Sandbox Code Playgroud)

从第三个例子:这一个

  Authentication authentication = new UsernamePasswordAuthenticationToken(user, null,
  AuthorityUtils.createAuthorityList("ROLE_USER"));
Run Code Online (Sandbox Code Playgroud)

另一个例子就是这里,它没有帮助,因为我需要从我自己的代码登录用户而不是从浏览器登录; 因此我不知道如何填充HttpServletRequest对象.

protected void automatedLogin(String username, String password, HttpServletRequest request) {
Run Code Online (Sandbox Code Playgroud)

mycode的

...
if(isAuthenticatedByFB())
{
    login(username);
    return "success";
}
else{
    return "failed";
}
Run Code Online (Sandbox Code Playgroud)

java spring-security

11
推荐指数
2
解决办法
9553
查看次数

什么是通知管理员有关Java应用程序的新异常的最佳方法?

我的问题是,最好的方法是跟踪应用程序管理员的异常.(出于维护目的,通知管理员抛出的异常).

对于系统用户,我认为应该捕获异常并显示相应的错误消息. 我认为,对于系统管理员来说,最好的方法是让消息系统将每个异常的详细信息作为消息发送给接收方.一旦接收方收到新的错误消息,它就会在数据库中持续显示,或者向管理员发送一封包含异常详细信息的电子邮件.

try{
  ....
}
catch(Exception e){
   //what to do here? how to notify admin?
}
Run Code Online (Sandbox Code Playgroud)

java exception-handling struts2 jms java-ee

10
推荐指数
4
解决办法
2361
查看次数

Java中的铸造成本是多少?避免它是一个好主意吗?

我知道有两种类型的转换是隐式显式转换.我在StackOverflow上阅读了不同的问题,例如this,thisthis,但我仍然想知道在Java中投射的成本是多少,避免它是个好主意?它的最佳实践是什么?

铸造有两种类型:

String s = "Cast";
Object o = s; // implicit casting

Object o = someObject;
String s = (String) o; // explicit casting
Run Code Online (Sandbox Code Playgroud)

在第二种情况下,运行时会产生开销,因为必须检查这两种类型,并且如果转换不可行,JVM必须抛出一个ClassCastException.

有人说最好对应用程序进行分析,以确保铸造是否有用.

java casting

9
推荐指数
3
解决办法
1万
查看次数

如何将菜单和设置选项添加到Android的自定义标题栏?

我的要求是增加标题栏的高度,但我不确定这是否可行.如果是我怎么能增加它的高度所以我会有更多的空间.如果不是,我需要在我的自定义标题栏中添加一个菜单选项(汉堡风格).

custom_title_bar.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/title_bar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#77b48e"
    android:gravity="center_vertical"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="29dp"
            android:layout_height="28dp"
            android:maxWidth="1dp"
            android:src="@drawable/logo" />

        <TextView
            android:id="@+id/title_bar_viewname"
            android:layout_width="wrap_content"
            android:layout_height="16dp"
            android:layout_weight="0.07"
            android:text="@string/app_name"
            android:textColor="@android:color/white"
            android:textSize="10sp" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
    </LinearLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

MainActivity.java

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.activity_main);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar);
    }
Run Code Online (Sandbox Code Playgroud)

android

9
推荐指数
1
解决办法
2万
查看次数

如何在AutoComplete中找出所选元素的类别?

我需要对AutoComplete结果进行分组,我发现了以下解决方案.我怎样才能找出所选建议的类别?

例如,假设有城市和国家类别,用户选择其中一个城市.我怎么知道所选项目是城市的一部分而不是国家类别(当表格提交时)?我也不希望用户可以看到类别名称.

到目前为止我发现了什么

$.widget( "custom.catcomplete", $.ui.autocomplete, {
        _renderMenu: function( ul, items ) {
            var self = this,
                currentCategory = "";
            $.each( items, function( index, item ) {
                if ( item.category != currentCategory ) {
                    ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
                    currentCategory = item.category;
                }
                self._renderItem( ul, item );
            });
        }
    });
Run Code Online (Sandbox Code Playgroud)

我的守则

$(function() {
    $("#box1").autocomplete({
        source: function(e, r) {
            var t, s = "http://localhost:8080/MyProject/autoComplete/box1";
            $.ajax({
                url: s,
                dataType: "json",
                data: {
                    q: e.term
                },
                success: function(e) …
Run Code Online (Sandbox Code Playgroud)

jquery jquery-ui jquery-ui-autocomplete

9
推荐指数
1
解决办法
1287
查看次数