标签:done dom travel public end params get str find
package cn.itcast.travel.dao.impl;
import cn.itcast.travel.dao.RouteDao;
import cn.itcast.travel.domain.Route;
import cn.itcast.travel.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.ArrayList;
import java.util.List;
/**
* @author aojie
* @fuction
* @create 2020-05-15 22:15
*/
public class RouteDaoImpl implements RouteDao {
private JdbcTemplate jdbcTemplate=new JdbcTemplate(JDBCUtils.getDataSource());
@Override
public int findTotalCount(int cid, String rname) {
// String sql="select count(*) from tab_route where cid=?";
String sql="select count(*) from tab_route where 1=1 ";
StringBuilder builder=new StringBuilder(sql);
//用来判断参数是否有值
List params=new ArrayList();
if (cid!=0){
builder.append(" and cid=? ");
//添加?对应的值
params.add(cid);
}
if (rname.equals("")){
builder.append(" and rname like ?");
params.add("%"+rname+"%");
}
sql=builder.toString();
return jdbcTemplate.queryForObject(sql,Integer.class,params.toArray());
}
@Override
public List<Route> findByPage(int cid, int start, int pageSize, String rname) {
// String sql="select * from tab_route where cid=? limit ? , ? ";
String sql="select * from tab_route where 1=1 ";
StringBuilder builder=new StringBuilder(sql);
List params=new ArrayList();
if (cid!=0){
builder.append(" and cid=? ");
//添加?对应的值
params.add(cid);
}
if (rname.equals("")){
builder.append(" and rname like ?");
params.add("%"+rname+"%");
}
builder.append(" limit ? , ?");
sql=builder.toString();
params.add(start);
params.add(pageSize);
return jdbcTemplate.query(sql,new BeanPropertyRowMapper<Route>(Route.class),params.toArray());
}
@Override
public Route findOne(int rid) {
String sql="select * from tab_route where rid=?";
return jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper<Route>(Route.class),rid);
}
}
标签:done dom travel public end params get str find
原文地址:https://www.cnblogs.com/aojie/p/12907714.html