課題でJavaのSpringBootでPostgreSQLのデータを扱っていますが,エラーがこのように文字化けしており解決方法が分かりません.
Java
1 2 displaylist.put(PostgreSQLJDBC.getList(shopid)); 3 ^ 4 ���Ғl: List<Shop>,List<Staff> 5 ���o�l: Map<List<Shop>,List<Staff>> 6 ���R: ���������X�g�Ɖ��������X�g�̒������قȂ�܂� 7 K,V���^�ϐ��̏ꍇ: 8 �C���^�t�F�[�X Map�Ő錾����Ă���K extends Object 9 �C���^�t�F�[�X Map�Ő錾����Ă���V extends Object
具体的なコードとしては,
Java
1 2package com.example.********;//伏せ字.動作確認済 3 4import java.sql.*; 5import java.util.*; 6 7public class PostgreSQLJDBC { 8 9 //public static void main(String args[]) { 10 11 public Map<List<Shop>,List<Staff>> getList(String shopId){ 12 List<Shop> displayShop = new ArrayList<Shop>(); 13 List<Staff> displayStaff = new ArrayList<Staff>(); 14 15 Connection c = null; 16 Statement stmt = null; 17 try { 18 Class.forName("org.postgresql.Driver"); 19 c = DriverManager.getConnection("jdbc:postgresql://*****","****","*****"); 20 //URL,username,passwordを伏字にしておりますがSQL文実行やmap生成まで接続確認済みです. 21 stmt = c.createStatement(); 22 23 String sql = "SELECT shop.shop_id, shop_name, staff_id, first_name, last_name "; 24 sql += " FROM shop JOIN staff "; 25 sql += " ON shop.shop_id=staff.shop_id WHERE staff.shop_id="+shopId; 26 ResultSet rs = stmt.executeQuery(sql); 27 while (rs.next()) { 28 Shop shop = new Shop(); 29 Staff staff = new Staff(); 30 31 //Long shopId = rs.getLong("shop_id"); 32 String shopName = rs.getString("shop_name"); 33 long staffId = rs.getLong("staff_id"); 34 String firstName = rs.getString("first_name"); 35 String lastName = rs.getString("last_name"); 36 37 shop.setShopId(java.lang.Long.parseLong(shopId)); 38 shop.setShopName(shopName); 39 staff.setStaffId(staffId); 40 staff.setShopId(java.lang.Long.parseLong(shopId)); 41 staff.setFirstName(firstName); 42 staff.setLastName(lastName); 43 44 displayShop.add(shop); 45 displayStaff.add(staff); 46 } 47 rs.close(); 48 49 50 stmt.close(); 51 c.close(); 52 53 } catch (Exception e) { 54 System.err.println(e); 55 } 56 57 Map<List<Shop>,List<Staff>> ssList = new HashMap<List<Shop>,List<Staff>>(); 58 ssList.put(displayShop,displayStaff); 59 return ssList; 60 } 61} 62
で生成されるShopクラスとStaffクラスのmapの配列を,
Java
1 2package com.example.********;//伏せ字.動作確認済 3 4import java.util.ArrayList; 5import java.util.HashMap; 6import java.util.List; 7import java.util.Map; 8 9import org.springframework.web.bind.annotation.GetMapping; 10import org.springframework.web.bind.annotation.PathVariable; 11import org.springframework.web.bind.annotation.RequestParam; 12import org.springframework.web.bind.annotation.RestController; 13 14 15 16@RestController 17public class ShopController { 18 /*@GetMapping("/shop") 19 public Map<List<Shop>,List<Staff>> getList(@RequestParam(id = "id") String id) { 20 return getList(id); 21 }*/ 22 23 @GetMapping("/shop/{shopid}") 24 public Map<List<Shop>,List<Staff>> getList(@PathVariable("shopid") String shopid) { 25 PostgreSQLJDBC posgre =new PostgreSQLJDBC(); 26 Map<List<Shop>,List<Staff>> displaylist=new HashMap<List<Shop>,List<Staff>>(); 27 displaylist.put(posgre.getList(shopid)); 28 return displaylist; 29 30 //ssList.put(displayShop,displayStaff); 31 //return PostgreSQLJDBC.getList(shopid); 32 } 33}
のようにしてRestCOntrollerで呼び出してショップIDごとにGoogle ChromeなどのブラウザにJSON形式で出力させたいと考えていますがエラーの部分で引っかかってコンパイルができません.
エラーの箇所から判断するにSpringBootを使っている@GetMapping以下がおかしいのだろうとは分かりますが,半日考えてもうまい解決方法が見つからないので,この辺りをどう直せばコンパイルすることができるのかアドバイス頂きたいです.
gradleの設定などlocalhostに表示させるための基本的な設定は完了しておりサンプルプログラムの動作確認済です.
またJavaのバージョンは質問前に最新のものにしてあります.
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/07/05 02:22 編集
2021/07/05 02:25
2021/07/05 02:39