package com.hy.rain.controller;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hy.rain.bean.BannerItem;
@RestController
@RequestMapping("banner1")
public class BannerItemController1 {
@RequestMapping("list1")
public List<BannerItem> getList(){
List<BannerItem> list=new ArrayList<BannerItem>();
try {
Class.forName("com.mysql.jdbc.Driver");
try {
Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/zreg","root","123456");
String sql="select b.id,b.key_word,i.url from banner_item b JOIN image i on b.img_id=i.id";
PreparedStatement statement=con.prepareStatement(sql);
ResultSet result=statement.executeQuery();
while(result.next()) {
BannerItem banner=new BannerItem();
banner.setId(result.getInt("id"));
banner.setUrl(result.getString("url"));
banner.setKey_word(result.getString("key_word"));
list.add(banner);
}
result.close();
statement.close();
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
}
java封装json数据
最新推荐文章于 2024-05-07 16:09:09 发布