问题列表 - 第46652页

在Spring中绑定时保护特定字段

我在允许用户编辑个人资料信息的页面上工作.我希望他们能够编辑他们的公共信息,但不允许他们更改系统标志,例如他们的用户类型.

这是用Spring MVC(3.0)实现的.用户对象具有典型字段,例如firstName,lastName,email(都应该是可编辑的)和一个布尔administrator(这不应该是可编辑的.

我的方法看起来像这样:

@RequestMapping(method = RequestMethod.POST)
public String doEdit(
        @ModelAttribute("user") User user,
        BindingResult result,
        ModelMap model)
throws IOException
{
      // validate, blah blah
      // save user object
      // return page

}
Run Code Online (Sandbox Code Playgroud)

我的表单包含的字段firstName,lastName等等,似乎很好地工作.

问题是,如果恶意用户使用参数administrator"true" 发布查询,他们可以在不应该设置此字段时设置该字段.

我知道我可以创建一个单独的"表单"对象,只包含我想要更改的字段并将其用于自动绑定.(复制数据).问题是我有很多地方使用这种技术.(对于用户和其他对象).当我想添加字段时,维护是一件麻烦事.

有没有办法在Spring MVC中使用注释或其他技术将参数列入白名单并防止更改任意域对象属性?

java spring spring-mvc

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

带有rails 3的多表继承

在rails 3中进行多表继承时,是否有标准或最佳实践?到目前为止,我能找到的最好的文章是:

http://mediumexposure.com/multiple-table-inheritance-active-record/

但即使这需要一些更改(例如将需求转移到初始化程序而不是旧的/config/environment.rb)

有更好的资源/标准吗?

ruby-on-rails multiple-tables sti

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

SQL查询,其中字段值不包含空格

我目前正在使用以下查询:

SELECT *
FROM `wp_usermeta`
WHERE meta_key='avatar'
AND meta_key NOT LIKE '% '
ORDER BY RAND()
LIMIT 4
Run Code Online (Sandbox Code Playgroud)

这样,我想尝试只获取字段值,文件名中没有空格.我的查询中的错误在哪里?它仍然选择文件名中带有空格的文件名.

mysql sql

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

使用Hibernate基于唯一键查找或插入

我正在尝试编写一个方法,它将返回一个基于唯一但非主键的Hibernate对象.如果实体已存在于数据库中,我想返回它,但如果不存在,我想创建一个新实例并在返回之前保存它.

更新:让我澄清一下,我正在编写的应用程序基本上是输入文件的批处理器.系统需要逐行读取文件并将记录插入数据库.文件格式基本上是我们模式中几个表的非规范化视图,所以我要做的是解析父记录,或者将其插入到db中,这样我就可以得到一个新的合成密钥,或者如果它已经存在则选择它.然后我可以在其他表中添加其他关联记录,这些表具有返回该记录的外键.

这很棘手的原因是每个文件需要完全导入或根本不导入,即为给定文件完成的所有插入和更新应该是一个事务的一部分.如果只有一个进程正在执行所有导入,这很容易,但是如果可能的话,我想在多个服务器上解决这个问题.由于这些约束,我需要能够保留在一个事务中,但是处理已经存在记录的异常.

父记录的映射类如下所示:

@Entity
public class Foo {
    @Id
    @GeneratedValue(strategy = IDENTITY)
    private int id;
    @Column(unique = true)
    private String name;
    ...
}
Run Code Online (Sandbox Code Playgroud)

我最初尝试编写此方法的方法如下:

public Foo findOrCreate(String name) {
    Foo foo = new Foo();
    foo.setName(name);
    try {
        session.save(foo)
    } catch(ConstraintViolationException e) {
        foo = session.createCriteria(Foo.class).add(eq("name", name)).uniqueResult();
    }
    return foo;
}
Run Code Online (Sandbox Code Playgroud)

问题是当我正在寻找的名称存在时,调用uniqueResult()会抛出org.hibernate.AssertionFailure异常.完整的堆栈跟踪如下:

org.hibernate.AssertionFailure: null id in com.searchdex.linktracer.domain.LinkingPage entry (don't flush the Session after an exception occurs)
    at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:82) [hibernate-core-3.6.0.Final.jar:3.6.0.Final]
    at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:190) [hibernate-core-3.6.0.Final.jar:3.6.0.Final]
    at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:147) [hibernate-core-3.6.0.Final.jar:3.6.0.Final]
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219) [hibernate-core-3.6.0.Final.jar:3.6.0.Final]
    at …
