refactor project structure

This commit is contained in:
2025-11-13 12:14:07 +01:00
parent 00fad14ab5
commit a2bc018235
24 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
package org.example.demo;
import java.io.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
@WebServlet(name = "helloServlet", value = "/hello-servlet")
public class HelloServlet extends HttpServlet {
private String message;
public void init() {
message = "Hello World!";
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/html");
// Hello
PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("<h1>" + message + "</h1>");
out.println("</body></html>");
}
public void destroy() {
}
}

View File

@@ -0,0 +1,27 @@
package org.example.demo.beans;
import jakarta.enterprise.context.SessionScoped;
import jakarta.inject.Named;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.io.Serializable;
@Named
@SessionScoped
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class StudentBean implements Serializable {
private String name;
private String matrikelnummer;
private String studiengang;
public String speichern() {
return "ausgabe?faces-redirect=true";
}
}

View File

@@ -0,0 +1,78 @@
package org.example.demo.models;
public class Buch
{
//Buch Attribute
private String titel;
private double preis;
private int id;
private static Integer idCounter;
//Konstruktor
static{
idCounter=0;
}
public Buch(String titel, double preis) {
super();
this.titel = titel;
this.preis = preis;
synchronized(this.getClass()){
id=idCounter;
idCounter++;
}
}// Konstruktor
public Buch() {
this("",-1);
}// Konstruktor
//Operation update(): aendert alle Attribute
public void update(String titel, double preis) {
this.titel = titel;
this.preis = preis;
}// update
public String getTitel() {
return titel;
}
public void setTitel(String titel) {
this.titel = titel;
}
public double getPreis() {
return preis;
}
public void setPreis(double preis) {
this.preis = preis;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String toString()
{
return this.titel+", "
+ ((""+preis).replace('.',','));
}// toString
public boolean equals(Object o){
if(o != null
&& o.getClass() == this.getClass()
&& ((Buch)o).getId()==this.getId()
){
return true;
}
else{
return false;
}
}
}// Buch

View File

@@ -0,0 +1,53 @@
package org.example.demo.models;
import java.util.ArrayList;
public class BuchContainer
{
//Objektverwaltung
private ArrayList<Buch> buchContainer;
public BuchContainer() {
buchContainer = new ArrayList<Buch>();
}// Konstruktor
//Operation add(): fuegt ein Element hinzu
public void add(Buch buch)
{
buchContainer.add(buch);
}// add
public void update(Buch buch, String titel, double preis) {
// Attribute des Buchs werden geaendert
buch.update(titel, preis);
}
//Operation delete(): loescht ein Buch aus dem Container
public void delete(Buch buch)
{
buchContainer.remove(buch);
}// delete
public void delete(int id)
{
Buch buch = new Buch();
buch.setId(id);
buchContainer.remove(buch);
}// delete
//
public Buch get(int id){
Buch buch = new Buch();
buch.setId(id);
return buchContainer.get(buchContainer.indexOf(buch));
}
//Rückgabe des Containers als Array von Objekten
public ArrayList<Buch> getAll()
{
return buchContainer;
}// getAll
}// class BuchContainer