一切都很好吗?
我正在编辑表单。
EL1008E:在类型'java.util.Optional“
的对象中找不到属性或字段'city'我可以在银行中保存,州和城市可以正确显示,但是当我要求编辑时,会出现此错误。有人可以帮我吗?
仅对城市选择组合显示错误
@RequestMapping(value = "/editar/{id}")
public String editar(@PathVariable(value = "id") Long id, Map<String, Object> model) {
Optional<Paciente> paciente = null;
if (id > 0) {
paciente = pacienteService.getOne(id);
System.out.println(paciente);
} else {
return " redirect:/listar";
}
model.put("paciente", paciente);
model.put("titulo", "Cadastrar paciente");
return "paginas/form";
}
我的表单编辑
<section id="basic-form-layouts">
<div class="row match-height justify-content-md-center">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h4 class="card-title" id="basic-layout-icons" th:text="${titulo}"></h4>
<a class="heading-elements-toggle"><i class="fa fa-ellipsis-v font-medium-3"></i></a>
<div class="heading-elements">
<ul class="list-inline mb-0">
<li><a data-action="collapse"><i class="ft-minus"></i></a></li>
<li><a data-action="expand"><i class="ft-maximize"></i></a></li>
<li><a data-action="close"><i class="ft-x"></i></a></li>
</ul>
</div>
</div>
<div class="card-content collapse show">
<div class="card-body">
<form class="form" method="post" th:action="@{/pacientes/salvar}"
th:object="${paciente}">
<div class="form-body">
<div class="row">
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="nome">Nome<i class="fa fa-asterisk pink"></i></span></label>
<div class="position-relative has-icon-left">
<input class="form-control" id="nome" name="nome"
placeholder="Nome do paciente"
th:field="*{nome}" type="text">
<div class="form-control-position">
<i class="ft-user"></i>
</div>
<p class="text-danger mt-1" th:errors="*{nome}"
th:if="${#fields.hasErrors('nome')}"></p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="dataNasc">Data de Nascimento<i class="fa fa-asterisk pink"></i></span></label>
<div class="position-relative has-icon-left">
<input class="form-control" id="dataNasc" name="dataNasc"
th:field="*{dataNasc}" type="date">
<div class="form-control-position">
<i class="fa fa-calendar"></i>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<label for="sexo">Sexo<i class="fa fa-asterisk pink"></i></span></label>
<select class="select2 form-control" id="sexo" name="sexo"
th:field="*{sexoId}">
<option th:each="sexo:${listaSexo}"
th:text="${sexo.descricao}"
th:value="${sexo.id}">
</option>
</select>
</div>
</div>
<div class="row">
<div class="col-md-4">
<label for="racaId">Raça<i class="fa fa-asterisk pink"></i></span></label>
<select class="select2 form-control" id="racaId" name="racaId"
th:field="*{racaId}">
<option th:each="raca:${listaRaca}"
th:text="${raca.descricao}"
th:value="${raca.getId()}">
</option>
</select>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="cns">Cartão Sus<i class="fa fa-asterisk pink"></i></span></label>
<div class="position-relative has-icon-left">
<input class="form-control" id="cns" name="cns"
placeholder="Cartão sus"
th:field="*{cns}" type="text">
<div class="form-control-position">
<i class="fa fa-id-card-o"></i>
</div>
<p class="text-danger mt-1" th:errors="*{cns}"
th:if="${#fields.hasErrors('cns')}"></p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="cpf">Cpf</label>
<div class="position-relative has-icon-left">
<input class="form-control" id="cpf" name="cpf"
placeholder="Cpf"
th:field="*{cpf}" type="text">
<div class="form-control-position">
<i class="fa fa-id-card-o"></i>
</div>
<p class="text-danger mt-1" th:errors="*{cpf}"
th:if="${#fields.hasErrors('cpf')}"></p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="cns">Rg<i class="fa fa-asterisk pink"></i></span></label>
<div class="position-relative has-icon-left">
<input class="form-control" id="rg" name="rg"
placeholder="Rg"
th:field="*{rg}" type="text">
<div class="form-control-position">
<i class="fa fa-id-card-o"></i>
</div>
<p class="text-danger mt-1" th:errors="*{rg}"
th:if="${#fields.hasErrors('rg')}"></p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="orgaoEmissor">Orgão emissor<i class="fa fa-asterisk pink"></i></span></label>
<div class="position-relative has-icon-left">
<input class="form-control" id="orgaoEmissor"
name="orgaoEmissor" placeholder="Órgão emissor"
th:field="*{orgaoEmissor}" type="text">
<div class="form-control-position">
<i class="fa fa-id-card-o"></i>
</div>
<p class="text-danger mt-1" th:errors="*{orgaoEmissor}"
th:if="${#fields.hasErrors('orgaoEmissor')}"></p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="dataEmissao">Data de emissão<i class="fa fa-asterisk pink"></i></span></label>
<div class="position-relative has-icon-left">
<input class="form-control" id="dataEmissao"
name="dataEmissao" th:field="*{dataEmissao}"
type="date">
<div class="form-control-position">
<i class="fa fa-calendar"></i>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<label for="estado">Estado<i class="fa fa-asterisk pink"></i></span></label>
<select class="form-control" id="estado" name="estado"
th:field="*{estado}">
<option value="">Selecione um estado</option>
<option th:each="estado:${listaEstado}"
th:text="${estado.nome}"
th:value="${estado.id}">
</option>
</select>
<p class="text-danger mt-1" th:errors="*{estado}"
th:if="${#fields.hasErrors('estado')}"></p>
</div>
<div class="col-md-4">
<div class="form-group">
<input type="hidden" id="inputHiddenCidadeSelecionada" th:value="*{cidade != null} ? *{cidade.id} : 'cidade is null'"/>
<label for="cidade">Cidade</label>
<select class="form-control" data:url="@{/cidades}" id="cidade"name="cidade" th:field ="*{cidade}" >
</select>
</div>
<p class="text-danger mt-1" th:errors="*{cidade}"
th:if="${#fields.hasErrors('cidade')}"></p>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="bairroId">Bairro</label>
<select class="select2 form-control" id="bairroId" name="bairroId" th:field="*{bairroId}">
<option th:each="bairro:${listaBairro}"
th:text="${bairro.nome}"
th:value="${bairro.id}">
</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="logradouroId">Logradouro<i class="fa fa-asterisk pink"></i></span></label>
<select class="select2 form-control" id="logradouroId" name="logradouroId" th:field="*{logradouroId}">
<option th:each="logradouro:${listaLogradouro}"
th:text="${logradouro.nome}"
th:value="${logradouro.getId()}">
</option>
</select>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="nomePai">Endereço</label>
<div class="position-relative has-icon-left">
<input class="form-control" id="endereco" name="endereco"
placeholder="Endereço"
th:field="*{endereco}" type="text">
<div class="form-control-position">
<i class="fa fa-map-marker"></i>
</div>
<p class="text-danger mt-1" th:errors="*{endereco}"
th:if="${#fields.hasErrors('endereco')}"></p>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="nomeMae">Número</label>
<div class="position-relative has-icon-left">
<input class="form-control" id="numero" name="numero"
placeholder="Número"
th:field="*{numero}" type="text">
<div class="form-control-position">
<i class="fa fa-map-marker"></i>
</div>
<p class="text-danger mt-1" th:errors="*{numero}"
th:if="${#fields.hasErrors('numero')}"></p>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="nomeMae">Complemento</label>
<div class="position-relative has-icon-left">
<input class="form-control" id="complemento" name="complemento"
placeholder="Complemento"
th:field="*{complemento}" type="text">
<div class="form-control-position">
<i class="fa fa-map-marker"></i>
</div>
<p class="text-danger mt-1" th:errors="*{complemento}"
th:if="${#fields.hasErrors('complemento')}"></p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="nomePai">Pai</label>
<div class="position-relative has-icon-left">
<input class="form-control" id="nomePai" name="nomePai"
placeholder="Nome do pai"
th:field="*{nomePai}" type="text">
<div class="form-control-position">
<i class="ft-user"></i>
</div>
<p class="text-danger mt-1" th:errors="*{nomePai}"
th:if="${#fields.hasErrors('nomePai')}"></p>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="nomeMae">Mãe</label>
<div class="position-relative has-icon-left">
<input class="form-control" id="nomeMae" name="nomeMae"
placeholder="Nome da mãe"
th:field="*{nomeMae}" type="text">
<div class="form-control-position">
<i class="ft-user"></i>
</div>
<p class="text-danger mt-1" th:errors="*{nomeMae}"
th:if="${#fields.hasErrors('nomeMae')}"></p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="telefone">Telefone</label>
<div class="position-relative has-icon-left">
<input class="form-control" id="telefone" name="telefone"
placeholder="Telefone"
th:field="*{telefone}" type="text">
<div class="form-control-position">
<i class="fa fa-phone"></i>
</div>
<p class="text-danger mt-1" th:errors="*{telefone}"
th:if="${#fields.hasErrors('telefone')}"></p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="celular">Celular</label>
<div class="position-relative has-icon-left">
<input class="form-control" id="celular" name="celular"
placeholder="Celular"
th:field="*{celular}" type="text">
<div class="form-control-position">
<i class="fa fa-mobile"></i>
<p class="text-danger mt-1" th:errors="*{celular}"
th:if="${#fields.hasErrors('celular')}"></p>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="email">E-mail</label>
<div class="position-relative has-icon-left">
<input class="form-control" id="email" name="email"
placeholder="E-mail"
th:field="*{email}" type="text">
<div class="form-control-position">
<i class="fa fa-envelope-o"></i>
</div>
<p class="text-danger mt-1" th:errors="*{email}"
th:if="${#fields.hasErrors('email')}"></p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="procedimentos">Procedimentos</label>
<select class="select2 form-control"
data-placeholder="Pesquisar procedimentos"
id="procedimentos" multiple="multiple"
name="procedimentos" th:field="*{procedimentos}">
<option th:each="procedimento:${listaProcedimento}"
th:text="${procedimento.descricao}"
th:value="${procedimento.getId()}">
</option>
</select>
<p class="text-danger mt-1" th:errors="*{procedimentos}"
th:if="${#fields.hasErrors('procedimentos')}"></p>
</div>
<input th:field="*{id}" type="hidden">
</div>
</div>
</div>
<!-- FIM DO FORM BODY -->
<div class="form-actions right">
<button class="btn btn-outline-red mr-1" type="reset">
<i class="ft-x"></i> Limpar
</button>
<button class="btn btn-outline-blue" type="submit">
<i class="fa fa-check-square-o"></i> Salvar
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</section>