本文整理汇总了Java中org.springframework.jdbc.core.RowMapper类的典型用法代码示例。如果您正苦于以下问题:Java RowMapper类的具体用法?Java RowMapper怎么用?Java RowMapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RowMapper类属于org.springframework.jdbc.core包,在下文中一共展示了RowMapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findAllBooks
import org.springframework.jdbc.core.RowMapper; //导入依赖的package包/类
@Override
public List<Book> findAllBooks(String author) {
// TODO Auto-generated method stub
System.out.println(author);
String FIND_ALL_Author="select * from book where author=?";
return jdbcTemplate.query(FIND_ALL_Author,new String[]{author}, new RowMapper<Book>() {
@Override
public Book mapRow(ResultSet set, int rows) throws SQLException {
// TODO Auto-generated method stub
Book book=new Book();
while(set.next())
{
book.setAuthor(set.getString("author"));
book.setBookName(set.getString("bookName"));
book.setISBN(set.getLong("ISBN"));
book.setPublication(set.getString("publication"));
book.setDescription(set.getString("description"));
}
System.out.println(book.getISBN()+"\t"+book.getAuthor());
return book;
}
});
}
示例2: create
import org.springframework.jdbc.core.RowMapper; //导入依赖的package包/类
/**
* Creates a {@link QueryLookupStrategy} for the given {@link EntityManager}
* and {@link Key}.
*
* @param em must not be {@literal null}.
* @param key may be {@literal null}.
* @param extractor must not be {@literal null}.
* @param evaluationContextProvider must not be {@literal null}.
* @return
*/
public static QueryLookupStrategy create(Key key, EvaluationContextProvider evaluationContextProvider,
SqlGenerator generator, NamedParameterJdbcTemplate template, RowMapper rowMapper,
TableDescription tableDescription) {
Assert.notNull(evaluationContextProvider, "EvaluationContextProvider must not be null!");
switch (key != null ? key : Key.CREATE_IF_NOT_FOUND) {
case CREATE:
return new CreateQueryLookupStrategy(generator, template, rowMapper, tableDescription);
case USE_DECLARED_QUERY:
return new DeclaredQueryLookupStrategy(generator, template, rowMapper, tableDescription);
case CREATE_IF_NOT_FOUND:
return new CreateIfNotFoundQueryLookupStrategy(generator, template, rowMapper, tableDescription);
default:
throw new IllegalArgumentException(String.format("Unsupported query lookup strategy %s!", key));
}
}
示例3: getCharacterStream
import org.springframework.jdbc.core.RowMapper; //导入依赖的package包/类
public Reader getCharacterStream(String id) throws SQLException {
final String sql = "SELECT CONTENT_ FROM BDF2_CLOB_STORE WHERE ID_=?";
List<Reader> list = super.getJdbcTemplate().query(sql,
new Object[] { id }, new RowMapper<Reader>() {
public Reader mapRow(ResultSet resultset, int i)
throws SQLException {
Reader content = LobStoreServiceImpl.this
.getLobHandler().getClobAsCharacterStream(
resultset, 1);
return content;
}
});
if(list.size() > 0){
return list.get(0);
}
return null;
}
示例4: pagingQuery
import org.springframework.jdbc.core.RowMapper; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void pagingQuery(Page<?> page,String sql,String dataSourceName,Map<String,Object> parameters,RowMapper<?> mapper){
NamedParameterJdbcTemplate namedjdbcTemplate=this.getNamedParameterJdbcTemplate(dataSourceName);
String querySql=this.getDialect(this.getJdbcTemplate(dataSourceName)).getPaginationSql(sql, page.getPageNo(), page.getPageSize());
String countSql="select count(*) from ("+sql+") sub_table_alias_";
if(parameters!=null){
if(mapper==null){
page.setEntities((List)namedjdbcTemplate.queryForList(querySql,parameters));
}else{
page.setEntities((List)namedjdbcTemplate.query(querySql,parameters,mapper));
}
page.setEntityCount(namedjdbcTemplate.queryForObject(countSql,parameters, Integer.class));
}else{
JdbcTemplate jdbcTemplate=this.getJdbcTemplate(dataSourceName);
if(mapper==null){
page.setEntities((List)jdbcTemplate.queryForList(querySql));
}else{
page.setEntities((List)jdbcTemplate.query(querySql,mapper));
}
page.setEntityCount(jdbcTemplate.queryForObject(countSql, Integer.class));
}
}
示例5: getEmployee
import org.springframework.jdbc.core.RowMapper; //导入依赖的package包/类
@Override
public Employee getEmployee(Integer id) {
String sql = "SELECT * FROM employee WHERE id = ?";
return jdbcInsert.getJdbcTemplate().queryForObject(sql, new RowMapper<Employee>() {
@Override
public Employee mapRow(ResultSet rs, int rowNum) throws SQLException {
Employee emp = new Employee();
emp.setId(rs.getInt("id"));
emp.setEmpId(rs.getInt("empId"));
emp.setFirstName(rs.getString("firstName"));
emp.setLastName(rs.getString("lastName"));
emp.setBirthday(rs.getDate("birthday"));
emp.setAge(rs.getInt("age"));
emp.setEmail(rs.getString("email"));
emp.setDeptId(rs.getInt("deptId"));
return emp;
}
}, id);
}
示例6: getRowMapper
import org.springframework.jdbc.core.RowMapper; //导入依赖的package包/类
private static RowMapper<Bookmark> getRowMapper() {
return (rs, rowNum) -> {
Bookmark bookmark = new Bookmark();
bookmark.setId(rs.getLong(BOOKMARK_ID.name()));
bookmark.setName(rs.getString(BOOKMARK_NAME.name()));
bookmark.setStartIndex(rs.getInt(START_INDEX.name()));
bookmark.setEndIndex(rs.getInt(END_INDEX.name()));
bookmark.setChromosome(new Chromosome(rs.getLong(REFERRED_CHROMOSOME_ID.name())));
bookmark.getChromosome().setName(rs.getString(CHROMOSOME_NAME.name()));
bookmark.setCreatedBy(rs.getLong(CREATED_BY.name()));
bookmark.setCreatedDate(new Date(rs.getTimestamp(CREATED_DATE.name()).getTime()));
return bookmark;
};
}
示例7: getUserGrantedAuthority
import org.springframework.jdbc.core.RowMapper; //导入依赖的package包/类
@Override
public List<RolePermission> getUserGrantedAuthority(int userId) {
String sql = "SELECT * FROM role_permission WHERE userId=?";
List<RolePermission> roleperms = jdbcInsert.getJdbcTemplate().query(sql, new Object[]{userId}, new RowMapper<RolePermission>() {
@Override
public RolePermission mapRow(ResultSet rs, int rowNum) throws SQLException {
RolePermission roleperm = new RolePermission();
roleperm.setId(rs.getInt("id"));
roleperm.setRoleId(rs.getInt("roleId"));
roleperm.setPermissionId(rs.getInt("permissionId"));
roleperm.setUserId(rs.getInt("userId"));
return roleperm;
}
});
return roleperms;
}
示例8: loadNestedProjects
import org.springframework.jdbc.core.RowMapper; //导入依赖的package包/类
@Transactional(propagation = Propagation.MANDATORY)
public Map<Long, List<Project>> loadNestedProjects(List<Long> parentIds) {
if (CollectionUtils.isEmpty(parentIds)) {
return Collections.emptyMap();
}
long listId = daoHelper.createTempLongList(parentIds);
Map<Long, List<Project>> map = new HashMap<>();
RowMapper<Project> rowMapper = ProjectParameters.getRowMapper();
getJdbcTemplate().query(loadProjectsByParentIdsQuery, rs -> {
Project project = rowMapper.mapRow(rs, 0);
long parentId = rs.getLong(ProjectParameters.PARENT_ID.name());
if (!map.containsKey(parentId)) {
map.put(parentId, new ArrayList<>());
}
map.get(parentId).add(project);
}, listId);
daoHelper.clearTempList(listId);
return map;
}
示例9: readCallBackUrlByClientId
import org.springframework.jdbc.core.RowMapper; //导入依赖的package包/类
public List<Map<String, String>> readCallBackUrlByClientId(Set<String> clientIds) {
try {
String parameterIds = "'" + Joiner.on("','").join(clientIds) + "'";
return jdbcTemplate.query(CALLBACK_URL_CLIENT_ID_SELECT_STATEMENT + "(" + parameterIds + ")",new RowMapper<Map<String, String>>(){
@Override
public Map<String, String> mapRow(ResultSet rs, int rowNum) throws SQLException {
return ImmutableMap.of("clientId",rs.getString("client_id"),"callbackUrl",rs.getString("callback_url"),"clientSecret",rs.getString("client_secret"));
}
});
} catch (DataAccessException e) {
e.printStackTrace();
}
return Collections.emptyList();
}
示例10: getRowMapper
import org.springframework.jdbc.core.RowMapper; //导入依赖的package包/类
static RowMapper<Person> getRowMapper() {
return (rs, rowNum) -> {
Person person = new Person();
person.setId(rs.getLong(PERSON_ID.name()));
person.setName(rs.getString(NAME.name()));
person.setEmail(rs.getString(EMAIL.name()));
long longVal = rs.getLong(ROLE_ID.name());
if (!rs.wasNull()) {
person.setRole(PersonRole.getRoleById(longVal));
}
return person;
};
}
示例11: getDepartments
import org.springframework.jdbc.core.RowMapper; //导入依赖的package包/类
@Override
public List<Department> getDepartments() {
String sql = "SELECT * FROM department";
List<Department> depts = jdbcInsert.getJdbcTemplate().query(sql, new RowMapper<Department>() {
@Override
public Department mapRow(ResultSet rs, int rowNum) throws SQLException {
Department dept = new Department();
dept.setId(rs.getInt("id"));
dept.setDeptId(rs.getInt("deptId"));
dept.setName(rs.getString("name"));
return dept;
}
});
return depts;
}
示例12: listForMapList
import org.springframework.jdbc.core.RowMapper; //导入依赖的package包/类
public List<Map<String, Object>> listForMapList(String sql, int nowPage, int pageSize, Object... args) {
sql = initSql(sql);
String limitSql = null;
try {
limitSql = SelectLimitUtils.getLimitSql(sql, nowPage, pageSize);
} catch (JSQLParserException e) {
System.out.println(sql + ",格式不正确,请检查后再试.");
return null;
}
Page<Map<String, Object>> page = new Page<Map<String, Object>>();
List<Object> objs = new ArrayList<Object>();
if (args != null && args.length > 0) {
for (Object obj : args) {
objs.add(obj);
}
}
return getJdbcTemplate().query(limitSql, objs.toArray(), new RowMapper<Map<String, Object>>() {
public Map<String, Object> mapRow(ResultSet rs, int i) throws SQLException {
return toMap(rs);
}
});
}
示例13: getUser
import org.springframework.jdbc.core.RowMapper; //导入依赖的package包/类
@Override
public AccountLogin getUser(String username) {
String sql = "SELECT * FROM logindetails WHERE username=?";
return jdbcInsert.getJdbcTemplate().queryForObject(sql, new RowMapper<AccountLogin>() {
@Override
public AccountLogin mapRow(ResultSet rs, int rowNum) throws SQLException {
AccountLogin account = new AccountLogin();
account.setId(rs.getInt("id"));
account.setUsername(rs.getString("username"));
account.setPassword(rs.getString("password"));
account.setEncPassword(rs.getString("enc_password"));
return account;
}
}, username);
}
示例14: getBytes
import org.springframework.jdbc.core.RowMapper; //导入依赖的package包/类
public byte[] getBytes(String id) throws SQLException {
final String sql = "SELECT CONTENT_ FROM BDF2_BLOB_STORE WHERE ID_=?";
List<byte[]> list = super.getJdbcTemplate().query(sql,
new Object[] { id }, new RowMapper<byte[]>() {
public byte[] mapRow(ResultSet resultset, int i)
throws SQLException {
byte[] content = LobStoreServiceImpl.this
.getLobHandler().getBlobAsBytes(resultset, 1);
return content;
}
});
if(list.size()>0){
return list.get(0);
}else{
return null;
}
}
示例15: getUserRole
import org.springframework.jdbc.core.RowMapper; //导入依赖的package包/类
@Override
public Role getUserRole(int id) {
String sql = "SELECT * FROM role WHERE id=?";
return jdbcInsert.getJdbcTemplate().queryForObject(sql, new RowMapper<Role>() {
@Override
public Role mapRow(ResultSet rs, int rowNum) throws SQLException {
Role role = new Role();
role.setId(rs.getInt("id"));
role.setName(rs.getString("name"));
role.setDescription(rs.getString("description"));
return role;
}
}, id);
}