bootstrap table

Lanjutkan gan

Bismillah

Melanjutkan tulisan ini :
https://saifiahmada.wordpress.com/2014/12/11/bootstrap-dan-spring-mvc/

Langkah2 yang akan dipraktekkan :

1. buat bean entity barang

2. buat interface BarangRepository

3. buat class BarangService

4. edit file classic.jsp menu About –menjadi-> Barang

5. edit file general.xml, tambahkan

6. buat file baranglist.jsp

7. buat class BarangController

8. jalankan jetty

q> – – – mulai – – –

1. buat bean entity barang


package com.saifiahmada.maven.entity;

import java.math.BigDecimal;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class Barang {

@Id
@GeneratedValue
private Integer id;

private String kode;

private String nama;

private BigDecimal harga;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getKode() {
return kode;
}

public void setKode(String kode) {
this.kode = kode;
}

public String getNama() {
return nama;
}

public void setNama(String nama) {
this.nama = nama;
}

public BigDecimal getHarga() {
return harga;
}

public void setHarga(BigDecimal harga) {
this.harga = harga;
}

}

2. buat interface BarangRepository


package com.saifiahmada.maven.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.saifiahmada.maven.entity.Barang;

public interface BarangRepository extends JpaRepository<Barang, Integer> {

}

3. buat class BarangService


package com.saifiahmada.maven.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.saifiahmada.maven.entity.Barang;
import com.saifiahmada.maven.repository.BarangRepository;

@Service
public class BarangService {

@Autowired
private BarangRepository barangRepository;

public void save(Barang barang){
barangRepository.save(barang);
}

public List<Barang> findAll() {
return barangRepository.findAll();
}

}

4. edit file classic.jsp menu About –menjadi->  Barang

<ul class="nav navbar-nav">
<li class="active"><a href="<spring:url value="/" />">Home</a></li>
<li><a href="<spring:url value="/barang/list.html" />">Barang</a></li>
<li><a href="#">Contact</a></li>
</ul>

5. edit file general.xml, tambahkan

<definition name="baranglist" extends="common">
<put-attribute name="title" value="Barang" />
<put-attribute name="body" value="/WEB-INF/jsp/baranglist.jsp" />
</definition>

6. buat file baranglist.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>

<%@ include file="../layout/taglib.jsp"%>

<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<td>Kode</td>
<td>Nama Barang</td>
<td>Harga</td>
</tr>
</thead>
<tbody>
<c:forEach items="${barangs}" var="barang">
<tr>
<td>${barang.kode}</td>
<td>${barang.nama}</td>
<td>${barang.harga}</td>
</tr>
</c:forEach>
</tbody>
</table>

7. buat class BarangController


package com.saifiahmada.maven.controller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.saifiahmada.maven.entity.Barang;
import com.saifiahmada.maven.service.BarangService;

@Controller
public class BarangController {

@Autowired
private BarangService barangService;

@RequestMapping("/barang/list")
public String barangList(Model model){
model.addAttribute("barangs", barangService.findAll());
return "baranglist";
}

}

8. jalankan jetty

buka browser dan klik menu barang, hasilnya :

Selection_620

 

Alhamdulillah

Published by

saifiahmada

Begin a big Process with a bit trying

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s