Run Code Online (Sandbox Code Playgroud)

java hibernate upsert unique-key unique-constraint

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

解密文件时索引超出范围

我真的不确定这里发生了什么.我的应用程序正确加密文件,没有问题,但在尝试解密同一文件时抛出了IndexOutOfRangeException ...

这是我的代码:

Public Sub EncryptDecrypt(ByVal Action As String, ByVal InFile As String, ByVal OutFile As String)
    Try
        Dim Buffer(4096) As Byte
        Dim Stream As CryptoStream
        Dim Rij As New System.Security.Cryptography.RijndaelManaged
        Dim Key(), IV() As Byte

        FSIn = New FileStream(InFile, FileMode.Open, FileAccess.Read)
        FSOut = New FileStream(OutFile, FileMode.OpenOrCreate, FileAccess.Write)
        FSOut.SetLength(0)

        Key = CreateKey("p0Ju423KQY7h4D29Ml536jbX7gS2Q6Rtm87XvRttlKiZ")
        IV = CreateIV("p0Ju423KQY7h4D29Ml536jbX7gS2Q6Rtm87XvRttlKiZ")

        If Action = "E" Then
            Stream = New CryptoStream(FSOut, Rij.CreateEncryptor(Key, IV), CryptoStreamMode.Write)
        Else
            Stream = New CryptoStream(FSOut, Rij.CreateDecryptor(Key, IV), CryptoStreamMode.Write)
        End If

        Stream.Close()
        FSIn.Close()
        FSOut.Close() …
Run Code Online (Sandbox Code Playgroud)

security encryption filestream rijndaelmanaged

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

如何使用Integers填充java中的二维ArrayList?

我必须创建一个大小未知的二维数组.所以我决定使用2d ArrayList问题是我不知道如何初始化这样的数组或存储信息.

说我有以下数据

   0 connects 1
   2 connects 3 
   4 connects 5
Run Code Online (Sandbox Code Playgroud)

....等等大量的随机连接

我想插入

true(1) into [0][1], 
true(1) into [2][3], 
true(1) into [4][5]. 
Run Code Online (Sandbox Code Playgroud)

数组是否可以自动更新列/行

任何帮助表示赞赏谢谢

java arraylist

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

如何在不使用.htaccess的情况下gzip图像?

Godaddy不会为我启用mod_gzip,所以我必须使用这样的标题:

<?php 
ob_start ("ob_gzhandler");
header("Content-type: text/css; charset: UTF-8");
header("Cache-Control: must-revalidate");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
$offset = 60 * 60 * 24 * 7;
$ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
gmdate("D, d M Y H:i:s",
time() + $offset) . " GMT";
header($ExpStr);
?>
Run Code Online (Sandbox Code Playgroud)

在这种情况下,那将是CSS文件

无论如何,我如何在我的图像中使用它?我的意思是,制作图像:image.php并将该代码置于顶部但使用header("Content-type: image/png; charset: UTF-8");不起作用,请告诉我.

php apache gzip

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

LP建模问题...自学校以来很长一段时间

当然,这本身并不是一个编程问题......但我想不出一个更好的地方来问这一切.

我正在编写一个应用程序,最终将帮助购物者确定如何在特定网站上实现最大的节省.该网站提供几乎所有产品的两种价格 - 正常价格和折扣价格.任何人都可以享受折扣价,但只有一个折扣商品可以添加到任何给定的订单中.只有这些信息,激励是最小化您的订单siz,而是放置多个订单.另一方面,总运输成本由订单大小(按重量)决定,因此激励是最大化订单大小并仅放置一个订单.

