package com.niu.service;
import com.niu.sxs.domain.LeeYqsbWhjl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.List;
@SpringBootTest
public class Test {
@Autowired
private JdbcTemplate jdbcTemplate;
public Object select(String tabName){
String sql = "SELECT * from "+tabName+"";
Object obj= jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(LeeYqsbWhjl.class));
return obj;
}
@org.junit.jupiter.api.Test
public void test1(){
// Object obj= select("lee_yqsb_whjl");
Object obj= select("lee_yqsb_basic");
obj=(List<LeeYqsbWhjl>) obj;
System.out.println("obj = " + obj);
}
}
/**
* 获取最大序号
*/
public Integer getMaxSnum(String field,String tabName){
String sql = "SELECT max("+field+") from "+tabName;
Integer maxSnum = jdbcTemplate.queryForObject(sql, Integer.class);
if (maxSnum != null) {
return maxSnum+1;
} else {
return 1;
}
}