change
http://localhost:8080/mobileWAO/
http://localhost:8080/
-------------------------------------------------
package jp.co.chepro.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class LoginController {
@RequestMapping(value="/", method=RequestMethod.GET)
public String index() {
return "login";
}
@RequestMapping("/loginError")
public String loginError(Model model) {
model.addAttribute("loginError", true);
return "login";
}
}
-------------------------------------------------
login.html
<div class="row" th:if="${loginError}">
<div class="col-xs-12 col-sm-12">
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="閉じる"><span aria-hidden="true">×</span></button>
<span>ユーザー名、パスワードのいずれかが有効ではありません。</span>
</div>
</div>
</div>
<form method="post" action="top.html" th:action="@{/login}">
<input type="text" name="userId" id="userId" placeholder="ユーザー名を入力" class="form-control input-lg" />
<input type="password" name="password" id="password" placeholder="パスワードを入力" class="form-control input-lg"/>
<input class="btn btn-default" type="submit" value="ログイン" />
-------------------------------------------------
public class SpringWebSecurityConfig extends WebSecurityConfigurerAdapter {
http.formLogin()
.loginPage("/")
.loginProcessingUrl("/login")
.defaultSuccessUrl("/top",true)
.failureUrl("/loginError")
.usernameParameter("userId")
.passwordParameter("password")
-------------------------------------------------
package jp.co.chepro.controller;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import jp.co.chepro.dto.UserDto;
@Controller
public class TopController {
@RequestMapping(value="/top", method=RequestMethod.GET)
public String top(Model model){
UserDto userDto = (UserDto)SecurityContextHolder.getContext().
getAuthentication().getPrincipal();
model.addAttribute("userDto", userDto);
return "top";
}
}
-------------------------------------------------
http://localhost:8080/mobileWAO/top
http://localhost:8080/top
top.html
<form name="searchForm" action="projectList.html" th:action="@{/projectSearch}" method="get">
-------------------------------------------------
package jp.co.chepro.controller;
import static jp.co.chepro.form.ProjectSearchForm.*;
import static jp.co.chepro.service.BusinessManagementService.*;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import jp.co.chepro.dto.PersonInChargeDto;
import jp.co.chepro.dto.ProjectSearchResult;
import jp.co.chepro.dto.ProjectStastics;
import jp.co.chepro.dto.SecDto;
import jp.co.chepro.form.ProjectSearchForm;
import jp.co.chepro.service.BusinessManagementService;
import jp.co.chepro.util.Pagination;
@Controller
public class BusinessManagementController {
@Autowired
private BusinessManagementService service;
/**
* プロジェクト検索実行
*/
@RequestMapping(value="/projectSearch", method=RequestMethod.GET)
public String projectSearch(@Valid @ModelAttribute ProjectSearchForm form, BindingResult errors, Model model, HttpSession session){
if (errors.hasErrors() ) {
return "projectDetailSearchCondition";
}
//ページング情報
Integer count = service.countProjects(form);
Pagination pagination = new Pagination(form.getPage(), PROJECT_NUM_PER_PAGE, count);
//集計情報
Map<ProjectStastics, List<ProjectStastics>> statistics = conv(service.summarizeByCurprctyp(form));
//プロジェクト一覧
List<ProjectSearchResult> projects = service.searchProjects(form);
session.setAttribute(SESSION_KEY, form);
model.addAttribute("projects", projects);
model.addAttribute("statistics", statistics);
model.addAttribute("pagination", pagination);
return "projectList";
}
-------------------------------------------------
package jp.co.chepro.service;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import jp.co.chepro.dto.PersonInChargeDto;
import jp.co.chepro.dto.ProjectDetail;
import jp.co.chepro.dto.ProjectEnvironment;
import jp.co.chepro.dto.ProjectSearchResult;
import jp.co.chepro.dto.ProjectStastics;
import jp.co.chepro.dto.SecDto;
import jp.co.chepro.dto.UserDto;
import jp.co.chepro.form.ProjectSearchForm;
import jp.co.chepro.util.Query;
@Service
public class BusinessManagementService {
/**
* jdbcテンプレート
*/
@Autowired
private NamedParameterJdbcTemplate jdbcTemplate;
/**
* プロジェクト検索
* @param form プロジェクト検索Form
* @return 検索結果リスト
*/
public List<ProjectSearchResult> searchProjects(ProjectSearchForm form) {
Query query = getProjectSearchQuery(form);
List<ProjectSearchResult> projects = this.jdbcTemplate.query(
query.getSql(), query.getParams(), new RowMapper<ProjectSearchResult>() {
@Override
public ProjectSearchResult mapRow(ResultSet rs, int rowNum) throws SQLException {
ProjectSearchResult dto = new ProjectSearchResult();
dto.setPrjno(rs.getString("prjno"));
dto.setPrjname(rs.getString("prjname"));
dto.setPrjdate(rs.getString("prjdate"));
dto.setCusname(rs.getString("cusname"));
dto.setGpcode(rs.getString("GPCODE"));
dto.setWatasidate(rs.getString("WATASIDATE"));
dto.setAnkno(rs.getString("ankno"));
dto.setAnkname(rs.getString("ankname"));
dto.setAnkdate(rs.getString("ankdate"));
dto.setCurprctyp(rs.getString("curprctyp"));
dto.setOdrgpex(rs.getString("OdrGPEx"));
dto.setAnkst(rs.getString("ANKST"));
dto.setOdrno(rs.getString("ODRNO"));
dto.setOdrdate(rs.getString("ODRDATE"));
dto.setUridate(rs.getString("URIDATE"));
dto.setUpddt(rs.getString("UPDDT"));
dto.setGpname(rs.getString("gpname"));
dto.setPrcnm(rs.getString("prcnm"));
dto.setAnkstnm(rs.getString("ankstnm"));
dto.setOdramtex(rs.getString("ODRAMTEX"));
dto.setOdrkind(rs.getString("odrkind"));
dto.setElccnstrctkind(rs.getString("elccnstrctkind"));
dto.setConstkindcd(rs.getString("constkindcd"));
dto.setBmncd(rs.getString("bmncd"));
dto.setOdrrate(rs.getString("ODRRATE"));
dto.setCltcode(rs.getString("cltcode"));
dto.setPcode(rs.getString("pcode"));
dto.setPname(rs.getString("pname"));
dto.setCpcode(rs.getString("CPCODE"));
dto.setCpname(rs.getString("CPNAME"));
dto.setEstno(rs.getString("estno"));
dto.setOdrraterank(rs.getString("OdrRateRank"));
return dto;
}
});
return projects;
}
-------------------------------------------------