Мы с важной новостью: с 28 февраля 2025 года сервис Хабр Фриланс прекратит свою работу.
Купить услуги можно до 28 февраля 2025, но пополнить баланс уже нельзя. Если на вашем счете остались средства, вы можете потратить их на небольшие услуги — служба поддержки готова поделиться бонусами, на случай, если средств немного не хватает.
- Обо мне
-
- Стоимость работы:
- от 30 000 руб. за проект
- Профессиональный опыт:
- менее года
- Форма собственности:
- Физ. лицо
- Способы оплаты:
- безналичный расчёт, электронные деньги
Работаю с Java , Java Spring Boot , Thymeleaf , Java Spring Framework , jquery , Javascript , .NET , ASP.NET , Qt , STL.
Пример PDF Creator for users , it can be transformed to any data type:
import java.awt.Color;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import com.luxuryattributes.common.entity.User;
public class UserPdfExporter extends AbstractExporter {
public void export(List<User> listUsers, HttpServletResponse response) throws IOException {
super.setResponseHeader(response, "application/pdf", ".pdf", "users_");
Document document = new Document(PageSize.A4);
PdfWriter.getInstance(document, response.getOutputStream());
document.open();
Font font = FontFactory.getFont(FontFactory.HELVETICA_BOLD);
font.setSize(18);
font.setColor(Color.BLUE);
Paragraph paragraph = new Paragraph("List of User", font);
paragraph.setAlignment(Paragraph.ALIGN_CENTER);
document.add(paragraph);
PdfPTable table = new PdfPTable(6);
table.setWidthPercentage(100f);
table.setSpacingBefore(10);
table.setWidths(new float[] {1.2f, 3.5f, 3.0f, 3.0f, 3.0f, 1.7f});
writeTableHeader(table);
writeTableData(table, listUsers);
document.add(table);
document.close();
}
private void writeTableData(PdfPTable table, List<User> listUsers) {
for (User user : listUsers) {
table.addCell(String.valueOf(user.getId()));
table.addCell(user.getEmail());
table.addCell(user.getFirstName());
table.addCell(user.getLastName());
table.addCell(user.getRoles().toString());
table.addCell(String.valueOf(user.isEnabled()));
}
}
private void writeTableHeader(PdfPTable table) {
PdfPCell cell = new PdfPCell();
cell.setBackgroundColor(Color.BLUE);
cell.setPadding(5);
Font font = FontFactory.getFont(FontFactory.HELVETICA);
font.setColor(Color.WHITE);
cell.setPhrase(new Phrase("ID", font));
table.addCell(cell);
cell.setPhrase(new Phrase("E-mail", font));
table.addCell(cell);
cell.setPhrase(new Phrase("First Name", font));
table.addCell(cell);
cell.setPhrase(new Phrase("Last Name", font));
table.addCell(cell);
cell.setPhrase(new Phrase("Roles ", font));
table.addCell(cell);
cell.setPhrase(new Phrase("Enabled", font));
table.addCell(cell);
}
}
Небольшой пример с jquery : Quantity Control Function:
$(document).ready(function() {
$(".linkMinus").on("click", function(evt) {
evt.preventDefault();
productId = $(this).attr("pid");
quantityInput = $("#quantity" + productId);
newQuantity = parseInt(quantityInput.val()) - 1;
if (newQuantity > 0) {
quantityInput.val(newQuantity);
} else {
showWarningModal('Minimum quantity is 1');
}
});
$(".linkPlus").on("click", function(evt) {
evt.preventDefault();
productId = $(this).attr("pid");
quantityInput = $("#quantity" + productId);
newQuantity = parseInt(quantityInput.val()) + 1;
if (newQuantity <= 5) {
quantityInput.val(newQuantity);
} else {
showWarningModal('Maximum quantity is 5');
}
});
});
Unit Test Example (With Mock):
@Test
@WithMockUser(username = "someuser@mail.ru", password = "somepassword", roles = "admin")
public void testCreateCountry() throws JsonProcessingException, Exception {
String url = "/countries/save";
String countryName = "Great Britain";
String countryCode = "UK";
Country country = new Country(countryName, countryCode);
MvcResult result = mockMvc.perform(post(url).contentType("application/json")
.content(objectMapper.writeValueAsString(country))
.with(csrf()))
.andDo(print())
.andExpect(status().isOk())
.andReturn();
String response = result.getResponse().getContentAsString();
Integer countryId = Integer.parseInt(response);
Optional<Country> findById = repo.findById(countryId);
assertThat(findById.isPresent());
Country savedCountry = findById.get();
assertThat(savedCountry.getName()).isEqualTo(countryName);
}
- Отзывы
Нет отзывов