我正在寻找一种模型,以确定最有效的方式来平衡订单,因为一个项目的可用折扣和重量影响订单的运输成本.

我记得回到学校的时候我认为这是一个线性编程问题......但我记得那个课程是多么令人困惑.

任何人都有关于如何计算这个程序的数学技巧?

algorithm math linear-programming

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

WidgetProvider在onReceive中找不到按钮点击发送的意图附加内容

我试图检测何时单击小部件按钮但没有任何Intent额外的东西出现在onReceive方法中.

onReceive每次点击都会调用,但我的所有内容都不会Intent显示出来.

我的代码如下:我只在更新时挂钩切换按钮,所以不确定这是否正确.null尽管我设置了这个,但没有一个额外的东西出现和类别.

onUpdate(上下文上下文等):

RemoteViews remoteViews = new RemoteViews(context.getPackageName(), 
                                R.layout.my_widget);

Intent buttonIntent = new Intent(context, MyWidgetProviderClass.class);
buttonIntent.setAction(ACTION_WIDGET_RECEIVER);
buttonIntent.putExtra("BUTTON_CLICKED", "buttonClick");
buttonIntent.putExtra("BUTTON",899);

PendingIntent muPendingIntent = PendingIntent.getBroadcast(context, 0, 
                                        buttonIntent, 
                                        PendingIntent.FLAG_CANCEL_CURRENT);
