@RestController
@RequestMapping("/check")
@Component
public class MySqlList {
@Resource(name = "oracleJdbcTemplate")
// 数据源
JdbcTemplate OREAV;
@RequestMapping("/test/{tableName}")
public void mqe(@PathVariable String tableName) throws IOException {
//sql
String sql = "select * from LDSYNBASETABLETRACE" ;
//sql添加到集合
List<Map<String, Object>> maps = OREAV.queryForList( sql);
//创建集合
ArrayList<Object> reList = new ArrayList<Object>();
//数据添加到集合
for (Map<String, Object> map : maps) {
reList.add( map );
}
//加上时间
Calendar calendar = Calendar.getInstance();
calendar.add( Calendar.DATE, -1 );
String yestedayDate = new SimpleDateFormat( "yyyyMMdd" ).format( calendar.getTime() );
//本机地址
String path = "C:\\Users\\姜迪\\Desktop\\新建文件夹\\";
String filePath = path + yestedayDate + ".txt";
//io流
File file = new File( filePath );
if (!file.exists()){
file.createNewFile();
}
OutputStreamWriter writer = new OutputStreamWriter( new FileOutputStream( file ));
//写入流
for (Object o : reList) {
writer.write( o.toString() );
}
//关闭流IO
writer.close();
}
}
数据库中获取表中数据存入text中
最新推荐文章于 2022-10-13 10:35:40 发布