小编fat*_*dem的帖子

使用primary_key和默认pk的Django AutoField

我很好奇Django数据库模型pk.

这有什么不同吗?

class Category(models.Model):
    category_id = models.AutoField(primary_key=True)
    category_name = models.CharField(max_length=50)
Run Code Online (Sandbox Code Playgroud)

这之间呢?

class Category(models.Model):
   category_name = models.CharField(max_length=50)
Run Code Online (Sandbox Code Playgroud)

都是一样的东西AutoField with primary_keydefault pk

django django-models

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

固定定位标题在Google Chrome中"跳转"

http://fundamentaldesigns.us/normal/

我正在开发一个网站,我遇到了一个我以前从未遇到过的问题.我有一个具有固定定位和高z-index的标题.它下面的部分具有相对定位,因此我可以绝对地将元素放置在它们内部.

在chrome中滚动时,标题会"跳转".我想通了如果我删除了z-index它修复了跳跃问题但是它没有显示在其他元素的前面.这里的诀窍是什么?

HTML

    <header>
    <div class="inner">
        <img src="images/logo.png" alt="Normal Public Library Foundation" class="logo">
        <nav>
            <ul>
                <li><a href="#whatif">Home</a></li>
                <li><a href="#">2014 Goals</a></li>
                <li><a href="#">Members</a></li>
                <li><a href="#">Donate</a></li>
            </ul>
        </nav>
    </div>
</header>

<div class="whatif section" id="whatif">
    <div class="inner">
        <h1>What if there was no library?</h1>
        <a href="#circulation" class="animated bounce"><img src="images/scroll-arrow.png" alt=""></a>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS

header {
position: fixed;
top:0;
width: 100%;
padding: 20px 0;
background-color: #FFF;
opacity: 0.9;
z-index: 999;


-webkit-box-shadow: 0px 1px 7px 0px rgba(50, 50, 50, 0.75);
-moz-box-shadow:    0px 1px 7px 0px …
Run Code Online (Sandbox Code Playgroud)

css google-chrome

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

Bootstrap标签的宽度相同

我正在使用Bootstrap 3.我有5个不同的labels,我想将它们设置width为最大值并使文本居中.

在此输入图像描述

例如,每个labelwidth应该等于红色.

<span class="label label-md label-danger">Merkez Taraf?ndan Reddedildi</span>
Run Code Online (Sandbox Code Playgroud)

html css twitter-bootstrap twitter-bootstrap-3

7
推荐指数
1
解决办法
9671
查看次数

使用constexpr进行基本编译时格式字符串检查

在我们的项目中,我们使用printf兼容函数将消息添加到外部日志文件中.我们可以写

__LOG_INFO( "number of files = %d\n", number_of_files );
__LOG_INFO( "Just for information\n" );
Run Code Online (Sandbox Code Playgroud)

函数声明__LOG_INFO看起来像这样

template<int N>
inline void __LOG_INFO( const char (&fmt)[N] )
{
    call_printf( MODULE_NAME, fmt, debug_parameters() );
}

template<int N, typename T1>
static void __LOG_INFO( const char (&fmt)[N], const T1 &t1 )
{
    call_printf( MODULE_NAME, fmt, debug_parameters( t1 ) );
}

template<int N, typename T1, typename T2>
static void __LOG_INFO( const char (&fmt)[N], const T1 &t1, const T2 &t2 )
{
    call_printf( MODULE_NAME, fmt, debug_parameters( …
Run Code Online (Sandbox Code Playgroud)

templates compile-time-constant compile-time constexpr c++11

6
推荐指数
1
解决办法
1236
查看次数

Spring Security maxSession不起作用

当用户超过maxSession计数时,我想防止登录。例如,每个用户只能登录一次。然后,如果登录的用户尝试使用其他登录系统,则应禁用该用户的登录。

.sessionManagement()
.maximumSessions(1).expiredUrl("/login?expire").maxSessionsPreventsLogin(true)
.sessionRegistry(sessionRegistry());


@Bean
public static ServletListenerRegistrationBean httpSessionEventPublisher() {
    return new ServletListenerRegistrationBean(new HttpSessionEventPublisher());
}
Run Code Online (Sandbox Code Playgroud)

spring spring-security spring-session

5
推荐指数
2
解决办法
2107
查看次数

在ImageView上的android setAlpha进入CollapsingToolbarLayout不起作用

在CollapsingToolbarLayout imageview里面,我需要setAlpha(float)当它向上和向下滚动时:

这是获取偏移的方法,并按偏移计算浮动:

AppBarLayout.OnOffsetChangedListener:

 @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
        float offsetAlpha = (float) (verticalOffset / appBarLayout.getTotalScrollRange());
        imageView.setAlpha(offsetAlpha);
    }
Run Code Online (Sandbox Code Playgroud)

xml布局:

 <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="50dp"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="@android:color/transparent">

      <ImageView
                    android:id="@+id/imageView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:scaleType="centerCrop"
                    app:layout_collapseMode="parallax" />

 </android.support.design.widget.CollapsingToolbarLayout>
Run Code Online (Sandbox Code Playgroud)

但是setAlpha不起作用.为什么?

android android-layout android-coordinatorlayout

5
推荐指数
1
解决办法
1342
查看次数

Python填充矩阵具有特定值

我有2D矩阵,我想用0和1填充它.我有一个列表包含一些值.

例如:

values = [1, 3, 5, 8]
Run Code Online (Sandbox Code Playgroud)

我想创建这个矩阵

matrix = [[0, 1, 0],
          [1, 0, 1],
          [0, 0, 1]]
Run Code Online (Sandbox Code Playgroud)

我用两个嵌套的for循环witf if语句做了这个.值是从0到100的随机整数.我的矩阵将是10*10.有没有办法让这更优雅?

python matrix

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

Spring Mongodb 时间戳时区误导

我正在使用 Spring Data MongoDB。当我保存一些记录时,MongoDb 没有正确保存我的时间戳。

这是我在 Spring 中的时间戳字段。

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private Date timestamp = new Date();
Run Code Online (Sandbox Code Playgroud)

我的 MongoDB 记录。

{
"_id": ObjectId("5697a672ce2a8e5347d86afd"),
"batteryLevel": 100,
"beaconClass": 3,
"beaconId": "dsadsa",
"timestamp": ISODate("2016-01-14T13:45:22.702Z")
}
Run Code Online (Sandbox Code Playgroud)

当我登录到控制台我的时区和日期时,我看到它是正确的。

Eastern European Time
Asia/Istanbul
Thu Jan 14 15:45:22 EET 2016
Run Code Online (Sandbox Code Playgroud)

如何更正时间 MongoDB 时间戳?

java timezone datetime mongodb spring-data-mongodb

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

如何使用android中的Text Watcher从Recycler View适配器获取Edit文本位置

我想知道如何从Recycler View适配器获取编辑文本的位置.我使用Card View,其中水平线性布局有三个视图TextView,EditText视图和TextView.我想从Recycler View Adapter中的Textwatcher获取特定的EditText位置.

适配器:

public class CartlistAdapter extends RecyclerView.Adapter < CartlistAdapter.ViewHolder > {

    private ArrayList < CartItemoriginal > cartlistadp;
    private ArrayList < Cartitemoringinaltwo > cartlistadp2;
    DisplayImageOptions options;
    private Context context;
    public static final String MyPREFERENCES = "MyPrefs";
    public static final String MYCARTPREFERENCE = "CartPrefs";
    public static final String MyCartQtyPreference = "Cartatyid";
    SharedPreferences.Editor editor;
    SharedPreferences shared,
    wishshared;
    SharedPreferences.Editor editors;
    String pos,
    qtyDelete;
    String date;
    String currentDateandTime;
    private static final int VIEW_TYPE_ONE = 1;
    private static final int VIEW_TYPE_TWO = …
Run Code Online (Sandbox Code Playgroud)

android android-layout recycler-adapter android-recyclerview

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

在fullpage.js中设置section的高度

我正在使用fullPage.js 这可能听起来非常noobish,但无法想象如何设置一个高度小于100%的部分,我已经尝试使用.section#section1(例如height: 80%;)在css中设置它,但这有没有效果...

非常感谢.

马克斯

html css height fullpage.js

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

Java EE jta hibernate.hbm2ddl.import_files不起作用

我尝试在Web应用程序运行时导入sql文件.我import.sql进去了src/main/resources/import.sql.然后我persistence.xml通过添加import_files指令修改了我:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             version="2.1"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jsp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="spPU" transaction-type="JTA">
    <description>SP Persistence Unit</description>
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <jta-data-source>java:jboss/datasources/SpDS</jta-data-source>

    <properties>
      <property name="hibernate.hbm2ddl.auto" value="create"/>
      <property name="hibernate.show_sql" value="true"/>
      <property name="hibernate.format_sql" value="false"/>
      <property name="hibernate.hbm2ddl.import_files" value="import.sql"/>
    </properties>
  </persistence-unit>
</persistence>
Run Code Online (Sandbox Code Playgroud)

但在重新部署或重启服务器后,没有任何内容可以上传到数据库中.我使用WildFly 8.1.0,Hibernate 4.3.5.Final,Database h2database 1.3.161.我试图从import.sql中删除空行并将hibernate.hbm2ddl.auto更改为create-drop.知道为什么import.sql没有加载到数据库中?

java sql hibernate

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

Spring MVC“请求处理失败” 500错误

我是Spring的新手,正在尝试学习教程。我有一个问题。我将基于xml的配置转换为基于注释的配置。是教程。

而且我收到HTTP 500错误。这是完整的堆栈跟踪。

SEVERE: Servlet.service() for servlet [dispatcher] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause


root cause

   java.lang.NullPointerException   com.ulotrix.spring.service.PersonServiceImpl.listPersons(PersonServiceImpl.java:35) 
    com.ulotrix.spring.controller.PersonController.listPersons(PersonController.java:28)    

     sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Run Code Online (Sandbox Code Playgroud)

项目结构

AppConfig.java

@EnableWebMvc
@Configuration
@ComponentScan({ "com.ulotrix.spring" })
public class AppConfig extends WebMvcConfigurerAdapter {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}

@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
    configurer.enable();
}

@Bean
public SessionFactory sessionFactory() {

    LocalSessionFactoryBuilder builder = new LocalSessionFactoryBuilder(dataSource());
    builder.scanPackages("com.ulotrix.spring.model");
    builder.addProperties(getHibernationProperties());

    return builder.buildSessionFactory();
}

private Properties …
Run Code Online (Sandbox Code Playgroud)

java spring annotations hibernate spring-mvc

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