我想只选择特定的列(例如SELECT a FROM b).我有一个通用的DAO,我想出的是:
public List<T> getAll(boolean idAndVersionOnly) {
CriteriaBuilder builder = manager.getCriteriaBuilder();
CriteriaQuery<T> criteria = builder.createQuery(entityClazz);
Root<T> root = criteria.from(entityClazz);
if (idAndVersionOnly) {
criteria.select(root.get("ID").get("VERSION")); // HERE IS ERROR
} else {
criteria.select(root);
}
return manager.createQuery(criteria).getResultList();
}
Run Code Online (Sandbox Code Playgroud)
错误是:
The method select(Selection<? extends T>) in the type CriteriaQuery<T> is not applicable for the arguments (Path<Object>).我该怎么改变?我想得到一个T只有ID和VERSION字段的类型对象,而其他所有的都是null.
类型Textends AbstractEntity包含这两个字段.
entityClazz是T.class.
我遇到了将搜索栏添加到导航项的新方法的问题.
正如您在下图中所看到的,有两个UIViewControllers一个接一个,并且都有搜索栏.问题是动画,当搜索栏在第一个视图控制器上可见但在第二个视图控制器上不可见时,这很难看.搜索栏占用的区域停留在屏幕上并突然消失.
代码非常基本(项目中没有其他更改):
(我主要使用C#编写,因此此代码中可能存在错误.)
ViewController.swift:
import UIKit
class ViewController: UITableViewController, UISearchResultsUpdating {
override func loadView() {
super.loadView()
definesPresentationContext = true;
navigationController?.navigationBar.prefersLargeTitles = true;
navigationItem.largeTitleDisplayMode = .automatic;
navigationItem.title = "VC"
tableView.insetsContentViewsToSafeArea = true;
tableView.dataSource = self;
refreshControl = UIRefreshControl();
refreshControl?.addTarget(self, action: #selector(ViewController.handleRefresh(_:)), for: UIControlEvents.valueChanged)
tableView.refreshControl = refreshControl;
let stvc = UITableViewController();
stvc.tableView.dataSource = self;
let sc = UISearchController(searchResultsController: stvc);
sc.searchResultsUpdater = self;
navigationItem.searchController = sc;
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: …Run Code Online (Sandbox Code Playgroud) 我刚刚安装了Visual Studio 2012,并希望创建我的第一个WCF服务应用程序.我是一名来自.NET世界的Java开发人员,所以请理解:)
我创建了一个新的C#项目WCF服务应用程序.然后我点击Debug(或F5),我得到一个错误说:
Unable to launch IIS Express
Run Code Online (Sandbox Code Playgroud)
当我再次点击时会出现另一个这样的错误,但这次IIS出现在托盘中,我收到通知(气泡),当我点击它时会显示一条消息:
Port '53234' is already being used by process 'IIS Express' (process ID '5524')
Run Code Online (Sandbox Code Playgroud)
我尝试在Web选项卡中更改项目属性中的端口,但它不会更改任何内容.msgs是相同的,只是端口号改变了.
对我来说这很有趣,但我无法修复它.我已经尝试更改端口,我重新安装了IIS,重新启动了Visual Studio和PC.我想要使用的端口上没有运行任何东西.
我使用的是Windows 8.1 x64,Visual Studio 2012(IIS 8).
编辑
IIS中有一个log msg:
Failed to register URL "http://localhost:53234/" for site "WcfService1" application "/". Error description: Cannot create a file when that file already exists. (0x800700b7)
Registration completed
Run Code Online (Sandbox Code Playgroud) 假设我有以下XML文件:
<authors>
<author>a1</author>
<author>a2</author>
<lastmodified>2010</lastmodified>
</authors>
Run Code Online (Sandbox Code Playgroud)
和XML模式片段:
<xs:element name="authors" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="author" maxOccurs="unbounded" type="xs:string"> </xs:element>
<xs:element name="lastmodified" type="xs:date" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="uniqueAuthor">
<xs:selector xpath="."/>
<xs:field xpath="author"/>
</xs:unique>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
我想要的是制作一个不允许两个相同的作者值的约束,但上面的那个不起作用.我究竟做错了什么?
我想保护一些行不被删除,我更喜欢使用触发器而不是我的应用程序的逻辑.我正在使用MySQL数据库.
我想出的是:
DELIMITER $$
DROP TRIGGER `preserve_permissions`$$
USE `systemzarzadzaniareporterami`$$
CREATE TRIGGER `preserve_permissions`
AFTER DELETE ON `permissions`
FOR EACH ROW
BEGIN
IF old.`userLevel` = 0 AND old.`permissionCode` = 164 THEN
INSERT INTO `permissions` SET `userLevel`=0, `permissionCode`=164;
END IF;
END$$
DELIMITER ;
Run Code Online (Sandbox Code Playgroud)
但是当我使用delete时它会给我一个错误:
DELETE FROM `systemzarzadzaniareporterami`.`permissions`
WHERE `userLevel` = 0 AND `permissionCode` = 164;
Error Code: 1442. Can't update table 'permissions' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
Run Code Online (Sandbox Code Playgroud)
有没有其他办法做这样的事情?
我正在实现一个类似于Messages应用程序中发生的视图,因此有一个视图,UITextView附加到屏幕的底部,还有UITableView显示主要内容.当它被轻敲时,它会随着键盘向上滑动,当键盘被解除时,它会滑回到屏幕的底部.
我有这个部分并且它完美地工作 - 我只是订阅键盘通知 - 将隐藏和显示.
问题是我已经在UITableView上将键盘解除模式设置为交互式,并且我无法在平移时捕获对键盘的更改.
第二个问题是这个uitextview栏覆盖了uitableview的某些部分.如何解决这个问题?我仍然希望uitableview像在消息应用程序中一样"在"这个栏下面.
我在所有地方都使用AutoLayout.
任何帮助将不胜感激!
============
EDIT1:这是一些代码:
查看层次结构如下:
视图 - UITableView(这个将包含"消息") - UIView(这个将滑动)
UITableView对父视图的顶部,左侧,右侧和底部有约束,因此它填满整个屏幕.UIView对父视图的左侧,右侧和底部有约束,因此它粘在底部 - 我通过调整约束的常量来移动它.
在ViewWillAppear方法中:
NSNotificationCenter.DefaultCenter.AddObserver (UIKeyboard.DidShowNotification, OnKeyboardDidShowNotification);
NSNotificationCenter.DefaultCenter.AddObserver (UIKeyboard.WillChangeFrameNotification, OnKeyboardDidShowNotification);
NSNotificationCenter.DefaultCenter.AddObserver (UIKeyboard.WillHideNotification, OnKeyboardWillHideNotification);
Run Code Online (Sandbox Code Playgroud)
以下是方法:
void OnKeyboardDidShowNotification (NSNotification notification)
{
AdjustViewToKeyboard (Ui.KeyboardHeightFromNotification (notification), notification);
}
void OnKeyboardWillHideNotification (NSNotification notification)
{
AdjustViewToKeyboard (0.0f, notification);
}
void AdjustViewToKeyboard (float offset, NSNotification notification = null)
{
commentEditViewBottomConstraint.Constant = -offset;
if (notification != null) {
UIView.BeginAnimations (null, IntPtr.Zero);
UIView.SetAnimationDuration (Ui.KeyboardAnimationDurationFromNotification (notification));
UIView.SetAnimationCurve ((UIViewAnimationCurve)Ui.KeyboardAnimationCurveFromNotification (notification));
UIView.SetAnimationBeginsFromCurrentState (true);
} …Run Code Online (Sandbox Code Playgroud) 是否可以使用Preferences API将我的应用程序的设置存储在自定义文件中?从我所读到的,在Windows首选项存储在注册表中这不是一个好主意imho我希望我的应用程序保存prefs让我们说D:\ app.preferences.可能吗?
我正在编写一个使用对象输出和输入流的应用程序.但是我有一个问题,因为我无法正确发送我的对象.我将它写入流,并且服务器给我一个类未找到异常,即使客户端和服务器都具有完全相同的此类副本(唯一的区别是包名称)具有相同的序列ID.这是我的班级:
import java.io.Serializable;
public class Message implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String username = null;
private String hashedPassword = null;
private Integer code = null;
private String from = null;
private String to = null;
private Object data = null;
public Message() {
}
public Message(Integer code) {
this.code = code;
}
public Message(Integer code, Object data) {
this.code = code;
this.data = data;
}
public Message(String username, String hashedPassword, Integer …Run Code Online (Sandbox Code Playgroud) 我正在编写一个将使用多个线程的应用程序.有一个主线程正在启动另一个线程.我想要实现的是当其中一个启动的线程抛出异常时,主线程应该停止启动线程.它看起来或多或少像这样:
class SomeClass {
boolean launchNewThread = true;
public static void main() {
while (launchNewThread) {
try {
AnotherClass.run();
} catch (CrossThreadException e) {
launchNewThread = false;
}
}
}
}
class AnotherClass implements Runnable {
public void run() {
if (a=0) throw new CrossThreadException();
}
Run Code Online (Sandbox Code Playgroud)
}
我想从MySQL数据库中删除具有指定名称的所有用户,而不管host参数如何。这是我写的:
DELIMITER ;;
## CREATING SCHEMA
DROP SCHEMA IF EXISTS rms;;
CREATE SCHEMA rms;;
USE rms;;
## DROP USER
DROP PROCEDURE IF EXISTS PREPARE_USERS;;
CREATE PROCEDURE PREPARE_USERS()
BEGIN
DECLARE V_RECORD_NOT_FOUND INTEGER DEFAULT 0;
DECLARE V_USER_HOST CHAR(60);
DECLARE C_HOSTS_CURSOR CURSOR FOR
SELECT host FROM mysql.user WHERE user='rms';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET V_RECORD_NOT_FOUND = 0;
OPEN C_HOSTS_CURSOR;
READ_LOOP: LOOP
FETCH C_HOSTS_CURSOR INTO V_USER_HOST;
IF V_RECORD_NOT_FOUND != 0 THEN
LEAVE READ_LOOP;
END IF;
SET @V_EXEC=CONCAT(CONCAT('DROP USER \'rms\'@\'',V_USER_HOST),'\';;');
PREPARE V_STMT FROM …Run Code Online (Sandbox Code Playgroud) 我正在尝试进行此类转换,但我遇到了一些问题.
假设我有一个以下字符串:
String in = "1234567890123456";
Run Code Online (Sandbox Code Playgroud)
然后我将它转换为ByteArrayInputStream,如下所示:
ByteArrayInputStream bais = new ByteArrayInputStream(in.getBytes("UTF-8"));
Run Code Online (Sandbox Code Playgroud)
我也有:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Run Code Online (Sandbox Code Playgroud)
然后我加密:
ch.encrypt(bais, baos);
Run Code Online (Sandbox Code Playgroud)
所以现在我的"输出"了baos.当我这样做的时候:
byte[] b2 = baos.toByteArray();
int[] i2 = toUnsignedIntArray(b2);
writeIntegersAsHex(i2);
Run Code Online (Sandbox Code Playgroud)
哪里(我知道它不是最优雅的方式,但它仅用于测试):
public static void writeIntegersAsHex(int[] integers) {
int height = integers.length;
for (int i = 0; i < height; i++) {
System.out.print(Integer.toHexString(integers[i]) + ",");
}
System.out.println("");
}
Run Code Online (Sandbox Code Playgroud)
我得到这样的输出:
d1,68,a0,46,32,37,25,64,67,71,17,df,ee,ef,2,12,
Run Code Online (Sandbox Code Playgroud)
并且该输出是正确的,因为当我处理包含相同字符串的文件时,in该输出是相同的.但我无法从中获得正确的字符串baos.
请不要问我为什么这样做,因为这不是我的电话.我是学生,这是一个例外.
算法(顺便说一句,它是aes128)工作正常,文件,但我不能得到字符串输入流和输出流到字符串工作正常.
java ×5
ios ×2
mysql ×2
animation ×1
autolayout ×1
c# ×1
constraints ×1
criteria-api ×1
delete-row ×1
eofexception ×1
exception ×1
hibernate ×1
iis ×1
inputstream ×1
ios11 ×1
jpa ×1
outputstream ×1
preferences ×1
schema ×1
string ×1
uikeyboard ×1
uisearchbar ×1
uitableview ×1
unique ×1
wcf ×1
xamarin ×1
xml ×1