我是Spring的新手。我试图使用DBDAOImplementation
内的条件if语句基于processController
类返回的值呈现视图。我试图为成功场景返回successuseraddstatus
jsp文件,为失败场景返回faileduseraddstatus
jsp文件。
ProcessController.java:
@RequestMapping(value = "/adduserstatus", method = RequestMethod.POST)
public String addStudent(@ModelAttribute("SpringWeb")Process process,ModelMap model) {
model.addAttribute("fname", process.getFname());
model.addAttribute("lname", process.getLname());
model.addAttribute("email", process.getEmail());
model.addAttribute("phone", process.getPhone());
ApplicationContext context =
new ClassPathXmlApplicationContext("Beans.xml");
DBDAOImp dbd =
(DBDAOImp)context.getBean("JDBCTemplate");
dbd.createuser(process.getFname(), process.getLname(), process.getEmail(), process.getPhone());
if (true){ //This is where I am having trouble
return "successuseraddstatus";
}
return "faileduseraddstatus";
}
DBDAOImplementation.java:
@Override
public Boolean createuser(String fname, String lname, String email, String phone) {
isExists(email);
if (isExists==false){
String SQL = "insert into USERS (user_id,f_name,l_name,creation_date,email,phone) values (seq_users.nextval,?,?,sysdate,?,?)";
jdbcTemplateObject.update( SQL, fname,lname,email,phone);
System.out.println("Created Record");
return true;
} else {
return false;
}
}
答案 0 :(得分:0)
如果条件有效,则在下面。但我不太确定这是否是正确的做法。
ProcessController.java:
@RequestMapping(value = "/adduserstatus", method = RequestMethod.POST)
public String addStudent(@ModelAttribute("SpringWeb")Process process,ModelMap model) {
model.addAttribute("fname", process.getFname());
model.addAttribute("lname", process.getLname());
model.addAttribute("email", process.getEmail());
model.addAttribute("phone", process.getPhone());
DBDAOImp dbd =
(DBDAOImp)context.getBean("JDBCTemplate");
if (dbd.createuser(process.getFname(), process.getLname(), process.getEmail(), process.getPhone())){
return "useraddstatus";
} else {
return "faileduseraddstatus";
}
}