Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zesp03.webapp.page;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.ModelMap;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import zesp03.common.core.Database;
- import zesp03.common.entity.Building;
- import zesp03.common.entity.Unit;
- import zesp03.webapp.dto.BuildingDto;
- import zesp03.webapp.dto.UnitBuildingsDto;
- import zesp03.webapp.dto.UnitDto;
- import javax.persistence.EntityManager;
- import javax.persistence.EntityTransaction;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * Created by Media on 2017-03-28.
- */
- @Controller
- public class LinkUnitAllBuildingsPage {
- @GetMapping("/link-unit-all-buildings")
- public String get(@RequestParam("id") long id,
- ModelMap model) {
- EntityManager em = null;
- EntityTransaction tran = null;
- try {
- em = Database.createEntityManager();
- tran = em.getTransaction();
- tran.begin();
- Unit u = em.find(Unit.class, id);
- List<Building> b= em.createQuery("SELECT b FROM Building b", Building.class).getResultList();
- model.put("unit", u);
- model.put("buildings",b);
- tran.commit();
- } catch (RuntimeException exc) {
- if( tran != null && tran.isActive() )
- tran.rollback();
- throw exc;
- } finally {
- if (em != null)
- em.close();
- }
- return "link-unit-all-buildings";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement