I want to develop an Spring boot web application where I can generate sets of number and store in a table. For example
This is my controller
@RequestMapping("/testInteger")
public String genint(com.randomdata.entity.Random random) {
int intRange;
try {
for (int i = 0; i < 10; i++) {
intRange = generateRandomIntIntRange(1000, 10000);
String string = Integer.toString(intRange);
random.setRandomNumber(string);
randomDao.save(random);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "index";
}
This is my random number generating method.
public static int generateRandomIntIntRange(int min, int max) {
Random r = new Random();
return r.nextInt((max - min) + 1) + min;
}
But it's can save 1 number in db table and others showing
Hibernate: update random set random_number=? where id=?
Hibernate: update random set random_number=? where id=?
Hibernate: update random set random_number=? where id=?
Hibernate: update random set random_number=? where id=?
Hibernate: update random set random_number=? where id=?
Hibernate: update random set random_number=? where id=?
Hibernate: update random set random_number=? where id=?
Hibernate: update random set random_number=? where id=?
Hibernate: update random set random_number=? where id=?
Of course, I missed something. but I cannot find yet.
Aucun commentaire:
Enregistrer un commentaire