猜猜我哪里错了。。?
package com.yyy.subject.model;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Subject {
@Id
private int id;
private String code;
private String name;
private String medium;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMedium() {
return medium;
}
public void setMedium(String medium) {
this.medium = medium;
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
package com.yyy.subject.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.yyy.subject.model.Subject;
@Repository
public interface SubjectRepository extends JpaRepository<Subject, Integer> {
@Query("select medium,count(medium) from subject group by medium")
public List<Object[]> findTypeAndTypeCount();
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
package com.yyy.subject.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.yyy.subject.model.Subject;
@Service
public interface SubjectService {
public Subject create(Subject subject);
public Subject update(Subject subject);
public void delete(int id);
public Subject readOne(int id);
public List<Subject> readAll();
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
package com.yyy.subject.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yyy.subject.model.Subject;
import com.yyy.subject.repository.SubjectRepository;
@Service
public class SubjectServiceImpl implements SubjectService {
@Autowired
private SubjectRepository subjectRepository;
@Override
public Subject create(Subject subject) {
return subjectRepository.save(subject);
}
@Override
public Subject update(Subject subject) {
return subjectRepository.save(subject);
}
@Override
public void delete(int id) {
subjectRepository.deleteById(id);
}
@Override
public Subject readOne(int id) {
return subjectRepository.findById(id).get();
}
@Override
public List<Subject> readAll() {
return (List<Subject>) subjectRepository.findAll();
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
package com.yyy.subject.util;
import java.util.List;
import org.springframework.stereotype.Component;
@Component
public interface ReportUtil {
public void generatePieChart(String path,List<Object[]> data);
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
package com.yyy.subject.util;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;
import org.springframework.stereotype.Component;
@Component
public class ReportUtilImpl implements ReportUtil {
@Override
public void generatePieChart(String path,List<Object[]> data) {
DefaultPieDataset dataset=new DefaultPieDataset();
for (Object[] objects : data) {
dataset.setValue(objects[0].toString(), new Double(objects[1].toString()));
}
JFreeChart chart = ChartFactory.createPieChart3D("Report", dataset);
try {
ChartUtilities.saveChartAsJPEG(new File(path+"pieChart.jpeg"), chart, 300, 300);
} catch (IOException e) {
e.printStackTrace();
}
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
package com.yyy.subject.controller;
import java.util.List;
import javax.servlet.ServletContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.yyy.subject.model.Subject;
import com.yyy.subject.repository.SubjectRepository;
import com.yyy.subject.service.SubjectService;
import com.yyy.subject.util.ReportUtil;
@Controller
public class SubjectController {
@Autowired
private SubjectService subjectService;
@Autowired
private SubjectRepository subjectRepository;
@Autowired
private ReportUtil report;
@Autowired
private ServletContext sc;
@RequestMapping("/form33")
public String create(ModelMap model)
{
model.addAttribute("subject", new Subject());
return "page1";
}
@RequestMapping("/form34")
public String create2(ModelMap model,@ModelAttribute("subject") Subject subject)
{
subjectService.create(subject);
model.addAttribute("msz", "Database created with id:"+subject.getId());
return "page1";
}
@RequestMapping("/display")
public String read(ModelMap model)
{
List<Subject> subject = subjectService.readAll();
model.addAttribute("subject", subject);
return "page2";
}
@RequestMapping("/deleteSubject")
public String delete(@RequestParam("id") int id,ModelMap model)
{
subjectService.delete(id);
List<Subject> subject = subjectService.readAll();
model.addAttribute("subject", subject);
return "page2";
}
@RequestMapping("/updateSubject")
public String edit(@RequestParam("id") int id,ModelMap model)
{
Subject subject = subjectService.readOne(id);
model.addAttribute("subject", subject);
return "editpage";
}
@RequestMapping("/updated")
public String update(@ModelAttribute("subject") Subject subject1,ModelMap model)
{
subjectService.update(subject1);
List<Subject> subject = subjectService.readAll();
model.addAttribute("subject", subject);
return "page2";
}
@RequestMapping("/generateReport")
public String generateReport()
{
String path=sc.getRealPath("/");
List<Object[]> data= subjectRepository.findTypeAndTypeCount();
report.generatePieChart(path,data);
return "report";
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
package com.yyy.subject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class YyySubjectApplication {
public static void main(String[] args) {
SpringApplication.run(YyySubjectApplication.class, args);
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.jsp
server.port=9090
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.yyy.subject</groupId>
<artifactId>YYYSubject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>YYYSubject</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.hibernate.hql</groupId>
<artifactId>hibernate-hql-parser</artifactId>
<version>1.5.0.Final</version>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.19</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ page isELIgnored="false" %>
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h2><i>Enter Details</i></h2>
<form:form action="form34" modelAttribute="subject" method="post">
Id:<input type="text" name="id"/><br><br>
Code:<form:input path="code"/><br><br>
Name:<form:input path="name"/><br><br>
Medium:<br>
English<form:radiobutton path="medium" value="ENGLISH"/><br>
Hindi<form:radiobutton path="medium" value="HINDI"/><br>
Punjabi<form:radiobutton path="medium" value="PUNJABI"/>
<br><br>
<input type="submit" value="Submit"/>
<br><br>
${msz}
<br><br>
<a href="display">View All</a>
</form:form>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
错误:
Error
正在创建名为“subjectController”的bean:通过字段“subjectService”表示未满足的依赖关系;嵌套的异常是org。springframework。豆。工厂未满足的依赖项异常:创建名为“subjectServiceImpl”的bean时出错:通过字段“subjectRepository”表示未满足的依赖项;嵌套的异常是org。springframework。豆。工厂BeanCreationException:创建名为“subjectRepository”的bean时出错:调用init方法失败;嵌套的异常是java。lang.IllegalArgumentException:方法公共抽象java的查询验证失败。util。列表com。yyy。主题存储库。主题库。findTypeAndTypeCount()!
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: subject is not mapped [select medium,count(medium) from subject group by medium]
1) JPQL区分大小写,2)必须使用别名:
@Query("select s.medium, count(s.medium) from Subject s group by s.medium")
我正在使用SpringBoot刷新我的Spring技能。我已经将库更新到最新版本。当我将浏览器指向应用程序时,会出现以下错误: 这是我的控制器: } tomcat日志看起来像这样: 如有任何建议,将不胜感激。 罗斯
我正在开发代码从链接:https://www.dineshonjava.com/microservices-with-spring-boot/和工作
在此处输入图像描述这是我的控制器,我正在使用端口localhost:8080访问它返回白色标签错误。原因可能是什么?
我有一个小的spring boot项目,效果很好。但是,我试图添加一些验证。。我在一个html页面上工作,但在另一个页面上失败了,没有可行的原因! 这是html页面(addProcedure.html): 对于控制器: 带有验证注释的实体类,, 我试过@NotNull、@NotEmpty和@NotBlank,但运气不好。。。似乎验证有效。然而,我没有进入html页面! 相反,我得到了以下信息:
我用的是Spring靴。我正在尝试使用thymeleaf模板。我用过龙目岛。我在运行该项目时收到白标签错误,该错误表示有一个意外错误(Type=internal Server error,status=500)。模板分析期间出错(模板:“class path resource[templates/design.html]”)org.thymeleaf.exceptions.templateInpu
问题内容: 应用程序可以运行,但是出现错误: 我该如何解决? 问题答案: 当我们创建一个Spring Boot应用程序时,我们用注解对其进行注解。该批注“包装”了许多其他必需的批注,以使应用程序正常工作。一种这样的注释是注释。该注释告诉Spring寻找Spring组件并配置要运行的应用程序。 你的应用程序类必须位于程序包层次结构的顶部,以便Spring可以扫描子程序包并找到其他必需的组件。 下面的