JAVA Interview points 003_mybatis the difference between # and $ __java

Source: Internet
Author: User
#的作用:
Usermapper.xml
Note Here, write the SQL statement, we can use the way of XML configuration, also can use the way of annotation.
E:\workspace\day76_mybatis01\src\com\credream\test2\userMapper.xml
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE Mapper Public "-//mybatis.org//dtd mapper 3.0//en" "Http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace= "Com.credream.test2.userMapper" >
<!--
CRUD Operations
-->
1. Add an additional action first
Parametertype= "User" This is passed into an object
//
<insert id= "AddUser" parametertype= "Com.credream.bean.User" >
Insert into the users (name, age) VALUES (#{name}, #{age})
</insert>
2. Here is the delete operation
Id=#{id} Note that the ID in this {ID} here Id=#{id is free to write
But values (#{name}, #{age}) cannot be written casually, because
The contents of (#{name}, #{age}) are obtained from the user's properties
//
<delete id= "DeleteUser" parametertype= "int" >
Delete from users where Id=#{id}
</delete>
3. Update operation
#{name},age=#{age} where Id=#{id}
These three are all obtained from the user object.
//
<update id= "UpdateUser" parametertype= "Com.credream.bean.User" >
Update users set Name=#{name},age=#{age} where Id=#{id}
</update>


<select id= "GetUser" parametertype= "int" resulttype= "Com.credream.bean.User" >
SELECT * from users where id=#{id}
</select>
4. All Inquiries:
This query returns a list, can you return a list here?
Resulttype= "List", if the result is a list, what type of content is inside him?
user right. Okay, this resulttype= "List" I'm not going to write first, do not specify the result set type
I'll write later.
//
<select id= "GetAllUsers" >
SELECT * from Users
</select>

</mapper>



E:\workspace\day76_mybatis01\src\conf.xml
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE configuration Public "-//mybatis.org//dtd Config 3.0//en" "Http://mybatis.org/dtd/mybatis-3-config.dtd" >
<configuration>
1. We can introduce this place here.
The first introduction of this db.properties file can directly
<properties resource= "Db.properties"/> So
//
<properties resource= "Db.properties" >
2. Then <property name= "name" value= "tt"/> What does it mean?
That means he can overwrite the contents of the Db.properties file.
//
<property name= "name" value= "tt"/>
</properties>
<!--
Development: Development model
Work: Working mode
-->
<environments default= "Development" >
<environment id= "Development" >
<transactionmanager type= "JDBC"/>
<datasource type= "Pooled" >
3. After the introduction of the configuration file, this is the time to use these parameters can be this
In the same way as the El expression.
//
<property name= "Driver" value= "${driver}"/>
<property name= "url" value= "${url}"/>
<property name= "username" value= "${name}"/>
<property name= "Password" value= "${password}"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource= "Com/credream/test1/usermapper.xml"/>
<mapper resource= "Com/credream/test2/usermapper.xml"/>
<mapper class= "Com.credream.test3.UserMapper"/>
</mappers>
</configuration>

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.