7.1 @param 注解单一属性
在java里面,@param是参数的解释
/**
*param s 这里表示对 s 的文字说明,描述
*/
public void aa(String s){}
//一般 java 中 @表示注解,解释一个方法,类,属性的作用。
实例一 @param注解单一属性
dao曾示例
Public User selectUser(@param("userName") String name,@param("userpassword") String password)
xml映射对应示例:
<select id = "selectUser" resultMap="BaseResultMap">
select * from user_user_t where user_name =
#{userName , jdbcType = VARCHAR} and user_password =
#{userPassword,jdbcType=VARCHATR}
</select>
注解:采用#{}的方式把@param注解括号内的参数进行引用(括号内参数对应的是形参如userName对应的name)
示例二 @param注解JavaBean对象
dao层示例:
public List<user> getUserInformatin(@param("user") User user);
xml对应映射:
<select id = "getUserInformation" parameterType="com.github.demo.vo.User>" resultMap="userMapper">
<include refrid="User_Base_Column_List"/>
from mo_user t where 1=1
<!--因为传进来的对象所以这样写是去取不到-->
<if test="user.userName!=null and user.userName!='' ">
and t.userName=#{user.userName}
</if>
<if test="user.userAge!=null and user.userAge!='' ">
t.user_age=#{user.userAge}
</if>
</select>
7.2 java注解 Annotation
注解 Annoation ,也叫元数据。一种代码级别的说明。
它是JDK1.5及以后版本引入的一个特性,与类、接口、枚举是在同一个层次。它可以声明在包、类、字段、方法、局部变量、方法参数等的前面,用来对这些元素进行说明,注释。
作用分类:
①编写文档:通过代码里标识的元数据生成文档【生成文档doc文档】
② 代码分析:通过代码里标识的元数据对代码进行分析【使用反射】
③编译检查:通过代码里标识的元数据让编译器能够实现基本的编译检查【Override】
@Documented –注解是否将包含在JavaDoc中
@Retention –什么时候使用该注解
@Target? –注解用于什么地方
@Inherited – 是否允许子类继承该注解
7.3 long m = new Integer(0).longValue();
longValue 输出long数据。
———————— 分割线 ——————————————————————————
7.Reverse Integer
Problem:
Given a 32-bit signed integer, reverse digits of an integer.
给定一个32位有符号的整数,翻转该证书
Example 1:
Input: 123
Output: 321
Example 2:
Input: -123
Output: -321
Example 3:
Input: 120
Output: 21
Note:
Assume we are dealing with an environment which could only hold integers within the 32-bit signed integer range. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows(整数溢出).
solution:
- 去符号,将原数取绝对值;全程对整数进行处理
逐位循环,每次循环有
res = res*10 + x%10;
x/=10;判断结果是否溢出。
Code:
class Solution {
/**
*@param n the integer to be resersed
*@return the reversed integer
**/
public int reverse(int x) {
int sign = x < 0 ? -1:1;//记录正负
x = Math.abs(x);
int res = 0;
while (x>0){
//Integer.MAX_VALUE最大整数
//判断是否溢出
if(Integer.MAX_VALUE/10 < res || (Integer.MAX_VALUE-x%10)< res*10 ){
return 0;
}
res = res*10 + x%10;
x/=10;
}
return sign *res;
}
}