이미지 파일 불러오기(select-image)(java)
2024. 6. 20. 14:31ㆍJSP+Spring Boot
PigController
package com.khmall.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import com.khmall.dto.Pig;
import com.khmall.service.PigService;
@Controller
public class PigController {
@Autowired
private PigService pigService;
@GetMapping("/")
public String getAllPigs(Model model) {
List<Pig> pigList = pigService.getAllPigs();
model.addAttribute("pigList", pigList);
return "index";
}
@GetMapping("/pigDetail/{pig_id}")
public String getPigById(Model model, @PathVariable int pig_id) {
Pig pig = pigService.getPigById(pig_id);
model.addAttribute("pig",pig);
return "pigDetail";
}
}
---------------------------------------------------------------------------------------------------------
Pig (DTO)
package com.khmall.dto;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class Pig {
private int pig_id;
private String pig_name;
private int pig_age;
private String pig_image_path;
}
-----------------------------------------------------------------------------------------------------------
PigMapper
package com.khmall.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import com.khmall.dto.Pig;
@Mapper
public interface PigMapper {
List<Pig> getAllPigs();
Pig getPigById(int pig_id);
}
------------------------------------------------------------------------------------------------------------
PigService
package com.khmall.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.khmall.dto.Pig;
import com.khmall.mapper.PigMapper;
@Service
public class PigService {
@Autowired
private PigMapper pigMapper;
public List<Pig> getAllPigs(){
return pigMapper.getAllPigs();
}
public Pig getPigById(int pig_id) {
return pigMapper.getPigById(pig_id);
}
}
'JSP+Spring Boot' 카테고리의 다른 글
이미지 파일 업로드하기(insert-image) (0) | 2024.06.21 |
---|---|
이미지 파일 불러오기(select-image)(resourses) (0) | 2024.06.20 |
과자와 회사 정보 모두 가져오기 + 과자 하나 상세보기(join) (java) (0) | 2024.06.20 |
과자와 회사 정보 모두 가져오기 + 과자 하나 상세보기(join) (resources) (0) | 2024.06.20 |
DB 테이블에 있는 값 불러오기(select) (0) | 2024.06.20 |