Quellcode durchsuchen

JdbcUtil.queryList

XMTT vor 8 Jahren
Ursprung
Commit
a5e5d67821

+ 0 - 37
src/main/java/com/ekexiu/console/system/dao/ViewCustomerDao.java

@ -10,11 +10,7 @@ import org.jfw.apt.orm.annotation.dao.param.Like;
10 10
import org.jfw.util.PageQueryResult;
11 11
12 12
import java.sql.Connection;
13
import java.sql.PreparedStatement;
14
import java.sql.ResultSet;
15 13
import java.sql.SQLException;
16
import java.util.ArrayList;
17
import java.util.List;
18 14
19 15
@DAO
20 16
public abstract class ViewCustomerDao {
@ -26,37 +22,4 @@ public abstract class ViewCustomerDao {
26 22
	@OrderBy(" ORDER BY create_time")
27 23
	public abstract PageQueryResult<ViewCustomer> query(Connection con, @Like String name, @Like String address, @Like String orgname, @Nullable Integer sendMailStatus, int pageSize, int pageNo) throws SQLException;
28 24
29
	public java.util.List<ViewCustomer> orgName(Connection con,String orgname) throws SQLException{
30
		int index = 1;
31
		boolean oname = null == orgname;
32
		StringBuilder sql = new StringBuilder();
33
		sql.append("SELECT ORGNAME FROM view_customer");
34
		if(!oname){
35
			sql.append(" WHERE ORGNAME LIKE ? group by orgname");
36
		}
37
		PreparedStatement ps = con.prepareStatement(sql.toString());
38
		try{
39
			if(!oname){
40
				ps.setString(index++,orgname);
41
			}
42
			ResultSet rs = ps.executeQuery();
43
			try{
44
				List<ViewCustomer> viewCustomers = new ArrayList<ViewCustomer>();
45
				while(rs.next()){
46
					ViewCustomer viewCustomer =  new ViewCustomer();
47
					String orgName = rs.getString(1);
48
					if(rs.wasNull()){
49
						orgName = null;
50
					}
51
					viewCustomer.setOrgname(orgName);
52
					viewCustomers.add(viewCustomer);
53
				}
54
				return viewCustomers;
55
			}finally{
56
				try{rs.close();}catch(Exception e){}
57
			}
58
		}finally{
59
			try{ps.close();}catch(Exception e){}
60
		}
61
	}
62 25
}

+ 11 - 6
src/main/java/com/ekexiu/console/system/service/ViewCustomerService.java

@ -11,8 +11,11 @@ import org.jfw.apt.web.annotation.operate.Get;
11 11
import org.jfw.apt.web.annotation.param.JdbcConn;
12 12
import org.jfw.apt.web.annotation.param.PathVar;
13 13
import org.jfw.util.PageQueryResult;
14
import org.jfw.util.jdbc.JdbcUtil;
15
import org.jfw.util.jdbc.ResultSetExtractor;
14 16
15 17
import java.sql.Connection;
18
import java.sql.ResultSet;
16 19
import java.sql.SQLException;
17 20
import java.util.ArrayList;
18 21
import java.util.List;
@ -59,13 +62,15 @@ public class ViewCustomerService {
59 62
	@Get
60 63
	@Path("/orgName")
61 64
	public List<TestService.TypeaheadItem> get(@JdbcConn Connection con, String q, @DefaultValue("11") int s) throws SQLException{
62
		String key=null;
63
		if(q!=null)
64
		{
65
			key="%"+q+"%";
66
		}
67 65
		List<TestService.TypeaheadItem> ret = new ArrayList<>(s);
68
		List<ViewCustomer> typeahead = this.viewCustomerDao.orgName(con, key);
66
		List<ViewCustomer> typeahead = JdbcUtil.queryList(con, "SELECT ORGNAME FROM view_customer WHERE ORGNAME LIKE '%" + q + "%' group by orgname", new ResultSetExtractor<ViewCustomer>() {
67
			@Override
68
			public ViewCustomer extractData(ResultSet resultSet) throws SQLException {
69
				ViewCustomer viewCustomer = new ViewCustomer();
70
				viewCustomer.setOrgname(resultSet.getString("ORGNAME"));
71
				return viewCustomer;
72
			}
73
		});
69 74
		for (ViewCustomer viewCustomer : typeahead) {
70 75
			TestService.TypeaheadItem thi = new TestService.TypeaheadItem();
71 76
			thi.setCode(viewCustomer.getOrgname());