功能说明:画面相同,功能不同,使用同一个JSP页面。
界面显示:
JSP界面:
<button id="newtmp" type="button" class="btn btn-purple btn-labeled fa fa-plus" onclick="tonewtmp()">新規作成</button>
<a href="/Template/newtmp?tmpId=${template.TEMPLATEID}&actionId=1">
<input class="btn btn-success" id="tempchange${status.index}" type="button" value="変更"/></a>
<a href="/Template/newtmp?tmpId=${template.TEMPLATEID}&actionId=2">
<input class="btn btn-primary" id="tempcopy${status.index}" type="button" value="コピー"/></a>
<script type="text/javascript">
function tonewtmp() {
window.location.href = "/Template/newtmp?actionId=0";
}
</script>
Controller层:前台像后台传递参数,参数的名称要跟后台接受的参数保持一致,如果不一致需要使用注解,@RequestParam(value="tmpId",required = false) String aa,@RequestParam(value="actionId") String bb,value是前台的参数名称,使用注解默认为传递的参数不可以为空,如果想要为空需要加required = false
@Controller
@Transactional(rollbackFor = Exception.class)
@RequestMapping(value = "/Template")
public class TemplateController {
@Autowired
private TemplateService templateService;
@Autowired
private MeetingShowService meetingShowService;
@Autowired
private ApplicationService applicationService;
@RequestMapping("/newtmp")
public ModelAndView newtmp(@RequestParam(value="tmpId",required = false) String aa,@RequestParam(value="actionId") String bb) {
//新建模板
ModelAndView modelAndView = new ModelAndView("new_template");
modelAndView.addObject("actionId", bb);
List<MeetingShowDto> meetinglist = new ArrayList<>();
if (aa == null) {
//新建显示所有会议
meetinglist = meetingShowService.meetingShowSelect();
modelAndView.addObject("meetinglist", meetinglist);
List<ApplicationDto> applist = applicationService.selectAppactive();
modelAndView.addObject("applist", applist);
} else {
TemplateDto changetmp = templateService.selectByPrimaryKey(aa);
modelAndView.addObject("changetmp", changetmp);
if (bb.equals("2")) {
meetinglist = meetingShowService.meetingShowSelect();
modelAndView.addObject("meetinglist", meetinglist);
List<ApplicationDto> applist = applicationService.selectAppactive();
modelAndView.addObject("applist", applist);
}
}
return modelAndView;
}
}