This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.springbook.model; | |
import org.hibernate.validator.constraints.NotBlank; | |
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | |
import org.springframework.data.annotation.CreatedDate; | |
import org.springframework.data.annotation.LastModifiedDate; | |
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | |
import javax.persistence.*; | |
import java.io.Serializable; | |
import java.util.Date; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.springbook; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | |
@SpringBootApplication | |
@EnableJpaAuditing | |
public class SpringBookApplication { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.springbook.repository; | |
import java.util.List; | |
import org.springframework.data.jpa.repository.JpaRepository; | |
import org.springframework.data.jpa.repository.Query; | |
import org.springframework.stereotype.Repository; | |
import com.example.springbook.model.Buku; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.springbook.controller; | |
import java.util.List; | |
import javax.validation.Valid; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.http.ResponseEntity; | |
import org.springframework.web.bind.annotation.DeleteMapping; | |
import org.springframework.web.bind.annotation.GetMapping; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RestMapper implements RowMapper<Rest>{ | |
@Override | |
public Rest mapRow(ResultSet rs, int rowNum) throws SQLException { | |
Rest rest = new Rest(); | |
rest.setId(rs.getInt("id")); | |
rest.setKey(rs.getString("key")); | |
rest.setValue(rs.getString("value")); | |
RestResult restResult = new RestResult(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Transactional | |
@Repository | |
public class RestDaoImp implements RestDao{ | |
@Autowired | |
private JdbcTemplate jdbcTemplate; | |
@Override | |
public List<RestResult> getAll() { | |
String sql = "select * from rest order by id asc"; | |
List<RestResult> rest = jdbcTemplate.query(sql, new RestMapper()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
public class RestServiceImp implements RestService{ | |
@Autowired | |
private RestDao restDao; | |
@Override | |
public List<RestResult> getAll() { | |
return restDao.getAll(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
@RequestMapping("rest") | |
public class RestController { | |
@Autowired | |
RestService restService; | |
@GetMapping("/{id}") | |
public ResponseEntity<RestResult> getById(@PathVariable("id") int id){ | |
RestResult rest = restService.getRestById(id); | |
return new ResponseEntity<RestResult>(rest, HttpStatus.OK); |