小编Ste*_*lla的帖子

Hibernate加入两个表并获取所有记录?

我有两个实体类Category和Events.I需要连接两个表并获取匹配给定条件的所有记录

我的SQL查询

SELECT * FROM category c  inner join `events` e on e.category_i=c.category_id where c.parent_category_id=1;
Run Code Online (Sandbox Code Playgroud)

我怎么能把这个SQL查询转换为hql并获取数据?我试过下面但没有得到结果?对休眠来说非常新

用于hibernate映射的事件实体类

import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;

/**
 * The persistent class for the user database table.
 *
 */
@Entity
@Table(name = "events")
public class Events implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "event_id")
    private int eventId;

    @Column(name = "event_name")
    private String eventName;

    @Column(name = "event_description")
    private String eventDescription;

    @Column(name = "category_i")
    private Integer categoryI; …
Run Code Online (Sandbox Code Playgroud)

java mysql spring hibernate

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

从未经过自动化访问保护Spring RESTful Web服务API?

我已成功创建了一个包含不同API的Spring RESTful Web服务.现在我应该保护他们免受未经授权的访问 我关注了http://www.beingjavaguys.com/2014/10/spring-security-oauth2-integration.html,登录逻辑完全不同于我的.有人可以帮助我继续前进吗?

获取用户登录请求

 @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ResponseBody
    @ResponseStatus(HttpStatus.OK)
    public UserResponse login(@RequestBody final UserLoginRequest userRequest) throws ServletException, IOException {
        UserResponse userResponse = new UserResponse();
        try {
            userResponse = accessService.login(userRequest);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return userResponse;
    }
Run Code Online (Sandbox Code Playgroud)

处理用户登录请求

 @Transactional
    public UserResponse login(UserLoginRequest userRequest) throws SQLException,
            ClassNotFoundException, IOException {
        UserResponse userResponse = new UserResponse();

        int status = 0;

        //boolean isExist = loginDao.isUserExist(userRequest.getUsername(), userRequest.getPassword());
        User user = loginDao.getUser(userRequest.getEmailID()); …
Run Code Online (Sandbox Code Playgroud)

android web-services spring-mvc spring-security

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

摄像头2:无法全屏录制视频?

我使用Google官方示例使用Camera API 2来处理视频录制.但问题是我无法全屏显示,因为我将屏幕方向仅限于肖像.这是我编辑的xml和官方的xml.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <AutoFitTextureView
        android:id="@+id/texture"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true" />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        <Button
            android:id="@+id/video"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/label_record" />

        <ImageView
            android:id="@+id/info"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|right"
            android:contentDescription="Description"
            android:padding="20dp"
            android:src="@drawable/ic_more" />

    </FrameLayout>

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

我认为这里是通过纵横比设置视频屏幕大小,TextureView但我无法全屏显示.任何帮助是极大的赞赏.

mVideoSize = chooseVideoSize(map.getOutputSizes(MediaRecorder.class));
mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), width, height, mVideoSize);
int orientation = getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
    mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight());
} else {
    mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth());
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

android camera-api

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

自定义 AppCompatButton drawableLeft?

如何在下图中放置drawableLeft和按钮AppCompatButton类似的文本?

应用兼容按钮

我试图申请paddingLeft,但文本正在远离可绘制的右侧。

<android.support.v7.widget.AppCompatButton
                android:id="@+id/filterBy"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:drawableLeft="@drawable/ic_btn_filter"
                android:paddingLeft="20dp"
                android:text="@string/filter_by"
                android:textAllCaps="false" />
Run Code Online (Sandbox Code Playgroud)

到目前为止,结果看起来像

在此处输入图片说明

布局

   <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/profileHeader"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="10dp">

            <android.support.v7.widget.AppCompatButton
                android:id="@+id/findFriends"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:drawableLeft="@drawable/ic_btn_search"
                android:text="@string/find_friends"
                android:textAllCaps="false" />

            <android.support.v7.widget.AppCompatButton
                android:id="@+id/filterBy"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:drawableLeft="@drawable/ic_btn_filter"
                android:text="@string/filter_by"
                android:textAllCaps="false" />
      </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

以及使事情变得清晰的解释性要求。

