春天的Hibernate价值并没有落后

时间:2016-05-26 09:00:06

标签: spring hibernate

大家好我想创建一个页面,它与客户端和放电之间有关系。我已经定义了一个组合框,它填充了客户端表单模型的数据,我想要在Discharge表中的客户端ID,但是如果你在前端检查它看起来不错但在后端它的null,那么我不会在后端获得价值所以请帮助我来解决这个问题。

这里是代码,

DischargeCard.java

@Entity
@Table(name = "Discharge_card")

public class DischargeCard {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private int DischargeId;

@ManyToOne(cascade = {CascadeType.ALL})
@JoinColumn(name = "Client_id")
private Client Client_id;

@Column(name = "IPDNo")
private String ipdno;

@Column(name = "DOA")
private Date DOA;

@Column(name = "DOO")
private Date DOO;

@Column(name = "DOD")
private Date DOD;

@Column(name = "DOB")
private Date DOB;

@Column(name = "Age")
private int age;

@Column(name = "Sex")
private String sex;

@Column(name = "Phone")
private String phone;

@Column(name = "Address")
private String Address;

@Column(name = "Diagnosis")
private String diagnosis;

@Column(name = "Treatment")
private String treatment;

@Column(name = "Anesthesia")
private String anesthesia;

@Column(name = "Clinical_Presentation")
private String clinical_presentation;

@Column(name = "Investigation")
private String investigation;

@Column(name = "Given_Treatment")
private String given_treatment;

@Column(name = "Advice_on_Discharge")
private String advice;

< generates setter / getter >

Client.java

@Entity
@Table(name = "CLIENT")
public class Client {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID")
    int clientId;

    @NotEmpty(message = "Please Enter Client Name..." )
    @Column(name = "Name")
    String clientName;


    @Column(name = "ContactName")
    String contactName;

    @NotEmpty(message = " Please Enter Client Address...")
    @Column(name = "Address")
    String clientAddress;

    @NotEmpty(message = "Please Enter Client Phone...")
    @Size (min = 10)
    @Pattern (regexp = "[0-9]*")
    @Column(name = "Phone")
    String phone;

    @Email (message = "Please Enter Proper Email Address of Client...")
    @Column(name = "Email")
    String email;

    @NotEmpty (message = "Please Enter Client City...")
    @Column(name = "City")
    String city;

    @NotEmpty (message = "Please Enter Client Zip Code...")
    @Size (min = 6)
    @Pattern (regexp = "[0-9]*")
    @Column(name = "Zip")
    String zip;

    @NotEmpty(message = "Please Enter Client State...")
    @Column(name = "State")
    String state;

    @NotEmpty (message = "Please Enter Client Country...")
    @Column(name = "Country")
    String country;


    @Column(name = "Private")
    String privateNote;


    @Column(name = "Other")
    String otherNote;

    @ManyToOne
    @JoinColumn(name = "Company_id")
    private Company company;
    @OneToMany(mappedBy = "Client_id")
    private Set<Invoice> invoice;
    @OneToMany(mappedBy = "Client_ID")
    private Set<Estimate> estimate;

    @OneToMany(mappedBy = "Client_id")
    private Set<DischargeCard> discharges;

    < generated setter / getter >

DischargeCardController.java

@Controller
public class DischargeCardController {
    @Autowired
    DischargeCardService ds;
    @Autowired
    ClientService service;


    @RequestMapping(value = "/dishcharge", method = RequestMethod.GET)
    public String showClientDetailsPage(Model m, HttpServletRequest req) {
        m.addAttribute("dischargecard", new DischargeCard());
        m.addAttribute("actionURL", "saveCard");
        List<Client> obj = service.getAll("");
        m.addAttribute("clientList", obj);

         List<String> clientlist = new ArrayList<>();
         for(Client c : obj)
         {
             clientlist.add(c.getClientName().toString());
         }
        m.addAttribute("client_name_list",clientlist);
        return "dischargeCard";
    }

    @RequestMapping(value = "/saveCard", method = RequestMethod.POST)
    public String saveCompanyDetails(@ModelAttribute("DischargeCard")DischargeCard dc, BindingResult result,
            HttpServletRequest req) {
        String redirectTo = "";
        /*if(result.hasErrors())
        {
            redirectTo = "dischargeCard";
            return redirectTo;
        }
        else
        {*/
        ds.saveData(dc);
        redirectTo = "redirect:dishcharge";
        return redirectTo;

    }

