我在java中编写了一个服务器程序,但是为了给web提供一个接口,我想在点击某个菜单按钮时在jsp中访问java方法.我怎样才能做到这一点?
我遇到了这种情况的问题(我会试着让它变得更容易) - 我的数据库中有用户列出了角色列表和状态列表.
public class User implements Serializable {
@ManyToMany(cascade = CascadeType.ALL, fetch= FetchType.LAZY)
@JoinTable(name = "role_to_user",
joinColumns={@JoinColumn(name = "user_id")},
inverseJoinColumns={@JoinColumn(name = "role_id")})
private Set<Role> roles = new LinkedHashSet<Role>();
@ManyToMany(cascade = CascadeType.ALL, fetch= FetchType.LAZY)
@JoinTable(name = "status_to_user",
joinColumns={@JoinColumn(name = "user_id")},
inverseJoinColumns={@JoinColumn(name = "status_id")})
private Set<Status> statuses = new LinkedHashSet<Status>();
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建一个hibernate标准,该标准能够使用指定的角色和状态返回用户(在使用角色表和状态表加入之后).就像是 :
返回role = 1或role = 2且status = 1的用户
我google了一些东西,现在我可以创建一个查询,只返回指定角色的用户,但不是状态.
Criteria cr = session.createCriteria(User.class)
.createCriteria("roles")
.add(Restrictions.or(Restrictions.eq("roletype", 1), Restrictions.eq("roletype", 2)));
Run Code Online (Sandbox Code Playgroud)
表用户和角色通过role_to_user表与两列(user_id,role_id)连接,类似于表用户和状态通过status_to_role表
谢谢你的建议 :)
我正在研究一个Android项目,我遇到了一个问题,问题是:
当我退回时,Arraylist为空.
这是我的java代码:
ArrayList<ArrayList<Object>> container = new ArrayList<ArrayList<Object>>();
ArrayList<Object> itemRow = new ArrayList<Object>();
JSONObject jsonObj = new JSONObject(result);
JSONArray allElements = jsonObj.getJSONArray("Table");
Log.i("allElements", "" + allElements);
for (int i = 0; i < allElements.length(); i++) {
itemRow.add(allElements.getJSONObject(i).getString("ParentName").toString());
itemRow.add(allElements.getJSONObject(i).getString("ParentEmailID").toString());
itemRow.add(allElements.getJSONObject(i).getString("ParentContact").toString());
itemRow.add(allElements.getJSONObject(i).getString("ParentAddress").toString());
itemRow.add(allElements.getJSONObject(i).getString("ParentProfilePictureName").toString());
itemRow.add(allElements.getJSONObject(i).getString("StudentName").toString());
Log.i("itemRow", "itemRow at index: " + i + ", " + itemRow);
container.add(((i*2)/2), itemRow);
itemRow.clear();
}
return container;
Run Code Online (Sandbox Code Playgroud)
在这段代码中,我有两个Arraylist用于包含所有元素,另一个用于存储单行元素.这些Arraylist是从JSONArray加载的,一切正常,我可以从项目行(Arraylist,单行)打印数据并存储到主Arraylist(容器).
但是当我返回这个Arraylist(容器)并在logcat中打印时,它会显示空的Arraylist
[[], [], [], [], []].
Run Code Online (Sandbox Code Playgroud)
我不明白为什么会发生这种情况请帮我解决这个问题.
谢谢.
这是我的班级:
public class MyClassA {
private int mode;
public static int THREAD_MODE=1;
public static int CLUSTER_MODE=2;
public MyClassA(int mode) {
this.mode= mode;
}
}
Run Code Online (Sandbox Code Playgroud)
我希望将我的spring配置xml中的这些信息发送到我的类实例.我如何实现这样的目标?
<bean id="myclass" class="com.test.MyClassA"> <constructor-arg value="MyClassA.THREAD_MODE"/> </bean>
Run Code Online (Sandbox Code Playgroud) 我试图使用Arrays.binarySearch()方法在字符串数组中找到字符串的索引,但是当查找字符串"Free"时,该方法似乎返回位置整数"-5".知道为什么会这样吗?
String[] names = {"Arken","Ben","Darklark", "Free","group"};
void changeFriends(String uname, boolean b)
{ // change a friend's "online" status
Arrays.sort(names);
int index = Arrays.binarySearch(names, uname);
System.out.println("NAME OF ONLINE USER IS AT INDEX:" + index + "Name:" + uname);
if(index > -1)
{
if(b == true)
{
loggedOn[index] = true;
}
else
{
loggedOn[index] = false;
}
}
// call method to update buttons
changeNameButtons();
}
Run Code Online (Sandbox Code Playgroud) 我试图使用此代码将当前日期和第二天的日期放在JComboBox中
private void dateCombo(){
Calendar cal = new GregorianCalendar();
int month =cal.get(Calendar.MONTH);
int year =cal.get(Calendar.YEAR);
int day =cal.get(Calendar.DAY_OF_MONTH);
cmb_date.addItem(+year+"-"+(month+1)+"-"+day);
cmb_date.addItem(+year+"-"+(month+1)+"-"+(day+1));
}
Run Code Online (Sandbox Code Playgroud)
但它以"yyyy-md"格式显示日期,我希望它以'yyyy-mm-dd'格式显示.
我想我可以用
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
txt_date.setText(sdf.format(date));
Run Code Online (Sandbox Code Playgroud)
以'yyyy-mm-dd'格式获取当前日期,但如何处理第二天的日期?
我正在从包含格式行的文件中读取YYYYMMDD.我如何regular expressions用来检查这些线的有效性?谢谢.该应用程序是一个Java应用程序
如果我创建一个字符串对象为
String s=new String("Stackoverflow");
Run Code Online (Sandbox Code Playgroud)
将String对象仅在堆中创建,或者它还在String常量池中创建一个副本.
提前致谢.
我试图获得不同数组大小的各种排序方法的总耗用时间.我能够获得size = 100,1000,10000和100000的经过时间,但是当我尝试1000000时它只是保持运行而不给出结果(我假设1000000太大了?).有没有办法使用nanoTime获取经过的时间,它会在合理的时间内编译?任何帮助都会很棒!
我的节目:
import java.util.Random;
public class Sorting {
public static void printArray(int[] array) {
System.out.print("The Array: ");
for (int i = 0; i < array.length; i++) {
System.out.print(array[i] + " ");
}
System.out.println();
}
public static void exchange(int[] array, int i, int j) {
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}
public static void selectionSort(int[] array) {
for (int fill = 0; fill < array.length - 2; fill++) {
int minPos = fill;
for …Run Code Online (Sandbox Code Playgroud) 有连接多个的方法ArrayLists吗?
例如:
ArrayList<Integer> a
ArrayList<Integer> b
ArrayList<Integer> c
ArrayList<Integer> d = a + b + c
Run Code Online (Sandbox Code Playgroud)
其中d是一个单独的ArrayList<Integer>,包含保留顺序中a,b,c的所有值
java ×10
collections ×2
date ×2
ajax ×1
android ×1
arraylist ×1
arrays ×1
benchmarking ×1
bubble-sort ×1
date-format ×1
datetime ×1
hibernate ×1
javascript ×1
jcombobox ×1
join ×1
jquery ×1
jsp ×1
list ×1
nanotime ×1
regex ×1
sorting ×1
spring ×1
string ×1
swing ×1