When developing Java Web applications, we often have to choose the right framework for development to improve efficiency and the quality of the application system. When choosing a frame, the hardest choice is the web framework (the persistence layer framework already has JPA specifications).
After using a large number of web frameworks, the actual project (online exam system) needs, I decided to try the latest framework combination:
JSF1.2 + Spring2
Before you start you have to configure the database in the project, the spring boot used in this article, compared to spring,spring boot eliminates many of the complex configuration of components, directly in the POM configuration components, will automatically help us to import components Then under Src/main/resources, create a new application.properties
Xml Spring-mvc.xml Database.propertiesdatabase.url=jdbc:mysql://127.0.0.1:3306/springdata?useunicode=truecharacterencoding= utf8database.username=rootdatabase.password=root# server with the following password Database.driverclassname=com.mysql.jdbc.driverPersistence.xml Spring-jpa.xml Log4j.properties SPRINGMVC+SPRING+J
Spring data JPA can write some implementations for you: Spring data JPA configuration
XML Configuration method:
Java Configuration Method
JPA Java Configuration Method
@Configuration
@EnableJpaRepositories (basepackage= "Com.oneslideicywater.repository") Public
class jpaco
add a thing annotation above the method, or add the management of the service thing controller in the XML file@Service@Transactionalcontext:component-scan base-package="Com.liwei.springdata.service" >Context: component-scan> Summarized as follows(1) UPDATE and DELETE operations can be completed via a custom JPQL. Note: JPQL does not support the use of INSERT;(2) Write JPQL statements in @Query annotations, but must be decorated with @Modifying. To notify Springdata that this is an UPDATE o
(converter = statusattributeconverter.class) PrivateString status; Status: 1 enabled, 1 disabled,-2 deleted}3. AdvantagesThe client does not have to hardcode the background numbers with the corresponding details of the description.The server provides an interface to get Statusenum, gets to [{"Value": 1, "description": "Enabled"}, {"Value":-1, "description": " Disabled "}, {" Value ": -2,"description":" deleted "}], the client is assembled directly into a drop-down list.Copyright = {"Author": "I
You need to delete some of the data from the table in the project@Query ("Delete from engineerservices es where Es.engineerid =? 1")int deletebyegid (String engineerid); But the error was promptedFor DML operationsBy looking up the relevant data, we need to add @Modifying annotations for executing update and DELETE statements. @Modifying@Query ("Delete from engineerservices es where Es.engineerid =? 1")int Deletebyegid (String Engineerid); However, another error occurred after the addition of t
There's nothing to say, just remember.Here are the methods in the servicePage DAO is defined as follows:Public interface Staffdao extends Repository Spring JPA Dynamic Query
1.JPQLA. Definition: Java Persistent Query Language (JPQL) is a portable query language designed to bind SQL syntax and simple query semantics together in an expression of an object-oriented expression language • Queries written in this language are portable and can be compiled into SQL on all major database servers.B. Statement:Select from User where u.userid=?2. One-to-one (Onetoone)The A.userinfo class has the user attribute (contains the user_id foreign key) @OneToOne @JoinColumn (nam
First, the common rules of fast-track1 and and2 or OR3 is,equals equals4 between between the two5 LessThan less than6 lessthanequal less than equals7 GreaterThan greater than8 greaterthanequal greater than or equal9 After (time) >Before before (time) One IsNull equals nullIsnotnull,notnull not equal to NULLLike fuzzy query. You need to add% in your enquiryThe notlike is not within the blur range. You need to add% in your enquiryStartingwith at a certain beginningEndingwith with a certain endCont
JPQL as follows:true ) @Query ("UPDATE synctestfromtkdo SET Stuans = ' where typeId =? 1")publicvoid Updatestuans (Integer typeid);Project run times error, hint:executing an update/delete query; nested exception is Javax.persistence.TransactionRequiredExceptionReason:Update, delete operation involves a transaction mechanism and needs to be setWorkaround:Add the annotation @transactional (import org.springframework.transaction.annotation.Transactional;) to the service class calling this method.[
Less nonsense.Parameters can be setIn the Org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties /** * Whether to expose and assume 1-based page number indexes. Defaults to "false", * meaning a page number of 0 in the request equals the first page. */ Private Boolean false;So in the APPLICATION.YML,Spring: Data: Web: pageable: default-page-size:20 size-parameter:rows
Using the @repository interface provided by Springboot, you can accomplish the custom work that once required a lot of code writing and configuration files. These configurations, which previously gave novice programmers a headache and were proud of an experienced programmer, have become less important due to the continuous improvement of the framework and have also improved programmer productivity.This article describes how to manipulate MongoDB through Springboot.I. Configure Pom.xml FirstTwo.
Title:Use repository to query, use Crudrepository's own GetOne () method and FindByID () method query, the database has this data, but can not be found.Userrepository.getone (ID) and Userrepository.findbyid (ID) cannot query from the database to the data.And in Userrepository, write a Finduserbyid () method, that is, you can query the dataSpecific reasons who know, can inform?Spring data JPA uses repository
Hibernate 3.2 supports JPA annotations, and spring integration JPA is optional.
The following is an example of the spring integration JPA.
Entity class MyUser, using JPA annotations to implement mappings to database table MyUser
Summary: Spring Data JPA is actually a dynamic proxy for JDK mode (requires an interface with a whole bunch of top-repository interfaces from Org.springframework.data.repository,There are crudrepository interface and an implementation class Simplejparepository), as long as there is an interface can query the database, in fact, is the proxy method, the specific query method has twoOne is simply the method na
Although JPA development is mostly done with the hibernate specification, there is a significant difference between the one and spring integration, and first look at the important configuration of spring's consolidated JPASee here to believe that I do not need to explain more people should be able to understand, if you use this way to pay attention to SRC must exist under the Meta-inf folder and the followi
In the "Spring boot, using JPA operations SQL Server database completion crud", based on spring boot, using JPA to invoke the SQL Server database's stored procedure and return the records collection, completed the crud and called the stored procedure query data.In many complex cases, there is a need to execute SQL dire
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.