    @RequestMapping(value = "/searchDischargeCard", method = RequestMethod.GET)
    public ModelAndView showUsersPage() {
        ModelAndView mv = new ModelAndView("searchDischargeCard");
        List<Client> obj = service.getAll("");
        mv.addObject("clientList", obj);

         List<String> clientlist = new ArrayList<>();
         for(Client c : obj)
         {
             clientlist.add(c.getClientName().toString());
         }
        mv.addObject("client_name_list",clientlist);
        mv.addObject("DischargeList",ds.getAll(""));
        return mv;
    }

}

DischargeCard.jsp

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

<jsp:include page="header.jsp"></jsp:include>
<jsp:include page="menu.jsp"></jsp:include>

<!-- BEGIN Content -->
<div id="main-content">
    <!-- BEGIN Page Title -->
    <div class="page-title">
        <div>
            <h1>
                <i class="fa fa-file-o"></i> Add Dishcharge Card
            </h1>
            <h4>Add data of new Discharge Card</h4>
        </div>
    </div>
    <!-- END Page Title -->

    <!-- BEGIN Breadcrumb -->
    <div id="breadcrumbs">
        <ul class="breadcrumb">
            <li><i class="fa fa-home"></i> <a href="index.html">Home</a> <span
                class="divider"><i class="fa fa-angle-right"></i></span></li>
            <li class="active">Discharge</li>
        </ul>
    </div>
    <!-- END Breadcrumb -->
    <div class="row">
        <div class="col-md-12">
            <div class="box box-pink">
                <div class="box-title">
                    <h3>
                        <i class="fa fa-bars"></i> Discharge Card
                    </h3>
                    <div class="box-tool">
                        <a data-action="collapse" href="#"><i class="fa fa-chevron-up"></i></a>
                        <a data-action="close" href="#"><i class="fa fa-times"></i></a>
                    </div>
                </div>
                <div class="box-content">
                    <%-- <form action="#" > --%>
                    <form:form action="${actionURL}" class="form-horizontal"
                        id="wizard-validation" method="post"
                        modelAttribute="dischargecard">
                        <form:hidden path="DischargeId" id="DischargeId" />
                        <div class="form-wizard" id="form-wizard-2">
                            <ul class="row steps steps-fill">
                                <li class="col-xs-12 col-sm-6 col-lg-3"><a href="#tab2-1"
                                    data-toggle="tab" class="step active"> <span class="number">1</span>
                                        <span class="desc"><i class="fa fa-check"></i> Client
                                            Details</span>
                                </a></li>
                                <li class="col-xs-12 col-sm-6 col-lg-3"><a href="#tab2-2"
                                    data-toggle="tab" class="step"> <span class="number">2</span>
                                        <span class="desc"><i class="fa fa-check"></i>
                                            Treatment Details</span>
                                </a></li>
                                <li class="col-xs-12 col-sm-6 col-lg-3"><a href="#tab2-3"
                                    data-toggle="tab" class="step"> <span class="number">3</span>
                                        <span class="desc"><i class="fa fa-check"></i> Photo's</span>
                                </a></li>
                                <li class="col-xs-12 col-sm-6 col-lg-3"><a href="#tab2-4"
                                    data-toggle="tab" class="step"> <span class="number">4</span>
                                        <span class="desc"><i class="fa fa-check"></i> Confirm</span>
                                </a></li>
                            </ul>
                            <div class="progress progress-striped">
                                <div class="progress-bar progress-bar-primary"></div>
                            </div>
                            <div class="tab-content">
                                <div class="tab-pane active" id="tab2-1">
                                    <div class="form-group">
                                        <label for="firstname2"
                                            class="col-sm-3 col-lg-2 control-label">Client Name</label>
                                        <div class="col-sm-5 col-lg-3 controls">
                                            <!-- <input type="text" name="firstname2" id="firstname2"
                                             class="form-control" data-rule-required="true"> -->
                                            <%-- <form:select path="Client_id"
                                                class="form-control chosen" data-rule-required="true"
                                                style="border-radius: 8px;"
                                                data-placeholder="Choose a client" tabindex="1">
                                                <option value=""></option>
                                                <c:forEach var="client" items="${clientList}">

