You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.3 KiB
Java

package com.xit.biz.sample.controller;
import com.xit.core.util.PoiExcelView;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.View;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
@Controller
@RequestMapping("/web/sample")
public class WebSampleController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@GetMapping("/sample-dark")
public String sampleDarkMode() {
return "thymeleaf/sample/sample-dark";
}
@GetMapping("/sample-admin")
public String sampleAdminMode() {
return "thymeleaf/sample/sample-admin";
}
@GetMapping("/greeting")
public String greeting(@RequestParam(value = "name", required = false, defaultValue = "World") String name,
Model model) {
model.addAttribute("name", String.format(template, name));
return "thymeleaf/sample/greeting";
}
@GetMapping("/jsp")
public String jspTest(@RequestParam(value = "name", required = false, defaultValue = "World") String name,
Model model) {
model.addAttribute("name", String.format(template, name));
return "Test";
}
@GetMapping("/exceltest")
public String exceltest() {
return "thymeleaf/sample/exceldown";
}
@PostMapping(value = "/exceldown")//, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public View excelDownTest(ModelMap modelMap) {
List<String> titleList = Arrays.asList( "아이디", "이름", "생년월일", "핸드폰번호", "전화", "이메일");
List<String> fieldList = Arrays.asList( "ID", "MBR_NM", "BRTHDY", "HP_NO", "TEL_NO", "EMAIL");
modelMap.addAttribute("titleList", titleList);
modelMap.addAttribute("fieldList", fieldList);
List<Map<String, Object>> listRes = new ArrayList<>();
Map<String, Object> map = new HashMap<>();
map.put("MBR_NM", "fsafas");
map.put("BRTHDY", "12341212");
map.put("HP_NO", "01011112222");
map.put("TEL_NO", "0311231234");
map.put("EMAIL", "a@b.com");
for(int i=0; i<10; i++) {
map.put("ID", i);
listRes.add(map);
}
modelMap.addAttribute("contentList", listRes);
return new PoiExcelView("exceltest.xlsx");
//modelMap.addAttribute("titleList", paramMap.get("titleList"));
//modelMap.addAttribute("fieldList", paramMap.get("fieldList"));
//return new PoiExcelView(paramMap.get("fileName").toString());
}
// @GetMapping("/greeting2")
// public Mono<Greeting> greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
// return new Greeting(counter.incrementAndGet(), String.format(template, name));
// }
//
// @GetMapping("/getGreetings")
// public Flux<Greeting> getAllMargins() {
// return null;//marginRepository.findAll();
// }
}