У меня нет ошибок журнала, просто не сохраняйте. Настройки моей базы данных указаны правильно в свойствах моего приложения, и я запускаю SQL Server на правильном порту в podman.
Вот мои классы:
Мой репозиторий:
Код: Выделить всё
package com.bonbap.mycrudproject;
import com.bonbap.mycrudproject.model.Cliente;
import org.springframework.data.jpa.repository.JpaRepository;;
import org.springframework.stereotype.Repository;
@Repository
public interface ClienteRepository extends JpaRepository {
}
Код: Выделить всё
package com.bonbap.mycrudproject.model;
import jakarta.persistence.*;
import lombok.Data;
@Entity
@Data
@Table(name = "t1209Clt")
public class Cliente {
@Id
@Column(name = "id_clt", nullable = false)
private String id;
@Column(name = "nm_clt", nullable = false)
private String nome;
@Column(name = "num_clt", nullable = false)
private String cpf;
@Column(name = "nm_tel", nullable = false)
private String telefone;
Код: Выделить всё
@Log4j2
@Service
@Transactional
public class ClienteService extends DefaultService implements CrudService {
private final ClienteRepository repository;
private final ClienteMapper mapper;
public ClienteService(ClienteRepository repository, ClienteMapper mapper) {
this.repository = repository;
this.mapper = mapper;
}
@Override
public boolean incluirCliente(IncluirClienteRequestDTO request) {
log.info("Incluindo cliente na base de dados...");
log.trace("Incluir cliente: {}", request);
salvarCliente(request);
return true;
}
private Cliente salvarCliente(IncluirClienteRequestDTO request) {
Cliente cliente = mapper.requestToModel(request);
return repository.save(cliente);
}
public IncluirClienteRequestDTO buscarClientePorId() {
log.info("Buscando cliente por id");
log.trace("Buscar cliente por id: {}", id);
List cliente = repository.findAll();
if (cliente == null) {
throw new ClienteNaoEncontradoException("Cliente não cadastrado.");
}
return mapper.modelToRequest(null);
}
}
Код: Выделить всё
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
org.springframework.boot
spring-boot-starter-parent
3.3.0
lombok
${lombok.version}
org.mapstruct
mapstruct-processor
1.6.0
-Amapstruct.defaultComponentModel=spring
Код: Выделить всё
spring:
application:
name: MyCrudProject
datasource:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://localhost:1460;databaseName=bon_dsv;sendStringParametersAsUnicode=false
username: sa
password: Passw0rd
jpa:
show-sql: true
properties:
hibernate:
format_sql: true
defer-datasource-initialization: true
Подробнее здесь: https://stackoverflow.com/questions/790 ... logs-error
Мобильная версия