                                                    <form:option value="${client.clientId}">${client.clientName}</form:option>

                                                </c:forEach>
                                            </form:select> --%>

                                            <form:select path="Client_id" items="${clientList}"
                                                itemValue="clientId" itemLabel="clientName" />

                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="firstname2"
                                            class="col-sm-3 col-lg-2 control-label">IPD Number</label>
                                        <div class="col-sm-5 col-lg-3 controls">
                                            <form:input path="ipdno" name="ipdno" type="text"
                                                class="form-control" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 col-lg-2 control-label">Date of
                                            Admission</label>
                                        <div class="col-sm-5 col-lg-3 controls">
                                            <form:input path="DOA" name="doa"
                                                class="form-control date-picker" id="dp1" size="16"
                                                type="text" value="" />


                                        </div>
                                        <div class="input-group col-sm-5 col-lg-2">
                                            <a class="input-group-addon" href="#"><i
                                                class="fa fa-clock-o"></i></a>
                                            <form:input path="DOA" name="doa"
                                                class="form-control timepicker-default" type="text" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 col-lg-2 control-label">Date of
                                            Operation</label>
                                        <div class="col-sm-5 col-lg-3 controls">
                                            <form:input path="DOO" name="doo"
                                                class="form-control date-picker" id="dp1" size="16"
                                                type="text" value="" />
                                        </div>
                                        <div class="input-group col-sm-5 col-lg-2">
                                            <a class="input-group-addon" href="#"><i
                                                class="fa fa-clock-o"></i></a>
                                            <form:input path="DOO" name="doo"
                                                class="form-control timepicker-default" type="text" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 col-lg-2 control-label">Date of
                                            Discharge</label>
                                        <div class="col-sm-5 col-lg-3 controls">
                                            <form:input path="DOD" name="dod"
                                                class="form-control date-picker" id="dp1" size="16"
                                                type="text" value="" />
                                        </div>
                                        <div class="input-group col-sm-5 col-lg-2">
                                            <a class="input-group-addon" href="#"><i
                                                class="fa fa-clock-o"></i></a>
                                            <form:input path="DOD" name="dod"
                                                class="form-control timepicker-default" type="text" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 col-lg-2 control-label">Date of
                                            Birth</label>
                                        <div class="col-sm-5 col-lg-3 controls">
                                            <form:input path="DOB" name="dob"
                                                class="form-control date-picker" id="dp1" size="16"
                                                type="text" value="" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="lastname2" class="col-sm-3 col-lg-2 control-label">Age</label>
                                        <div class="col-sm-5 col-lg-3 controls">
                                            <form:input path="age" name="Age" type="text" id="lastname2"
                                                class="form-control" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 col-lg-2 control-label">Radio
                                            Buttons</label>
                                        <div class="col-sm-9 col-lg-10 controls">
                                            <label class="radio-inline"> <form:radiobutton
                                                    path="sex" name="optionsRadios2" value="Male" /> Male
                                            </label> <label class="radio-inline"> <form:radiobutton
                                                    path="sex" name="optionsRadios2" value="Female" /> Female
                                            </label>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="firstname2"
                                            class="col-sm-3 col-lg-2 control-label">Phone</label>
                                        <div class="col-sm-5 col-lg-3 controls">
                                            <form:input path="phone" name="Phone" type="text"
                                                class="form-control" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 col-lg-2 control-label">Address</label>
                                        <div class="col-sm-5 col-lg-5 controls">
                                            <form:textarea path="Address" name="address"
                                                class="form-control" rows="4"></form:textarea>
                                        </div>
                                    </div>
                                </div>
                                <div class="tab-pane" id="tab2-2">
                                    <div class="form-group">
                                        <label class="col-sm-3 col-lg-2 control-label">Diagnosis</label>
                                        <div class="col-sm-5 col-lg-5 controls">
                                            <form:textarea path="diagnosis" name="Diagnosis"
                                                class="form-control" rows="4"></form:textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 col-lg-2 control-label">Treatment</label>
                                        <div class="col-sm-5 col-lg-5 controls">
                                            <form:textarea path="treatment" name="Treatment"
                                                class="form-control" rows="4"></form:textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="firstname2"
                                            class="col-sm-3 col-lg-2 control-label">Anesthesia</label>
                                        <div class="col-sm-5 col-lg-3 controls">
                                            <form:input path="anesthesia" name="Anesthesia" type="text"
                                                class="form-control" />
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 col-lg-2 control-label">Clinical
                                            Presentation</label>
                                        <div class="col-sm-5 col-lg-5 controls">
                                            <form:textarea path="clinical_presentation"
                                                name="clinicalpresentation" class="form-control" rows="4"></form:textarea>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 col-lg-2 control-label">Investigation</label>
                                        <div class="col-sm-5 col-lg-5 controls">
                                            <form:textarea path="investigation" name="Investigation"
                                                class="form-control" rows="4"></form:textarea>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 col-lg-2 control-label">Given
                                            Treatment</label>
                                        <div class="col-sm-5 col-lg-5 controls">
                                            <form:textarea path="given_treatment" name="giventreatment"
                                                class="form-control" rows="4"></form:textarea>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 col-lg-2 control-label">Treatment
                                            Advice on Discharge</label>
                                        <div class="col-sm-5 col-lg-5 controls">
                                            <form:textarea path="advice" name="Advice"
                                                class="form-control" rows="4"></form:textarea>
                                        </div>
                                    </div>
                                </div>
                                <div class="tab-pane" id="tab2-3">
                                    <div class="form-group">
                                        <label for="country2" class="col-sm-3 col-lg-2 control-label">Country</label>
                                        <div class="col-sm-5 col-lg-3 controls">
                                            <input type="text" name="country2" id="country2"
                                                class="form-control">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="city2" class="col-sm-3 col-lg-2 control-label">City</label>
                                        <div class="col-sm-5 col-lg-3 controls">
                                            <input type="text" name="city2" id="city2"
                                                class="form-control">
                                        </div>
                                    </div>
                                    <%-- <div class="form-group">
                                        <label class="col-sm-3 col-lg-2 control-label">Gender</label>
                                        <div class="col-sm-5 col-lg-3 controls">
                                            <label class="radio-inline"> 
                                            <form:radiobutton path="sex" name="gender" value="Male" /> Male
                                            </label> <label class="radio-inline"> 
                                            <form:radiobutton path="sex" name="gender" value="Female" /> Female
                                            </label>
                                        </div>
                                    </div> --%>
                                    <div class="form-group">
                                        <label for="textarea2" class="col-sm-3 col-lg-2 control-label">More
                                            info</label>
                                        <div class="col-sm-5 col-lg-3 controls">
                                            <textarea name="textarea2" id="textarea2" rows="5"
                                                class="form-control"></textarea>
                                        </div>
                                    </div>
                                </div>
                                <div class="tab-pane" id="tab2-4">
                                    <div class="form-group">
                                        <label class="col-sm-3 col-lg-2 control-label">First
                                            Name</label>
                                        <div class="col-sm-5 col-lg-3 controls">
                                            <span class="text">Penny</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 col-lg-2 control-label">last
                                            Name</label>
                                        <div class="col-sm-5 col-lg-3 controls">
                                            <span class="text">Rodrigez</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 col-lg-2 control-label">Gender</label>
                                        <div class="col-sm-5 col-lg-3 controls">
                                            <span class="text">Female</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 col-lg-2 control-label">Username</label>
                                        <div class="col-sm-5 col-lg-3 controls">
                                            <span class="text">PennyRod</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 col-lg-2 control-label">Email</label>
                                        <div class="col-sm-5 col-lg-3 controls">
                                            <span class="text">pennyrod@domain.com</span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2">
                                    <a href="javascript:;" class="btn button-previous">Back</a> <a
                                        href="javascript:;" class="btn btn-primary button-next">Continue</a>
                                    <button type="submit" class="btn btn-success button-submit">Submit</button>
                                </div>
                            </div>
                        </div>
                    </form:form>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- END Main Content -->
<jsp:include page="footer.jsp"></jsp:include>

0 个答案:

没有答案