java在if中返回_【Java】如下程序,Springmvc中 controller可以在内部加一个if语句,返回不同的modelandview吗?...

@RequestMapping(value = “/index”)

public ModelAndView index(Page p2, ZqbpContract params,

HttpServletRequest request,String id,String name,String god,String oneid,String twoid,String s) throws SQLException {

ModelAndView view = new ModelAndView("/Admin/Contract/contract-index");

HttpSession session = request.getSession();

ZqbpUser user = (ZqbpUser) session.getAttribute(ConfigUtil.USER);

ConnectionSource connectionSource = DBUtil.getConnectionSource();

Page p;

String l="";

String sql = "select contract_id,contract_name,contract_filename,contract_money,contract_num,contract_status,contract_type,contract_url,con_money_fangshi,con_xitong,create_time,stop_time,user_id,custom_id,flow_id,(select product_name from zqbp_product where product_id=con_chanpin) as con_chanpin,(select sum(money) from zqbp_con_m where con_id=contract_id) as create_user from zqbp_contract where status='0'";

int a=0;

if(id!=null&&id!=""){

a=Integer.parseInt(id.toString());

if(a!=2&&a!=3&&a!=4&&a!=5){

sql+=" and custom_id like '%"+id+"%'";

}

}

if(god!=""&&god!=null){

int x=Integer.parseInt(god);

if(x==1){

List c=(List)session.getAttribute("list6");

for(ZqbpContract t:c){

l+="'"+t.getContractId()+"',";

}

if(l.endsWith(",")){

l=l.substring(0, l.length()-1);

}

sql+=" and contract_id in ("+l+")";

}else if(x==2){

Page c=(Page)session.getAttribute("ct");

if(c.getItem()!=null){

//如果判断为空的话,我想返回不同的页面应该怎么写啊?@@@@@@@@@@@@@@@@@@@

for(ZqbpContract t:c.getList()){

System.out.println(123);

l+="'"+t.getContractId()+"',";

}

if(l.endsWith(",")){

l=l.substring(0, l.length()-1);

}

sql+=" and contract_id in ("+l+")";

}else{

sql+=" and contract_id in ('zqbp_contract')";

}

}else{

List c=(List)session.getAttribute("tac");

for(ZqbpContract t:c){

l+="'"+t.getContractId()+"',";

}

if(l.endsWith(",")){

l=l.substring(0, l.length()-1);

}

sql+=" and contract_id in ("+l+")";

}

}

if(oneid!=""&&oneid!=null){

sql+=" and contract_id='"+oneid+"'";

}

if(twoid!=""&&twoid!=null){

sql+=" and contract_id='"+twoid+"'";

}

String aa="";

if(a==3){

List cc=(List)session.getAttribute("aa");

if(cc.get(0).getContractId()!=null){

for(ZqbpContract ccc:cc){

aa+="'"+ccc.getContractId()+"',";

}

if(aa.endsWith(",")){

aa = aa.substring(0, aa.length() - 1);

}

sql+=" and contract_id in ("+aa+")";

}

}

if(a==2){

List cc=(List)session.getAttribute("list1");

if(cc.get(0).getContractId()!=null){

for(ZqbpContract ccc:cc){

aa+="'"+ccc.getContractId()+"',";

}

if(aa.endsWith(",")){

aa = aa.substring(0, aa.length() - 1);

}

sql+=" and contract_id in ("+aa+")";

}

}

if(a==4){

List cc=(List)session.getAttribute("list2");

if(cc.get(0).getContractId()!=null){

for(ZqbpContract ccc:cc){

aa+="'"+ccc.getContractId()+"',";

}

if(aa.endsWith(",")){

aa = aa.substring(0, aa.length() - 1);

}

sql+=" and contract_id in ("+aa+")";

}

}

if(a==5){

List cc=(List)session.getAttribute("list3");

if(cc.get(0).getContractId()!=null){

for(ZqbpContract ccc:cc){

aa+="'"+ccc.getContractId()+"',";

}

if(aa.endsWith(",")){

aa = aa.substring(0, aa.length() - 1);

}

sql+=" and contract_id in ("+aa+")";

}

}

String dat="";

String u="";

if(name!=null&&name!=""){

sql+=" and stop_time like '%"+name+"%'";

}

if(s!=null&&s!=""){

sql+=" and custom_id like '%"+s+"%'";

}

if(p2.getPage()==1){

p2.setPage(0);

}

p = DBUtil.getMySqlPageSql(ZqbpContract.class, p2, sql);

p2.setList(p.getList());

p2.setPage(p.getPage()<=0?1:p.getPage());

p2.setPageCount(p.getPageCount());

p2.setTotalCount(p.getTotalCount());

for(ZqbpContract c:p2.getList()){

if(c.getCreateUser()!=null && !"".equals(c.getCreateUser())){

c.setCreateUser(Integer.parseInt(c.getContract_money())-Integer.parseInt(c.getCreateUser())+"");

}else{

c.setCreateUser("未收款");

}

}

view.addObject("page", p2);

return view;

}

回答

这里的SQL,业务逻辑,和视图控制都耦合在一起了。

你这样不好分离也不好重构。

先重构分层一下,看看。

直接设置新的视图

view.setView(viewName);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值