使用layout_weight属性 am 调整两个按钮的宽度,我必须做的是,文本应该在按钮的中心,drawable 应该在文本的左侧附近对齐。

请问有什么建议吗?

android button android-appcompat compound-drawables

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

LinkedIn集成Android移动SDK电子邮件ID无法获取

我同意OAuth用户协议:

默认范围:r_basicprofile r_fullprofile

网址

private static final String host = "api.linkedin.com"; 
private static final String PROTECTED_URL_GET_CURRENT_USER_PROFILE = "https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,picture-url,industry)";
Run Code Online (Sandbox Code Playgroud)

除了电子邮件地址外,我还能得到所有的信息 谁知道为什么?

android linkedin

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

使用oauth2的Spring安全性向授权URL添加其他参数?

我在我的restful Web服务中实现了Spring Security.实际上,我必须在客户端的请求中添加一个额外的参数,并且应该在请求认证/ accesstoken时从服务中获取它.

弹簧security.xml文件

<?xml version="1.0" encoding="UTF-8" ?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:sec="http://www.springframework.org/schema/security" xmlns:mvc="http://www.springframework.org/schema/mvc"
           xsi:schemaLocation="http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2-2.0.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
            http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd 
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd ">

        <!-- @author Nagesh.Chauhan(neel4soft@gmail.com) -->  

        <!-- This is default url to get a token from OAuth -->
        <http pattern="/oauth/token" create-session="stateless"
                  authentication-manager-ref="clientAuthenticationManager"
                  xmlns="http://www.springframework.org/schema/security">
            <intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" />
            <anonymous enabled="false" />
            <http-basic entry-point-ref="clientAuthenticationEntryPoint" />
            <!-- include this only if you need to authenticate clients via request 
            parameters -->
            <custom-filter ref="clientCredentialsTokenEndpointFilter" 
                                   after="BASIC_AUTH_FILTER" />
            <access-denied-handler ref="oauthAccessDeniedHandler" />
        </http> …
Run Code Online (Sandbox Code Playgroud)

java rest spring oauth spring-security

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

Hibernate:自我加入混乱?

我有一个category表格。其中前 5 个是主要类别,其他是子类别。

在此处输入图片说明

我需要获取前 5 个主要类别的子类别,所以我找到了 sql 查询

SELECT m.category_id,m.category_name  AS 'Parent',
      e.category_name AS 'Sub'
FROM category e
INNER JOIN category m ON m.category_id = e.parent_category_id
ORDER BY Parent
Run Code Online (Sandbox Code Playgroud)

查询本身加入同一个表。并且得到下面给出的结果

结果

在此处输入图片说明

如何将 SQL 查询转换为 HQL 并以标准 json 格式将如上图所示的数据返回给用户?

获取子类别

import java.io.Serializable;
import java.util.Set;
import javax.persistence.*;

@Entity
@Table(name = "category")
public class FetchSubCategory implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "category_id")
    private Integer categoryId;

    @Column(name = "category_name")
    private String categoryName; …
Run Code Online (Sandbox Code Playgroud)

java mysql rest spring hibernate

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

Android 在社交网络中共享 google play 安装引荐网址?

我必须在 Play 商店中与社交网络中的活动者详细信息共享我的应用程序的 URL,当访客安装该应用程序时,我将用于获取com.android.vending.INSTALL_REFERRER活动者详细信息。我的疑问是我将如何构建 URL 并以编程方式共享它。

以下是我的理解..

1) 创建一个 URL,将 Play-store 与我们的包名称和独特的引用详细信息链接起来,如下所示https://play.google.com/store/apps/details?id=com.hellochatty&referrer=tracking_id%3D123456789

2) 通过任何社交媒体分享 URL

3)当点击共享链接时,它将重定向到Play商店,在安装应用程序时,我们可以referrer使用广播接收器获取参数。

 <receiver
     android:name="com.ex.MyReceiver"
     android:exported="true">
     <intent-filter>
         <action android:name="com.android.vending.INSTALL_REFERRER" />
     </intent-filter>
 </receiver>
Run Code Online (Sandbox Code Playgroud)

如果我的理解有问题,请告诉我?

java android social-networking referrals google-play

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