我想创建一个类,可以使用JPA本机查询映射到从数据库中提取的结果.有没有办法将没有基础表的实体映射到结果?我提到了这个允许它进行休眠的链接.这可以用JPA来完成吗?
这是我想要映射结果的类.
import java.math.BigDecimal;
import javax.persistence.Entity;
@Entity
public class OpUsage {
String username;
BigDecimal number_of_clicks;
String accordion;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public BigDecimal getNumber_of_clicks() {
return number_of_clicks;
}
public void setNumber_of_clicks(BigDecimal number_of_clicks) {
this.number_of_clicks = number_of_clicks;
}
public String getAccordion() {
return accordion;
}
public void setAccordion(String accordion) {
this.accordion = accordion;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在制作一个安静的应用程序并尝试将对象列表转换为json以获取特定的URL(@RequestMapping/@ResponseBody)
我的classpath中有jackson-hibernate4和jackson-core,databind等.
这是我想要转换为json的对象.
@Entity
@Table(name="Product")
public class Product {
@Id
@Column(name="productId")
@GeneratedValue
protected int productId;
@Column(name="Product_Name")
protected String name;
@Column(name="price")
protected BigDecimal baseprice;
@OneToMany(cascade = javax.persistence.CascadeType.ALL,mappedBy="product",fetch=FetchType.EAGER)
protected List<ProductOption> productoption = new ArrayList<ProductOption>();
@OneToMany(cascade = javax.persistence.CascadeType.ALL,mappedBy="product",fetch=FetchType.EAGER)
protected List<ProductSubOption> productSubOption = new ArrayList<ProductSubOption>();
@ManyToOne
@JoinColumn(name="ofVendor")
protected Vendor vendor;
Run Code Online (Sandbox Code Playgroud)
Product里面的两个对象也是POJO'S ..
这是我检索产品列表的方法
@Override
public List<Product> getMenuForVendor(int vendorId) {
List<Product> result = em.createQuery("from "+Product.class.getName()+" where ofVendor = :vendorId").setParameter("vendorId", vendorId).getResultList();
System.out.println(result.size());
return result;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试在我的控制器中返回此列表时,我得到了"不能懒惰加载json"所以我设置我的对象急切地获取.这是我的控制器
@Autowired
private MenuDaoImpl ms;
@RequestMapping(value = "/{vendorId}", method = RequestMethod.GET) …Run Code Online (Sandbox Code Playgroud) 每次我运行 grails 应用程序时都使用
run-app
Run Code Online (Sandbox Code Playgroud)
它运行良好,但如果我停止使用它
stop-app
Run Code Online (Sandbox Code Playgroud)
然后它会停止,但如果我尝试再次运行它或执行任何其他命令,则会出现以下错误
error executing script runapp _grailsclasspath_groovy$_run_closure1
Run Code Online (Sandbox Code Playgroud)
我必须手动删除所有文件,target>work>scriptCache以便每次都能再次工作。有没有配置错误?clean停止应用程序后我也尝试过,但没有帮助
我正试图在Ionic应用程序中为我的推送通知实现自定义声音.我将声音文件复制到www /也设置了插件选项,如下所示
//In app.run
$ionicPush.init({
"debug": true,
"onNotification": function(notification){
$cordovaDialogs.alert(notification.message, 'Notification', 'OK').then(function(){
console.log(notification);
});
}
"onRegister": function(data) {
console.info("New device registered with token "+data.token);
}
"pluginConfig": {
"ios": {
"badge": true,
"sound": true
},
"android": {
"iconColor": "#343434"
}
}
});
//In my main controller -
$scope.saveUserDeviceReg = function(data){
var ionicUser = Ionic.User.current();
if(!ionicUser.id){
ionicUser.id = $scope.user.userId;
}
ionicUser.set('name', $scope.user.name);
ionicUser.set('image', $scope.user.profilePic);
ionicUser.set('email', $scope.user.email);
$ionicPush.addTokenToUser(ionicUser);
ionicUser.save();
if($scope.user.devices){
$scope.user.devices[data.token] = true;
$scope.user.$save().then(function(success){
console.log("User device saved");
},function(error){
console.error("Error saving user device");
}); …Run Code Online (Sandbox Code Playgroud) 我创建了一个jstree如下
$('#js-tree').jstree({
'core' : {
'data' : {
'url' : "${pageContext.request.contextPath}/makeTree",
"plugins" : [ "types", "search"],
'data' : function (node) {
return { 'id' : node.id };
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
我想在提交信息时检查所选节点是否是叶节点 -
var selectedLeaves = $("#js-tree").jstree("get_selected");
Run Code Online (Sandbox Code Playgroud)
但这只给了我 id 数组。如何使用 is_leaf 方法从所选节点中过滤我们唯一的叶节点?我提到了这篇文章 - 强制用户仅选择叶节点 此解决方案对我不起作用。
我有一个firebase Auth工厂如下
app.factory("Auth", ["$firebaseAuth", "FIREBASE_URL","$ionicPlatform",
function($firebaseAuth, FIREBASE_URL, $ionicPlatform) {
var auth = {};
$ionicPlatform.ready(function(){
var ref = new Firebase(FIREBASE_URL);
auth = $firebaseAuth(ref);
});
return auth;
}
]);
Run Code Online (Sandbox Code Playgroud)
我在我的ui-router解决方案中注入Auth工厂作为依赖关系但是在配置ui-router时,auth是空的,因为平台准备就绪后开始.
app.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('menu', {
url: '/menu',
abstract:true,
cache: false,
controller: 'MenuCtrl',
templateUrl: 'templates/menu.html',
resolve: {
auth: function($state, Auth){
//<--Auth is empty here when the app starts ----->
return Auth.$requireAuth().catch(function(){
$state.go('login'); //if not authenticated send back to login
});
}
}
})
Run Code Online (Sandbox Code Playgroud)
如何确保Auth工厂在注入ui-router之前不为空?
我试过这个 -
app.factory("Auth", ["$firebaseAuth", "FIREBASE_URL","$ionicPlatform",
function($firebaseAuth, FIREBASE_URL, …Run Code Online (Sandbox Code Playgroud) 我从另一个分支切换,因此可以进行推送。签出时,文件在我的编辑器中打开,这可能导致权限被拒绝错误。git是否丢失了我的所有文件?我不知道如何让他们回来。这是我的工作-文件丢失了,
js/Messages目录
templates/Messages目录这些是在我执行git操作时在编辑器中打开的
C:\Users\***\Documents\myproject>git pull
Password for 'https://********@bitbucket.org':
Already up-to-date.
C:\Users\***\Documents\myproject>git checkout paymentmodule
error: cannot stat 'www/js/Messages': Permission denied
error: cannot stat 'www/js/Messages': Permission denied
error: cannot stat 'www/templates/Messages': Permission denied
C:\Users\***\Documents\myproject>git checkout paymentmodule
Switched to branch 'paymentmodule'
C:\Users\***\Documents\myproject>git push origin paymentmodule
Password for 'https://******@bitbucket.org':
To https://*******@bitbucket.org/********/myproject.git
! [rejected] paymentmodule -> paymentmodule (non-fast-forward)
error: failed to push some refs to 'https://********@bitbucket.org/********/myproject.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. …Run Code Online (Sandbox Code Playgroud) 我有一个我正在努力的任务问题,需要一些方向来解决.假设我有一张纸条,我将它从中心折叠,使左半部分落在右半部分后面.然后我按顺序编号折叠的peices,当我展开如下时,我得到数字.1:2
如果我折叠两次我得到的数字展开时如下1:4:3:2
如果我三次折叠我得到如下1 8 5 4 3 6 7 2
当我折叠n次时,我想生成数字数组.因此,如果我将它折叠例如25次,我将以类似的顺序得到2 ^ 25个数字.
这些是我所做的观察
第一个和最后一个数字始终为1和2.
中间的两个数字总是4和3
索引1处的数字是最大数字,第二个最后位置处的数字是第二大数字.
它看起来像二进制搜索树的前序遍历,但我不知道这有多大帮助.
编辑:为了搜索这个生成的数组中的元素,我可以进行顺序搜索,这将是O(n)效率.但我意识到在这个系列中搜索一个数字必须有一个更快的方法.
我不能进行二分搜索,因为它没有排序,当完成25次折叠时有超过十亿的数字.
我可以使用什么样的搜索策略来查找数字及其索引?
这是我想将其转换为具有log(n)搜索效率的二叉搜索树的原因之一.
编辑2:我尝试了其中一个答案建议的表折叠算法,它不是内存效率.我无法在我的内存中存储超过十亿个数字,所以必须有一种方法来查找数字索引,而无需实际创建数字数组.