menambah menu stok

Menu stok akan coba kita tambahkan guys😀

Bismillah

Melanjutkan tulisan sebelumnya :
https://saifiahmada.wordpress.com/2014/12/13/membuat-modal-bootstrap-untuk-form-simpan/

1. buat bean entity Stok

2. buat interface StokRepository

3. buat class StokService

4. buat class StokController

5. buat file stoklist.jsp pada /WEB-INF/jsp/stoklist.jsp

6. tambahkan definition untuk stok pada general.xml

7. tambahkan menu stok pada classic.jsp

8. Insert data stok secara manual

9. testing hasil

q> – – – mulai – – –

1. buat bean entity Stok


package com.saifiahmada.maven.entity;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;

@Entity
public class Stok {

@Id
private Integer id;

private Integer jumlah;

@OneToOne
@JoinColumn(name="id", referencedColumnName="id")
private Barang barang;

public Integer getId() {
return id;
}

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

public Integer getJumlah() {
return jumlah;
}

public void setJumlah(Integer jumlah) {
this.jumlah = jumlah;
}

public Barang getBarang() {
return barang;
}

public void setBarang(Barang barang) {
this.barang = barang;
}

}

2. buat interface StokRepository


package com.saifiahmada.maven.repository;

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

import com.saifiahmada.maven.entity.Stok;

public interface StokRepository extends JpaRepository<Stok, Integer> {

}

3. buat class StokService


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.Stok;
import com.saifiahmada.maven.repository.StokRepository;

@Service
public class StokService {

@Autowired
private StokRepository stokRepository;

public void save(Stok stok){
stokRepository.save(stok);
}

public List<Stok> findAll(){
return stokRepository.findAll();
}

}

4. buat class StokController


package com.saifiahmada.maven.controller;

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.service.StokService;

@Controller
public class StokController {

@Autowired
private StokService stokService;

@RequestMapping("/stok/list")
public String list(Model model){
model.addAttribute("stoks", stokService.findAll());
return "stok";
}

}

5. buat file stoklist.jsp pada /WEB-INF/jsp/stoklist.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>Barang</td>
<td>Stok</td>
</tr>
</thead>
<tbody>
<c:forEach items="${stoks}" var="stok">
<tr>
<td>${stok.barang.kode}</td>
<td>${stok.barang.nama}</td>
<td>${stok.jumlah}</td>
</tr>
</c:forEach>
</tbody>

</table>

6. tambahkan definition untuk stok pada general.xml

<definition name="stok" extends="common">
<put-attribute name="title" value="Stok" />
<put-attribute name="body" value="/WEB-INF/jsp/stoklist.jsp" />
<put-attribute name="current" value="stok" />
</definition>

7. tambahkan menu stok pada classic.jsp

<li class="${current == 'stok' ? 'active' : '' }"><a
href="/stok/list.html">Stok</a></li>

8. Insert data stok secara manual

Selection_627

9. testing hasil

Selection_628

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