buttonIntent.addCategory("buttonclick");
remoteViews.setOnClickPendingIntent(R.id.ToggleImageButton, myPendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
Run Code Online (Sandbox Code Playgroud)

的onReceive():

intent.getIntExtra("BUTTON",-1);    ---> 1
intent.getCategories()   --- > null
Run Code Online (Sandbox Code Playgroud)

android widget broadcastreceiver android-intent

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

使用WPF的ShowDialog打开表单时出现异常


我有一个WPF应用程序,当尝试使用时打开一个表单ShowDialog(),我在下面的一台机器上得到了这个奇怪的例外.
知道问题可能是什么?

异常消息=操作已中止(HRESULT异常:0x80004004(E_ABORT))异常堆栈跟踪=
System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode,IntPtr errorInfo)System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode, MS.Internal.FontCache.FamCollection.LookupFamily上的MS.Internal.Text.TextInterface.FontCollection.FindFamilyName(String familyName,UInt32&index)中的MS.Internal.Text.TextInterface.Native.Util.ConvertHresultToException(Int32hr)处的IntPtr errorInfo) System.Windows.Media.FontFamily.LookupFontFamilyAndFace(CanonicalFontFamilyReference canonicalFamilyReference,FontStyle&style,FontWeight&weight,FontStretch&stretch)在System.Windows.Media.FontFamily.FindFirstFontFamilyAndFace上的字符串familyName,FontStyle&fontStyle,FontWeight&fontWeight,FontStretch&fontStretch(FontStyle&style,在Syste的System.Windows.Media.Typeface.ConstructCachedTypeface()的FontWeight&weight,FontStretch&stretch)m.Windows.Media.Typeface.get_CachedTypeface()在MS.Internal.TextFormatting.SimpleTextLine..ctor(FormatSettings设置,的Int32 cpFirst,的Int32 paragraphWidth,ArrayList中运行时,的Int32&后,的Int32&trailingSpaceWidth)
在MS.Internal.TextFormatting.SimpleTextLine.在MS.Internal.TextFormatting的MS.Internal.TextFormatting.TextFormatterImp.FormatLineInternal(TextSource textSource,Int32 firstCharIndex,Int32 lineLength,Double paragraphWidth,TextParagraphProperties paragraphProperties,TextLineBreak previousLineBreak,TextRunCache textRunCache)中创建(FormatSettings设置,Int32 cpFirst,Int32 paragraphWidth). System.Windows.Controls.TextBoxLine.Format(Int32 dcp,Double formatWidth,Double paragraphWidth,LineProperties lineProperties,TextRunCache textRunCache,TextFormatter formatt)中的TextFormatterImp.FormatLine(TextSource textSource,Int32 firstCharIndex,Double paragraphWidth,TextParagraphProperties paragraphProperties,TextLineBreak previousLineBreak,TextRunCache textRunCache)呃)System.Windows上的System.Windows.FrameworkElement.MeasureCore(Size availableSize)上的System.Windows.Controls.TextBoxView.MeasureOverride(Size constraint)中的System.Windows.Controls.TextBoxView.FullMeasureTick(Double constraintWidth,LineProperties lineProperties). UIElement.Measure(尺码availableSize)在MS.Internal.Helper.MeasureElementWithSingleChild(的UIElement元件,尺寸约束)在System.Windows.Controls.ScrollContentPresenter.MeasureOverride(尺寸约束)在System.Windows.FrameworkElement.MeasureCore(尺码availableSize)在系统.Windows.UIElement.Measure(尺码availableSize)在System.Windows.Controls.Grid.MeasureCell(的Int32细胞,布尔forceInfinityV)在System.Windows.Controls.Grid.MeasureCellsGroup(的Int32 cellsHead,尺寸referenceSize,布尔ignoreDesiredSizeU,布尔forceInfinityV) System.Windows.UIElement.Measure上的System.Windows.FrameworkElement.MeasureCore(Size availableSize)中的System.Windows.Controls.Grid.MeasureOverride(Size约束)(大小可用)System.Windows.Controls.Border.MeasureOverride上System.Windows.UIElement.Measure(Size availableSize)的System.Windows.FrameworkElement.MeasureCore(Size availableSize)上的System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint)处的ableSize) System.Windows.FrameworkElement.MeasureCore上System.Windows.Controls.Control.MeasureOverride(Size constraint)上System.Windows.UIElement.Measure(Size availableSize)的System.Windows.FrameworkElement.MeasureCore(Size availableSize)上的(大小约束) System.Windows.Controls.Grid.MeasureCell(Int32 cell,Boolean forceInfinityV)中的System.Windows.UIElement.Measure(Size availableSize)上的(size availableSize)System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead,Size referenceSize,系统中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)上的System.Windows.FrameworkElement.MeasureCore(Size availableSize)中的系统布局ignoreDesiredSizeU,布尔forceInfinityV)在Sys的System.Windows.UIElement.Measure(Size availableSize)tem.Windows.Controls.StackPanel.MeasureOverride(尺寸约束)在System.Windows.FrameworkElement.MeasureCore(尺码availableSize)在System.Windows.UIElement.Measure(尺码availableSize)在MS.Internal.Helper.MeasureElementWithSingleChild(的UIElement元件,尺寸System.Windows.Documents.AdasurenerDecorator.MeasureOverride上System.Windows.UIElement.Measure(Size availableSize)的System.Windows.FrameworkElement.MeasureCore(Size availableSize)上的System.Windows.Controls.ContentPresenter.MeasureOverride(Size约束)处理约束. System.Windows.FrameworkElement.MeasureCore上System.Windows.Controls.Border.MeasureOverride(Size constraint)的System.Windows.UIElement.Measure(Size availableSize)上的System.Windows.FrameworkElement.MeasureCore(Size availableSize)的(大小约束) System.Windows.Uasurelement.Measure(Size availableSize)的System.Windows.Uasurelement.Measure(Size availableSize)的大小(available availableSize)位于Syste的System.Windows.Window.MeasureOverride(Size availableSize)的System.Windows.WindOverrideHelper(Size constraint)System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)at的System.Windows.Interop.HwndSource.SetLayoutSize()处的System.Windows.UIElement.Measure(Size availableSize)中的m.Windows.FrameworkElement.MeasureCore(Size availableSize) System.Windows.Interop.HwndSource.set_RootVisual(视觉值)System.Windows.Window.SetRootVisual()在System.Windows.Window.SetRootVisualAndUpdateSTC()在System.Windows.Window.SetupInitialState(双人间requestedTop,双requestedLeft,双requestedWidth …

.net wpf exception

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